WordPress.org

Ready to get started?Download WordPress

Forums

wp_list_pages and its echo (3 posts)

  1. moody
    Member
    Posted 8 years ago #

    What are some of the possibilities with using the echo parameter set to false of the wp_list_pages? In other words, what does it mean "return the list to be used in PHP"?

    Another way for me to ask the question is, How are others using this?

    Thanks.

  2. irakrakow
    Member
    Posted 8 years ago #

    The documentation has a useful example - testing a condition. Here's the code:

    <?php if(wp_list_pages("child_of=".$post->ID."&echo=0")) { ?>
    <ul>
    <?php wp_list_pages("title_li=&child_of=".$post->ID."&sort_column=menu_order&show_date=modified&date_format=$date_format");?>
    </ul>
    <?php } ?>

    The if test is testing to see whether there actually are any child posts. If there are any, then wp_list_pages is called again, with echo = 1 (true - the default) to actually output the child posts.

    You could generalize this to test for some other condition (such as the existence of a specific page name), do the if test, and if true, output the result by calling wp_list_pages again with echo = 1. Or, say, you want to display the child posts of ID 2 only if there are child posts of ID 1. It's a bit inefficient, requiring two calls to the same function, but it would do the job.

  3. moody
    Member
    Posted 8 years ago #

    Thanks irakrakow!

    I was hoping to somehow be able to use the echo parameter to some how give me some data that I can make my own list, BECAUSE, I have to have an separate image for each page in the links that are returned--with no text and without using CSS for making background images. The image must be in the HTML and the image visually describes the Page. More detail: the Page is a list of SubPages of people that some very obtrusive JavaScript uses to do some completely unnecessary behavior things.

    Currently I have a hardcoded include that is currently at 7 IFs and SubPages and will increase. It would be nice to use the database and WP to help me with this.

    Perhaps, is there a plugin that allows more, if not complete, control of how the links are outputted without having to edit the template-functions-post.php file?

    Any ideas?

Topic Closed

This topic has been closed to new replies.

About this Topic