WordPress.org

Ready to get started?Download WordPress

Forums

post_status question with wp_list_pages() function (2 posts)

  1. syncbox
    Member
    Posted 5 years ago #

    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>&nbsp;&nbsp;<a href="url">Contact Us</a>&nbsp;&nbsp;</li><li<?php if (is_page(52)) {echo ' class="footselected"'; } else {} ?>><span>|</span>&nbsp;&nbsp;<a href="url">Subscribe</a>&nbsp;&nbsp;</li><li<?php if (is_page(17)) {echo ' class="footselected"'; } else {} ?>><span>|</span>&nbsp;&nbsp;<a href="url">Resources</a>&nbsp;&nbsp;</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().

  2. syncbox
    Member
    Posted 5 years ago #

    Anyone? Surely this isn't too difficult for the gurus out there? I'm open to alternatives if my approach is just wack.

    Ideas? TIA!

Topic Closed

This topic has been closed to new replies.

About this Topic