• Hi. I’m trying to use:
    <?php wp_list_pages('child_of=2&title_li='); ?>

    But instead of ‘child_of=2’ I want to return the id of the current page. That way, this will only list the child pages of the page currently being viewed.

    What string do I have to use to get this to work? I can’t figure out the answer from the forums or codex… ??

Viewing 15 replies - 1 through 15 (of 17 total)
  • Try this:

    <?php wp_list_pages("child_of=$page_id&title_li="); ?>

    Thread Starter ccheaton

    (@ccheaton)

    Nope… when I try that I get the following:

    Warning: Invalid argument supplied for foreach() in path/to/my/install/wp-includes/template-functions-post.php on line 378

    However, that is what I’m trying to do. I just don’t know the PHP syntax for it. Any more suggestions?

    Thread Starter ccheaton

    (@ccheaton)

    Anybody?

    It should work. How did you add the code?
    Post the whole file here https://paste.uni.cc/

    And here’s the part that sucks…. here’s how I ended up solving the issue: code in pastebin/

    Basicaly I had to loop through all my pages until I found the one that matched by using is_page(). Then I pass that ID to the wp_list_pages…. there’s a catch though, it doesn’t properly check to see if there are any child pages to the current one (although it should, I’ll have to work on that.)

    You can see how it does work at my site.

    Tg

    Thread Starter ccheaton

    (@ccheaton)

    Thanks, TechGnome. alphaoide, I pasted the code in exactly where I had the bit that I posted in my first message here. While the bit that I posted always returns the posts that are the child of page 2, your bit always returns the error that I posted above.

    TechGnome, where do you have that code inserted? Does it have to be outside of the loop? I’m using a modified version of the Connections theme, and I had it in post.php. It returns an error that there’s an unexpected $ when I put it where I originally had my bit of code.

    ccheaton, I want you to paste the whole file where that snippet of code goes. https://paste.uni.cc

    Thread Starter ccheaton

    (@ccheaton)

    Ok… is this right?
    https://paste.uni.cc/7648

    Ummm mine is in the side bar…. it’s for listing child pages of the current page (nothing to do with posts). And is outside the loop.

    Tg

    I’ve modified your code to take affect only when viewing a Page.
    https://paste.uni.cc/7649

    Thread Starter ccheaton

    (@ccheaton)

    Ok, well, now I only get the error message when I’m displaying a page. What I’m trying to do is to have a list of the sub-pages of a particular page appear when that page is viewed. Ideally, it would appear after the content of the page — perhaps at the bottom. However, having it appear in the loop would be good, too.

    I get the same error, but just on pages. You can look here:
    https://www.thejoyoflex.com/dtree

    Notice that there is a post on the homepage, but that the About Us link is to a page. I pasted the code into the post.php exactly as it appeared in the link from above…

    Suggestions? Do I have to use PHP to echo the page_id into the statement? Somehow it’s just not working.

    Thread Starter ccheaton

    (@ccheaton)

    I should add that it is WP 1.5.2

    Try moving line 8-10 to outside The Loop, then. The Loop is probably in index.php. So, put it after The Loop in index.php.

    Thread Starter ccheaton

    (@ccheaton)

    Hmm… same problem. It’s now outside of the loop and doing the same thing.

    That’s weird because the behavior you are trying to get is exactly what that code does. It could be that I am a little behind in the code base (shhh! don’t tell anyone.) so it may be a core versioning difference….. dang, now yo uhave me concerned about it…

    tg

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘Dynamic return of page_id?’ is closed to new replies.