• Resolved rmetfd

    (@rmetfd)


    Hey folks.

    At the moment, I have the following menu structure:

    Parent 1
    Child 1A
    Child 1B
    Child 1Aa
    Parent 2
    Child 2A
    Child 2B
    Parent 3

    When you click on Parent 1, my sidebar menu shows the following:

    Child 1A
    Child 1B
    Child 1Aa

    I want to have a heading at the top of the menu called Parent 1, and have this as a clickable link back to the parent (can be active when on parent as well)

    I’m currently using the wp_nav_plus plugin to show my menu and its great, so Im limited as to editing my menu. The whole site runs off one menu. But I am willing to add some code into the template above my menu to show the Tier 1 page (Parent 1)

    IE something like this

    <?php some sort of code to call depth=0 parent for all child pages and parent itself ?>
    <div ="sidebarmenu">
    <?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('SidebarMenu')) : ?>
    <?php endif; ?>
    </div>

    My speciality is in CSS and HTML and im only somewhat familiar with wordpresses PHP functions. I usually use search engines to find the code I need and haven’t managed to find anything like this.

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

    (@rmetfd)

    I’ve found two pieces of code that may help but dont know how I should combine them to achieve the function

    <?php get_ancestors( $object_id, $object_type ); ?>

    <?php $permalink = get_permalink( $id ); ?>

    Thread Starter rmetfd

    (@rmetfd)

    Found a solution.

    For everybodies information…

    in functions.php

    function my_page_ancestor() {
         global $post;     if( !is_front_page() ) {
    $parents = get_post_ancestors( $post );         $top_parent_link = get_permalink( end($parents) );         echo '<a href="' . $top_parent_link . '"><span class="pageAncestor">' . get_the_title( end($parents) ) . '</span></a>';
    }
    }

    on the page template

    `<?php my_page_ancestor();?>’

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Menu Heading as Link’ is closed to new replies.