WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] display bug for subpages on 404 and search results (4 posts)

  1. feistyred
    Member
    Posted 6 years ago #

    Not sure if this should be an advanced topic or not... but I'm using the following codex example to display subpage navigation links ONLY on pages that have child pages assigned, or when ON a child page:

    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>

    It works flawlessly except on the 404.php page, and erroneous search results pages (a.k.a any term that produces NO results). Instead, what's happening is the nav is being listed in its entirety (and in duplicate). You can see what I mean here:
    http://cornerstone.designadaptations.com/whatever

    Oddly enough, search terms that do produce results don't have the same bug, but still show child pages where there should be none. The two templates do nothing more than call the header as any normal page would. Does anyone have ANY CLUE why the code above would not work properly in those two instances? I'm stumped.

    p.s. The Basic Page demo is the only one with any child pages assigned.

  2. feistyred
    Member
    Posted 6 years ago #

    For anyone else desperately searching the forums on a related problem, maybe this will help... the solution for me was the Loop. I never realized you could add a separate Loop to the header (or even thought to try it), but it worked like a charm.

  3. Yoris
    Member
    Posted 6 years ago #

    Thanks!! I've been looking for a solution for this problem for some time now. And your solution works great for the 2 cases you've mentioned (404 page and erroneous search results).

    But by adding this loop, you've created a new location where this error occurs. Being: when a search returns results form different child pages, or pages that have child pages. Because of the loop, the nav is displayed for every search result that is or has a child page. (This is my guess) For example, try searching 'child' on your page.

    So I guess we are still looking for a (total) solution to our problem...

  4. Yoris
    Member
    Posted 6 years ago #

    Well I found another solution.

    <?php if(is_404() or is_search()) : ?>
    //put here what you want to show on your 404 and searchresults pages instead of de childpages
    <?php else : ?>
    
    <?php
    if($post->post_parent)
    $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0"); else
    $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    <ul>
    <?php echo $children; ?>
    </ul>
    <?php } ?>
    
    <?php endif; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic