Find us on Facebook

LightBlog
Responsive Ads Here

Thứ Sáu, 29 tháng 12, 2017

Disable parent in wp_list_pages - Wordpress

Question:

I have the following code the generates the sitemap.
 wp_list_pages(
                                array(
                                    'exclude' => '5',
                                    'sort_column' => 'ID',
                                    'title_li' => ''
                                )
                            );
It generates a hierarchy of my Pages but it also has links to my parent pages.
enter image description here
check the screenshot above. I only need the title for all the parents not the link.

Answer:

You can use get_pages() instead and write some custom code like this :
$args = array('exclude' => '5',
             'sort_column' => 'ID'
       )
$pages = get_pages($args); 
  foreach ( $pages as $page ) {
    echo $page->post_title;
  }
You may of course elaborate more the code in order to obtain a tree.
You may also check the source code of wp_list_pages() and you will see that there is the get_pages() function, so you may also copy its code and modify it :

Không có nhận xét nào:

Đăng nhận xét