WordPress.org

Ready to get started?Download WordPress

Forums

filtering child and grandchild pages (4 posts)

  1. hafman
    Member
    Posted 3 years ago #

    Hi,

    Can i get the plugin to show 3 or four levels of pages but exclude the top-most level?

    I'm trying out conditional code on the page template but i'm getting lost in the $post->post_parent stuff. Scoping or testing for page levels is no easy task it seems.

    Any hints would be welcome

  2. hafman
    Member
    Posted 3 years ago #

    my code, lost....

    if(function_exists('wpdt_list_pages')){           
    
    	if($post->post_parent) {
      print ('second level');
    
      $children = wpdt_list_pages(array(
    			'title_li' => '',
    			'child_of' => $post->post_parent,
    			'echo' => 0,
    			'oclinks' => 0,
    			'sort_column' => 'menu_order',
    			'showselection' => 1,
    			'opentoselection' => 1,
    			'opento' => $post->ID,
    			'uselines' => 0,
    			'cache' => 0
    			));
    
    } else if ($post->post_parent->post_parent) {
      print ('third level');
    
     $children = wpdt_list_pages(array(
    			'title_li' => '',
    			'child_of' => $post->post_parent,
    			'echo' => 0,
    			'oclinks' => 0,
    			'sort_column' => 'menu_order',
    			'showselection' => 1,
    			'opentoselection' => 1,
    			'opento' => $post->ID,
    			'uselines' => 0,
    			'cache' => 0
    			));
    
      }	else {
        print ('top level');
    
      $children = wpdt_list_pages(array(
    			'title_li' => '',
    			'parent' => $post->post_parent,
    			'echo' => 0,
    			'oclinks' => 0,
    			'sort_column' => 'menu_order',
    			'showselection' => 1,
    			'opentoselection' => 1,
    			'opento' => $post->ID,
    			'uselines' => 0,
                            'exclude' => '171',
    			'cache' => 0
    			));
    
    			}
    	if ($children) {
    		echo $children;
    	}
    }
  3. ulfben
    Member
    Posted 3 years ago #

    Your solution to figuring out levels of nesting is kind of neat. But if you rarely add or delete pages at the top-most level, I'd probably just create a list of those IDs and exclude them.

    $children = wpdt_list_pages('exclude=1,2,3');

    Problem solved.

    The WP-dTree template functions are built to mirror WordPress built-in ones. In this case I'd recommend you check out the Codex article on wp_list_pages.

    Oh and don't disable the cache. The cache is "indexed" by the function parameters and blog content (posts, pages, links, categories). If any of those changes (renames, deletes, adds) you will get a freshly generated dTree. WP-dTree performs a lot of work to produce the navigation trees and you don't want your server punished like that for every page view.

  4. hafman
    Member
    Posted 3 years ago #

    Thanks, although i think it over complicates things a bit. I did just as you suggest in the end. Had to stand back a bit though! I'll take your advice about the cache.

Topic Closed

This topic has been closed to new replies.

About this Topic