How to compare a "post title" to "navigation title" and highlight (3 posts)

  1. Kampflebkuchen
    Posted 4 years ago #

    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.

    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;?>
  2. Michael
    Forum Moderator
    Posted 4 years ago #

    within the logic of your code, you could try:

    <?php if ($page_title == get_the_title()) : ?>
  3. Kampflebkuchen
    Posted 4 years ago #

    Thank you alchymyth :) It worked!

Topic Closed

This topic has been closed to new replies.

About this Topic