• Vince

    (@vincentrich)


    I cannot seem to exclude all of the I enter in exclude= in 2.7.

    Am I alone or do you guys have the same problem?

Viewing 15 replies - 1 through 15 (of 19 total)
  • Thread Starter Vince

    (@vincentrich)

    http://codex.wordpress.org/wp_list_pages

    exclude (string)
    Define a comma-separated list of Page IDs to be excluded from the list (example: ‘exclude=3,7,31’). There is no default value. See the Exclude Pages from List example below.

    exclude_tree (string)
    Define a comma-separated list of parent Page IDs to be excluded. Use this parameter to exclude a parent and all of that parent’s child Pages. So ‘exclude_tree=5’ would exclude the parent Page 5, and its child Pages. This parameter was available at Version 2.7.

    ==========

    I think I need to use exclude_tree in WP 2.7. Let me test it.

    Thread Starter Vince

    (@vincentrich)

    I discovered that the 2nd and subsequent item on my exclude_tree does not work.

    It only excludes the 1st item.

    exclude_tree = 1,2,3,4,5,6

    I assume 6 pages would be hidden but only the page id 1 is hidden. I think this is a bug!

    Thread Starter Vince

    (@vincentrich)

    http://trac.wordpress.org/ticket/8683

    Someone reported a bug too….

    Thread Starter Vince

    (@vincentrich)

    My temporary fix was to edit wp-include/post-template.php:

    Line 616: $r[‘hierarchical’] = 0;

    Edit to: //$r[‘hierarchical’] = 0;

    I compared with the previous version of WordPress and this is the only major difference.

    In includes/post.php you will find the following chunk of code beginning in line 2190 :

    (At least in WordPress version 2.7.1 you will – line numbers may vary for other versions)

    if ( !empty($exclude_tree) ) {
    $exclude = array();

    $exclude = (int) $exclude_tree;
    $children = get_page_children($exclude, $pages);
    $excludes = array();
    foreach ( $children as $child )
    $excludes[] = $child->ID;
    $excludes[] = $exclude;
    $total = count($pages);
    for ( $i = 0; $i < $total; $i++ ) {
    if ( in_array($pages[$i]->ID, $excludes) )
    unset($pages[$i]);
    }
    }

    The problem is that the exclude_tree argument is not handled like a list of parameters, but merely as a single integer argument. I learned this after trying to build a menu for ttu.no by excluding a number of chapters, that should not go on the front page. Well, I got a nice surprise when even my elaborate exclude list only worked on the first section and my menu totally filled the front page.

    But I found the problem, and have a solution – by updating the code as below, everything will work as expected:

    if ( !empty($exclude_tree) ) {
    $exclude = array();

    $exclude = explode(‘,’,$exclude_tree);
    foreach ($exclude as $exclude_page) {
    $children = get_page_children($exclude_page, $pages);
    $excludes = array();
    foreach ( $children as $child )
    $excludes[] = $child->ID;
    $excludes[] = $exclude_page;
    $total = count($pages);
    for ( $i = 0; $i < $total; $i++ ) {
    if ( in_array($pages[$i]->ID, $excludes) )
    unset($pages[$i]);
    }
    }
    }

    Now, this is my first “real” contribution to the open source world – I wish I knew how to use TRAQ, so I could fix this directly in the repository as well πŸ™‚

    Please send me a pointer if you know how to work with the TRAQ system.

    Kind regards
    Torben Brams

    Tried to follow the guide as documented in Reporting Bugs, submitted a TRAC (!) ticket, assigned it to myself, created a patch file with this fix and marked the ticket “has_patch” and finally changed status to Fixed.

    Hope somebody will review and approve soon πŸ™‚

    Cheers
    Torben Brams

    I hope it’s not too late to get in on this discussion. This seems to be the closest I’ve seen to my particular issue. I was hoping that the above code change would be the ticket, but again, no dice.

    In my v2.7 sidebar, I am trying to get the child pages to hide unless their parent page is clicked.

    Can anyone help me out please?

    I too fixed this bug, I ‘think’ this is slightly more efficient as it doesn’t have a nested loop. Don’t mean to hijack your thread but found it when I was looking to post my fix.

    if( !empty( $exclude_tree ) )
        {
    	$exclude_trees = array();
            $exclude_trees = explode(',', $exclude_tree );
    
            $excludes = array();
            foreach( $exclude_trees as $parent_exclude )
            {
                $excludes[] = $parent_exclude;
                $children = get_page_children( $parent_exclude, $pages );
                foreach ( $children as $child )
                    $excludes[] = $child->ID;
            }
    
    	$total = count( $pages );
    	for ( $i = 0; $i < $total; $i++ ) {
    	    if ( in_array( $pages[$i]->ID, $excludes) ) {
    		unset( $pages[$i] );
                }
    	}
        }

    PhrankDee, you should be able to do what you want with css.

    @thelim3y: Thanks, this is the only version of the bugfix that works for me! I tried all the others I could find – one of them only hid the parent page and the first two subpages, another one just returned an error, but yours does exactly what I want. πŸ˜€

    …works for 2.8, too! The code to be replaced moved down a couple lines to 2351. Here’s more detailed instructions:
    exclude_tree bugfix for WP 2.8

    none of these fixes work in latest version of WP. only hides first two levels and then subpages are listed again. Big problem for me πŸ™

    In my 2.8.4 I solve the problem:

    1. Like vincentrich says:

    My temporary fix was to edit wp-include/post-template.php:
    Line 616: $r[‘hierarchical’] = 0;
    Edit to: //$r[‘hierarchical’] = 0;

    2. Edit post.php in the /wp-includes

    if ( !empty($exclude_tree) ) {
    $excludetrees = array();
    $excludetrees = preg_split(‘/[\s,]+/’,$exclude_tree);
    // $exclude = (int) $exclude_tree;
    foreach ($excludetrees as $exclude) { $children = get_page_children($exclude, $pages);
    $excludes = array();
    foreach ( $children as $child )
    $excludes[] = $child->ID;
    $excludes[] = $exclude;
    $total = count($pages);
    for ( $i = 0; $i < $total; $i++ ) {
    if ( in_array($pages[$i]->ID, $excludes) )
    unset($pages[$i]);
    }
    }
    }

    Hi Rafff. I tried your code but it doesn’t seem to register all the arguments in my exclude_tree. For example here is my code:

    <?php wp_list_pages('exclude_tree=3,7,9,2&title_li='); ?>

    It’s only removing 3, while 7,9 and 2 are still visible. This is important functionality – does anyone know if the folks at WordPress are working on an official fix?

    Yes, this is very irritating, I’ve got the same problem with an update to 2.8.4, I’ve been banging my head against a wall for some time now – tried the fixes you suggested rafff, but to no avail.

    thelim3y’s fix works, sort of. The problem is it only exludes the first level of subpages, grandchildren are not excluded. Not really my definition of exclude tree, which in my mind should actually exclude the entire tree.

    So it means I need to manually add 10 different trees to exclude, rather than just the top level page. Annoying.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘WordPress 2.7 wp_list_pages Exclude Broken?’ is closed to new replies.