WordPress.org

Ready to get started?Download WordPress

Forums

Dynamic parent page highligtning (1 post)

  1. schmolzer
    Member
    Posted 4 years ago #

    Hi!

    I want to highlight my parent and grandparent pages, when on a child page.
    And I don't know how. Please help me, I have looked at other posts and found this piece of code :

    <?php>
    function has_parent($post, $post_id) {
      if ($post->ID == $post_id) return true;
      else if ($post->post_parent == 0) return false;
      else return has_parent(get_post($post->post_parent),$post_id);
    }
    ?>
    
    <?php global $wp_query; if( has_parent($wp_query->post), 3) :?>
    <?php endif; ?>

    But I don't know how I'm supposed to write to make it work!
    Thank you in advance

    I have two menus:

    <div id="topNav">
    	<div id="topNav_topShadow"></div>
        <div id="topNav_content">
    
        	<ul id="menu">
                           <li class="urskog"<?php
                    if (is_page('urskog'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a>/urskog">Urskog</a>
    
                 <li class="products"<?php
                    if(is_page('products'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a>/products/lov/walnut">Products</a>
    
                  <li class="press"<?php
                    if(is_page('press'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a>/press">Press</a>
    
                 <li class="contact"<?php
                    if(is_page('contact'))
                    {
                    echo " id=\"current\"";
                    }?>>
                    <a>/contact">Kontakt</a>
    
            <li class="separator">

    My second menu:

    <ul>
    				<li class="mainNav_lov"<?php 
    
    					if (is_page('lov')) 
    
    					{
    					echo " id=\"current2\"";
    
    					}?>>
    
    					<a>/products/lov/walnut">Lov</a>
    
    				<li class="mainNav_miniLov"<?php 
    
    					if (is_page('minilov')) 
    
    					{
    
    					echo " id=\"current2\"";
    
    					}?>>
    
    					<a>/products/minilov/walnut">Mini Lov</a>
    
    				<li class="mainNav_pinne"<?php 
    
    					if (is_page('pinne')) 
    
    					{
    
    					echo " id=\"current2\"";
    
    					}?>>
    
    					<a>/products/pinne/walnut">Pinne</a>
    
    				<li class="mainNav_pokus"<?php 
    
    					if (is_page('pokus')) 
    
    					{
    
    					echo " id=\"current2\"";
    
    					}?>>
    
    					<a>/products/pokus/walnut">Pokus</a>
    
    				<li class="mainNav_kil"<?php 
    
    					if (is_page('kil')) 
    
    					{
    
    					echo " id=\"current2\"";
    
    					}?>>
    
    					<a>/products/kil">Kil</a>
    
    				<li class="mainNav_skate"<?php 
    
    					if (is_page('skate')) 
    
    					{
    
    					echo " id=\"current2\"";
    
    					}?>>
    
    					<a>/products/skate/walnut">Skate</a>
    
    			<li class="mainNav_drivved"<?php 	
    
    				if (is_page('drivved'))
    
    				{
    				echo " id=\"current2\"";
    
    				}?>>	
    
    				<a href="<?php bloginfo('url') ?>/products/drivved">Drivved</a>
    
    			</li>
                                    <li class="mainNav_separator">
    
    </ul>

Topic Closed

This topic has been closed to new replies.

About this Topic