WordPress.org

Ready to get started?Download WordPress

Forums

Dynamic return of page_id? (18 posts)

  1. ccheaton
    Member
    Posted 8 years ago #

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

  2. Kafkaesqui

    Posted 8 years ago #

    Try this:

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

  3. ccheaton
    Member
    Posted 8 years ago #

    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?

  4. ccheaton
    Member
    Posted 8 years ago #

    Anybody?

  5. Joshua Sigar
    Member
    Posted 8 years ago #

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

  6. TechGnome
    Moderator
    Posted 8 years ago #

    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

  7. ccheaton
    Member
    Posted 8 years ago #

    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.

  8. Joshua Sigar
    Member
    Posted 8 years ago #

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

  9. ccheaton
    Member
    Posted 8 years ago #

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

  10. TechGnome
    Moderator
    Posted 8 years ago #

    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

  11. Joshua Sigar
    Member
    Posted 8 years ago #

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

  12. ccheaton
    Member
    Posted 8 years ago #

    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:
    http://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.

  13. ccheaton
    Member
    Posted 8 years ago #

    I should add that it is WP 1.5.2

  14. Joshua Sigar
    Member
    Posted 8 years ago #

    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.

  15. ccheaton
    Member
    Posted 8 years ago #

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

  16. TechGnome
    Moderator
    Posted 8 years ago #

    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

  17. ccheaton
    Member
    Posted 8 years ago #

    Thanks for the help! I just removed the code for the time being. I'd like to get this working, though, so if you think of anything, or if you try it in an updated version, let me know!

  18. TechGnome
    Moderator
    Posted 8 years ago #

    I've uipgraded to the latest,..... and the code snip still works, so it isn't a WP version problem....

    Ok, let's try this:
    1) When do you want it to appear, only when a Page is displayed, right?
    2) Where do you want it displayed? On the page somewhere, or in the side bar?

    Tg

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.