Displaying the parent page link on a menu, but only on certain pages (1 post)

  1. LucyRyder
    Posted 3 years ago #

    Hello there!
    I am using the Child Page navigation plugin for child page menus on the 2nd level pages of my site:
    (right hand teal menu)

    I am trying to add some code to the plugin which will display also the parent page link at the top of this child page link menu, but only on certain 2nd level pages.

    The code needs to basically say:
    "if is_page id 6, display the parent page link as the first
    li in this child page menu, and give it a class of li class="current_page"
    "if is pages 8,10, or 33, again display the parent page link as the first li, but do not then give it the class."
    I'm trying this on my local version o the site which unfortunately i haven't hooked up t a live URL for you to see, but So far I have the link appearing correctly at the top of the child page menu when on the parent page, but can't get it to work on the other child pages when the parent links still needs to be at the top of the menu. The code I have tried is:

    $parent_title = get_the_title($post->post_parent);
                        if (is_page(6)){
                         echo "<li class='current_page'><a href='".get_permalink($post->post_parent)."'>$parent_title</a></li>";
    				if (is_page(array( 8, 10, 33 ))){
                         echo "<li><a href='".get_permalink($post->post_parent)."'>$parent_title</a></li>";

    Although the first if statement seems to work, I also don't know if just using $parent_title in the li

    tag is correct?

    Any help would be massively appreciated!!!!

    Thanks in advance kind coders :)

Topic Closed

This topic has been closed to new replies.

About this Topic