Support » Fixing WordPress » How to compare a "post title" to "navigation title" and highlight
4 years, 11 months ago
I am trying to highlight a navigation element if it has the same title as the current page being shown.
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; ?>
within the logic of your code, you could try:
<?php if ($page_title == get_the_title()) : ?>
Thank you alchymyth 🙂 It worked!