WordPress.org

Support

Support » How-To and Troubleshooting » How to compare a "post title" to "navigation title" and highlight

How to compare a "post title" to "navigation title" and highlight

  • Hello everybody,
    I am trying to highlight a navigation element if it has the same title as the current page being shown.

    For example:

    If I Visit the Page “home” only the navigation button which has the title “home” should be given another css rule = opacity:1; how can I achieve this?

    For now, it queries the current category posts and links them to the single posts, but I don’t know what to compare and not completely mess it up.

    <?php
    foreach(get_the_category() as $category)
    {
    $cat = $category->category_nicename;
    }
    
    $page_title = get_the_title();
    ?>
    
    <?php query_posts('category_name=' . $cat . ''); ?>
    <?php while (have_posts()) : the_post(); ?>
    <?php if ($page_title == '###COMPARE HERE###') : ?>
    <div style="opacity:1;"><a href="<?php the_permalink() ?>"><strong><?php the_title(); ?></strong></a></div>
    
    <?php else : ?>
    
    <div><a href="<?php the_permalink() ?>"><strong><?php the_title(); ?></strong></a></div>
    <?php endif; ?>
    <?php endwhile;?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to compare a "post title" to "navigation title" and highlight’ is closed to new replies.