V
V
Valera Udav2013-12-22 00:38:27
CMS
Valera Udav, 2013-12-22 00:38:27

How to display the pages of the last level of nesting in WordPress?

Suppose there is such a hierarchy of nested pages:

Каталог
  - Оборудование
    -- Трансформаторы
      --- Масляные трансформаторы
        ---- Масляный трансформатор 1
        ---- Масляный трансформатор 2
      --- Сухие трансформаторы
        ---- Сухой трансформатор 1
        ---- Сухой трансформатор 2

It is necessary to implement the output of pages (not a list, but with the output of titles, text, etc.) at the maximum nesting level.
Those. When we are on the page - Transformers , on the page we should see the information of the following pages:
---- Oil transformer 1
---- Oil transformer 2
---- Dry transformer 1
---- Dry transformer 2
If we go to to the subpage --- Oil transformers , you should only see:
---- Oil transformer 1
---- Oil transformer 2
By analogy --- Dry-type transformers .
The wp_list_pages function has a convenient depth attribute in which you can specify the nesting depth, but alas, this function only outputs lists, but I need to generate the output of records myself.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
N
Nikolai Antal, 2013-12-22
@hermit931

get_pages does the same thing as wp_list_pages only prints all the data about the page

P
Pavel K, 2013-12-22
@PavelK

Can you write your Walker to wp_list_pages? It will be as you write.

R
redc0de, 2013-12-23
@redc0de

Definitely write your Walker.
https://github.com/twittem/wp-bootstrap-navwalker/...
Here for bootstrap, insert where you need the condition to display only for the current page.

J
Jonh Doe, 2014-02-16
@CodeByZen

Most likely you have a Catalog, Equipment, Transformers, Oil transformers, these are not pages but headings. A Oil transformer 1 etc. These are headings. If entries are located only in final headings, then there is a simple construction.

// узнаем id данной рубрики
$id = get_category(get_query_var('cat'))->cat_ID;
// смотрим все посты рубрики
$posts_array = get_posts( array('category'=>$id) );

and accordingly we get an array with our records.

E
Egor Kukolshchikov, 2014-08-20
@Pic

function myPagesparent($mypageID,$MyID){ 
       $myargs = array(
       	'numberposts' => -1,
       	'post_parent' => $mypageID,
       	); 
       $pages = get_children($myargs); 
       foreach ($pages as $pagg) {
         if($pagg->post_parent == $MyID ){
         	myPagesparent($pagg->ID,$MyID);
         }else{
              $option = '<a href="'.get_page_link($pagg->ID).'">';
              $option .= $post->ID;
              $option .= $pagg->post_title;
              echo '<li>'.$option.'</a></li>';
         }
      }
    }
myPagesparent($post->ID,$post->ID);

this of course will complete the task!) But this is not the most beautiful way!) If anyone has a better share

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question