How to say "if sub navigation exists", need help...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

How to say "if sub navigation exists", need help...

Post by WithHisStripes »

So I'm working on this site based on Wordpress: http://www.thedaylightstudio.com/testin ... ng_counsel

And when you rollover over "Endorsements" it should show a different background image than all of the others. This is because they all have sub navigation elements and this one doesn't. So I need to write a PHP statement that says "If sub pages are listed beneath this than echo" but I'm not sure how to do that. Can anyone help?

Thanks!
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

Re: How to say "if sub navigation exists", need help...

Post by paqman »

Can you post the code that outputs those tabs?
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

Re: How to say "if sub navigation exists", need help...

Post by WithHisStripes »

Yep:

Code: Select all

<div class="row-2-col-1">
                    <img src="../wp-content/themes/coaching-counsel/images/portrait-of-founder.jpg" /><!-- This enables use for the additional fields option when creating a Wordpress page or post. -->
                    
                    <br />
                    
                    <!-- This lists the navigation for all "Pages" within the account -->
                    <li class="page_item page-item-7"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/archives" title="Coaching Corners Blog">Coaching Corners Blog</a>
<ul>
    <li class="page_item page-item-129"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/archives/example-2" title="Example 2">Example 2</a></li>
</ul>
</li>
<li class="page_item page-item-9"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/presentations" title="Presentations">Presentations</a>
<ul>
    <li class="page_item page-item-74"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/presentations/example" title="Example">Example</a></li>
    <li class="page_item page-item-133"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/presentations/example-2" title="Example 2">Example 2</a></li>
</ul>
</li>
<li class="page_item page-item-11"><a href="resources" title="Endorsements">Endorsements</a></li>
<li class="page_item page-item-13"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/writings" title="Writings">Writings</a>
<ul>
    <li class="page_item page-item-79"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/writings/example" title="Example">Example</a></li>
    <li class="page_item page-item-137"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/writings/example-2" title="Example 2">Example 2</a></li>
</ul>
</li>
<li class="page_item page-item-15"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/references-links" title="References & Links">References & Links</a>
<ul>
    <li class="page_item page-item-81"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/references-links/example" title="Example">Example</a></li>
    <li class="page_item page-item-139"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/references-links/example-2" title="Example 2">Example 2</a></li>
</ul>
</li>
<li class="page_item page-item-47"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/services/for-business-professionals" title="For Business Professionals">For Business Professionals</a></li>
<li class="page_item page-item-27"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/services/for-lawyers" title="For Lawyers">For Lawyers</a></li>
<li class="page_item page-item-96"><a href="http://www.thedaylightstudio.com/testing/mpp/coaching_counsel/services/transitions" title="Transitions">Transitions</a></li>
                </div>
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

Re: How to say "if sub navigation exists", need help...

Post by paqman »

Is that the php code which outputs the list? That looks like the html output to me...
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

Re: How to say "if sub navigation exists", need help...

Post by WithHisStripes »

Oh my mistake, here's the PHP:

Code: Select all

<div class="row-1-navigation">
                <?php  ?>
                <ul><?php
                        if($post->post_parent)
                            $children = wp_list_pages('include=2,3,4,21,27,47,53,96&title_li=&child_of='.$post->post_parent.'&echo=0'); else
                            $children = wp_list_pages('include=2,3,4,21,27,47,53,96&title_li=&child_of='.$post->ID.'&echo=0');
                        if ($children) { ?>
                            <li>
                                <h2><?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?></h2>
                            <ul>
                                <?php echo $children; ?>
                            </ul>
                            </li>
                    <?php } ?>
                </ul>
                <?php  ?>
                </div>
User avatar
paqman
Forum Contributor
Posts: 125
Joined: Sun Nov 14, 2004 7:41 pm
Location: Burnaby, BC, Canada

Re: How to say "if sub navigation exists", need help...

Post by paqman »

No worries - if that was the PHP code I couldn't have helped haha. It looks like the function wp_list_pages generates those links, so can you find that function and post it to the forum? Within there you might have luck with your problem.
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

Re: How to say "if sub navigation exists", need help...

Post by WithHisStripes »

Code: Select all

function wp_list_pages($args = '') {
    $defaults = array(
        'depth' => 0, 'show_date' => '',
        'date_format' => get_option('date_format'),
        'child_of' => 0, 'exclude' => '',
        'title_li' => __('Pages'), 'echo' => 1,
        'authors' => '', 'sort_column' => 'menu_order, post_title',
        'link_before' => '', 'link_after' => ''
    );
 
    $r = wp_parse_args( $args, $defaults );
    extract( $r, EXTR_SKIP );
 
    $output = '';
    $current_page = 0;
 
    // sanitize, mostly to keep spaces out
    $r['exclude'] = preg_replace('/[^0-9,]/', '', $r['exclude']);
 
    // Allow plugins to filter an array of excluded pages
    $r['exclude'] = implode(',', apply_filters('wp_list_pages_excludes', explode(',', $r['exclude'])));
 
    // Query pages.
    $r['hierarchical'] = 0;
    $pages = get_pages($r);
 
    if ( !empty($pages) ) {
        if ( $r['title_li'] )
            $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';
 
        global $wp_query;
        if ( is_page() || is_attachment() || $wp_query->is_posts_page )
            $current_page = $wp_query->get_queried_object_id();
        $output .= walk_page_tree($pages, $r['depth'], $current_page, $r);
 
        if ( $r['title_li'] )
            $output .= '</ul></li>';
    }
 
    $output = apply_filters('wp_list_pages', $output);
 
    if ( $r['echo'] )
        echo $output;
    else
        return $output;
}
Post Reply