WordPress.org

Ready to get started?Download WordPress

Forums

WordPress 2.7 wp_list_pages Exclude Broken? (20 posts)

  1. Vince
    Member
    Posted 5 years ago #

    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?

  2. Vince
    Member
    Posted 5 years ago #

    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.

  3. Vince
    Member
    Posted 5 years ago #

    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!

  4. Vince
    Member
    Posted 5 years ago #

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

    Someone reported a bug too....

  5. Vince
    Member
    Posted 5 years ago #

    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.

  6. tbrams
    Member
    Posted 5 years ago #

    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

  7. tbrams
    Member
    Posted 5 years ago #

    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

  8. PhrankDee
    Member
    Posted 5 years ago #

    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?

  9. thelim3y
    Member
    Posted 5 years ago #

    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.

  10. milky
    Member
    Posted 5 years ago #

    @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. :D

  11. milky
    Member
    Posted 5 years ago #

    ...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

  12. jtimar
    Member
    Posted 4 years ago #

    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 :(

  13. rafff
    Member
    Posted 4 years ago #

    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]);
    }
    }
    }

  14. eggnog
    Member
    Posted 4 years ago #

    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?

  15. pmcpartlan
    Member
    Posted 4 years ago #

    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.

  16. jtimar
    Member
    Posted 4 years ago #

    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.

  17. msagacious
    Member
    Posted 4 years ago #

    ahhh...
    Same problem here.. I am using wp 2.8.4.
    Even thelim3y's fix didn't work.

    Is there any other alternate to get the list of all sub pages of a particular Top Level Page?

    thesandeepgoyal@yahoo.com

  18. emile12
    Member
    Posted 4 years ago #

    i have the same problem
    i have try with the flexi page plugin and it's the same

    all the page i want to exclude are display

  19. walrock
    Member
    Posted 4 years ago #

    thelim3y's fix worked for me. this seems like a pretty amatuer oversight for something so critical to be outstanding without an official bug fix for the past 10 months. particularly given the large number of complaints on here.

    if anyone can direct how to submit this to relevant people, to put some emphasis on getting this including in the next official release please advise.

  20. voo
    Member
    Posted 4 years ago #

    K same here, this was happen to me and wat i did is use exclude instead of exclude_tree I know there is extra bit work how ever until it fix probably this is the best way if you develop themes for market else can use thelim3ys fix

Topic Closed

This topic has been closed to new replies.

About this Topic