Answer the question
In order to leave comments, you need to log in
How to sort the output of php files in wordpress?
Friends, there is a little-known Titan framework, in principle I like it, but I decided to leave it. is not updated in favor of ACF , usually typesetting the main (blocked) each block in its php and then output through a cycle with the ability to sort in the admin panel.
<?php
/*
Template Name: Главная страница
*/
?>
<?php get_header('main'); ?>
<?php $titan = TitanFramework::getInstance( 'gpress' );?>
<?php
foreach( (array) $titan->getOption('home_sortable' ) as $item) {
get_template_part('files/homepage', $item);
} ?>
<?php get_footer('main'); ?>
Answer the question
In order to leave comments, you need to log in
I use PODS (pods.io) and I'll show you how it's done using its example. In ACF, everything is similar.
1. Create a place where we will store information about the blocks (Pods Admin > Add New > Create New > Custom Taxonomy):
2. Do not forget to set where it will be in the admin panel (Admin UI > Menu Location > Add a submenu item to Settings menu):
3. Add blocks to the resulting taxonomy:
4. Create a page with settings (Pods Admin > Add New > Create New > Custom Settings Page):
5. On this page we need one field, let's call it Blocks:
Do not forget to specify in Additional Field Options Multiple Select type and List view format.
6. On the settings page, fill in the Blocks field with blocks from the custom taxonomy:
Next, work with the template, for example:
<?php
$homepage_blocks = get_option('homepage_test_blocks');
foreach ($homepage_blocks as $block) {
$term = get_term_by('term_taxonomy_id', $block, 'homepage_blocks');
$slug = $term->slug;
$file_name = $slug . '.php';
echo $file_name;
}
homepage-work.php
homepage-slider.php
homepage-test.php
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question