• HappyCloud

    (@happycloud)


    Is there any way to link each child page link to a particular div within my theme template?

    For example; Link “About us” to domainname.com/aboutus#div3 ?

    The code I am using is listed below.

    <?php
      			if($post->post_parent)
     				 $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
      			else
      				$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
      			if ($children) { ?>
      				<ul class="sub-menu">
      					<?php echo $children; ?>
      				</ul>
     		 <?php } ?>

    Thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter HappyCloud

    (@happycloud)

    Still looking for a solution

    i can only think to do it by doing away with the wp_list_pages call and using several $wpdb calls to generate arrays of your page lists and their children..

    i do this with all my pages as it gives me a MUCH greater control over what gets displayed and how..

    $nav_item = $wpdb->get_col("SELECT post_title FROM <code>wp_posts</code> WHERE post_type='page' AND post_status ='publish' AND post_parent =0");
                $nav_link = $wpdb->get_col("SELECT post_name FROM <code>wp_posts</code> WHERE post_type='page' AND post_status ='publish' AND post_parent =0");
    
                        for($i = 0; $i < count($nav_item); $i++){
                            if($nav_link[$i] != 'checkout' && $nav_link[$i] != 'callback' && $nav_link[$i] != 'my-account' && $nav_link[$i] != 'admin-options' && $nav_link[$i] != 'privacy' && $nav_link[$i] != 'terms' && $nav_link[$i] != 'home' && $nav_link[$i] != 'my-profile'){
    
    							echo "<li><a href=\"";
    							bloginfo('url');
    							echo "/".strtolower($nav_link[$i])."\" title=\"".strtoupper($nav_item[$i])."\"><div class=\"nav_left\"></div><div class=\"nav_link\">".strtoupper($nav_item[$i])."</div><div class=\"nav_right\"></div></a>";
    
    							echo "</li>";	
    
                            }
                        }

    ive been using something like above to add curved corners to the edges of my nav items..

    youd want something like

    $sub_nav_link = $wpdb->get_col("SELECT post_name FROM <code>wp_posts</code> WHERE post_type='page' AND post_status ='publish' AND post_parent !=0");

    to get your child page names and then you just check if the post parent of that post is equal to the current list item.. and then start another ul inside that li..

    hope that helps

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to link page to certain div within template’ is closed to new replies.