W
W
WebforSelf2020-08-11 11:16:56
WordPress
WebforSelf, 2020-08-11 11:16:56

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'); ?>


https://yadi.sk/i/inEzROMEw0dprg

This is how this thing looks physically.

Those. I sort in the admin panel (by dragging blocks) and then using an array and this sorting, it displays my files to me in the sequence I want. Is it possible to do this using Advanced Custom Fields??

The task is such that I can move the laid-out blocks in places. Can anyone bother with such a question, advise how to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Chesnokov, 2020-08-13
@WebforSelf

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):
5f34fc68e7afb205498073.jpeg
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):
5f34fccec051e901772241.jpeg
3. Add blocks to the resulting taxonomy:
5f34fd00c654d407645889.jpeg
4. Create a page with settings (Pods Admin > Add New > Create New > Custom Settings Page):
5f34fda7c56ae107836626.jpeg
5. On this page we need one field, let's call it Blocks:
5f34fdef88dd4587755283.jpeg
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:
5f34feb24ce27338812674.jpeg
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;
}

Result:
homepage-work.php
homepage-slider.php
homepage-test.php

There are several other ways to do this, but they have their own nuances, for example: you can not use an additional taxonomy, but write all the values ​​manually in a field like "Relationship > Simple", but then there may be problems with manual sorting of blocks. Or make a separate field for each block, like "Position #1" > and make a choice from the list, which block will be in it. Etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question