post_status question with wp_list_pages() function
-
I have a need to build a menu of page links horizontally along my footer element… no issues on design or using wp_list_pages() to do it, etc but I need to have the resulting link(s) not display if that page isn’t published at the time, to not display.
I know normally it wouldn’t if I just used:
<?php wp_list_pages('include=4&title_li='); ?><?php wp_list_pages('include=52&title_li='); ?><?php wp_list_pages('include=17&title_li='); ?>BUT, I need to have something look selected as well when appropriate — even if on a child page of one of the links… I can hardcode this easily (real example below):
<li <?php if (is_page(4)) {echo ' class="footselected"'; } else {} ?>><span>|</span> <a href="url">Contact Us</a> </li><li<?php if (is_page(52)) {echo ' class="footselected"'; } else {} ?>><span>|</span> <a href="url">Subscribe</a> </li><li<?php if (is_page(17)) {echo ' class="footselected"'; } else {} ?>><span>|</span> <a href="url">Resources</a> </li>The problem with trying to use wp_list_pages() to generate both the link and text of the link is that A) I cannot use my conditional class=”footselected” code because there’s no place INSIDE the wp_list_pages() function to pass that…. is there?
So, I thought that maybe there was a way to use something equivalent to if post_status == ‘publish’ wrapped around each or the group?
Any hints, folks?
I know I can use it this way:
<?php // Set output to be empty $output = ''; // Get pages $pages = get_pages("child_of=18&sort_column=post_title&title_li="); // Build output foreach ($pages as $page) { $output .= ($page->post_status == 'publish') ? '<div class="clients">'.$page->post_excerpt.'</div>' : ''; } // Display output echo $output; ?>to generate markup and metadata for a page or child page, but cannot figure how to apply that to the footer links where I only want a specific few pages — not all that are published and I want to use wp_list_pages().
The topic ‘post_status question with wp_list_pages() function’ is closed to new replies.