WordPress.org

Ready to get started?Download WordPress

Forums

Some help with a code snippet? (7 posts)

  1. jgpippin
    Member
    Posted 9 years ago #

    I'm trying to concoct a code snippet that, when viewing a parent page or its children, will show only the children of said parent in the side bar.

    I can use the child_of argument to refer to a specific parent:

    <?php wp_list_pages('child_of=3&title_li=<h2>' . __('Pages') . '</h2>' ); ?>

    But that won't detect which parent (or subsequent children) are in view.

    Someone on another post posted this bit of code:

    <?php
    if($wp_query->is_page && !is_home()) {
    $lp_param = "";
    $lp_param = "title_li=&depth=1&child_of=" .
    $wp_query->get_queried_object_id();
    wp_list_pages($lp_param);
    }
    ?>

    But a) the li is gone, and b) the list of children disappears whenever you look at any page other than the parent.

    I'm new to WP, and don't know how to write this code myself. Can anyone help?

  2. jgpippin
    Member
    Posted 9 years ago #

    please help!

  3. jgpippin
    Member
    Posted 9 years ago #

    i really hate to bump, but i'm in a bad way on this.

  4. jgpippin
    Member
    Posted 9 years ago #

    Really? No takers at all?

  5. nearlythere
    Member
    Posted 9 years ago #

    i'm new to WP, so i won't be much help to you but i feel bad for you. so i gave the code above a go.

    this piece of code appears to be hard-wiring to show the children of a particular page, and if you put it in the side-bar it will appear on all pages.
    <?php wp_list_pages('child_of=3&title_li=<h2>' . __('Pages') . '</h2>' ); ?>

    this piece put out nothing for me at all, but i can see that it is checking if the current page is 'home'.

    <?php if($wp_query->is_page && !is_home()) {
    $lp_param = "";
    $lp_param = "title_li=&depth=1&child_of=" .
    $wp_query->get_queried_object_id();
    wp_list_pages($lp_param);
    }
    ?>

    so i did a search for keywords, child parent page and came up with these posts, which i will dig into now... i'll get back to you if i can finger something out.

    http://wordpress.org/support/topic.php?id=24230#post-139411

    http://wordpress.org/support/topic.php?id=24230#post-136812

    http://wordpress.org/support/topic.php?id=25207#post-141907

    in terms of getting feedback- i've noticed we might get better response by giving our posts keyworded titles like 'Show only child pages' or something like that. Since the forums only list *so very few* recent posts on the first page- only the last few hours show up. So you might get more response by people searching for same topic, and that's where the title is important!

    -h

  6. jgpippin
    Member
    Posted 9 years ago #

    I appreciate your desire to help; unfortunately, I read all of those posts before I posted this one.

    At one point, someone purported to have solved the problem, but never posted the solution.

  7. crash
    Member
    Posted 9 years ago #

    i think this is what you're looking for.

    http://codex.wordpress.org/Template_Tags/wp_list_pages

    scroll down and read about the child_of parameter

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.