Forums

link to latest post in category (2 posts)

  1. Travel-Junkie
    Member
    Posted 5 years ago #

    i have a categoy i have set up as a fotoblog. in my menu bar i am trying to link directly to the latest post in that category. i am trying to use the loop to do this, but unfortunatly it doesn't work properly with the utw tag pages.
    the code i use to display the link is this:

    <a href="<?php
    $my_query = new WP_Query('category_name=photoblog&showposts=1');
    while ($my_query->have_posts()) : $my_query->the_post(); {
    the_permalink();
    } endwhile; ?>" <?php if (is_category('photoblog') || is_single() && in_category('2')){ echo " id=\"current\"";}?>><?php _e('photoblog') ?></a>  |

    this works great (e.g. here), unless you go to a tag page (e.g. here). then, the loop just links to the page you are on at the moment. any ideas as to why that happens?
    thanks, b

  2. Travel-Junkie
    Member
    Posted 5 years ago #

    i just saw that there seems to be a conflict with that mini loop and the way the menu highlighting works. when i go to a single page of whatever category, then photoblog in the menu is always highlighted (e.g. here).
    is there maybe another way to get the latest link displayed?

    here's the code for the whole menu bar:

    <div id="navigation">
    <a href="/" <?php if (is_home()){ echo " id=\"current\"";}?>><?php _e('home') ?></a>  |
    <a href="/category/travelogues/"<?php if (is_category('travelogues') || is_single() && in_category('1')){ echo " id=\"current\"";}?>><?php _e('travelogues') ?></a>  |
    <a href="<?php
    $my_query = new WP_Query('category_name=photoblog&showposts=1');
    while ($my_query->have_posts()) : $my_query->the_post(); {
    the_permalink();
    } endwhile; ?>" <?php if (is_category('photoblog') || is_single() && in_category(2)){ echo " id=\"current\"";}?>><?php _e('photoblog') ?></a>  |
    <a href="/about-me" <?php if (is_page('about-me') || is_page('qualifications') || is_page(23)){ echo " id=\"current\"";}?>><?php _e('about me') ?></a>  |
    <a href="/travel-map" <?php if (is_page('travel-map')){ echo " id=\"current\"";}?>><?php _e('travel map') ?></a>  |
    <a href="/cheeky-site" <?php if (is_page('cheeky-site') || is_page(15) || is_page(34)){ echo " id=\"current\"";}?>><?php _e('support') ?></a>  |
    <a href="/archives" <?php if (is_page('116') || is_month() || is_tag() || is_page('103') || is_page('119') || is_page('127')){ echo " id=\"current\"";}?>><?php _e('archives') ?></a>
    </div>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags