• Resolved jay.weeks

    (@jayweeks)


    i want to link to the latest post for four different categories.
    can’t seem to get it to work

    <?php
    	$nc = get_cat_id('news');
    	query_posts('cat=$nc');
    	?>
    <?php
    	$latestNewsPost = get_posts('numberposts=1&category=$nc');
    	$latestNewsPostID = $wp_query->$latestNewsPost->ID;
    	?>
    
    <div class="home-header" id="news-head"><a title="news" href="<?php echo get_permalink($latestNewsPostID); ?> ">news</a></div>
Viewing 2 replies - 1 through 2 (of 2 total)
  • This is what I use to show the permalink of the latest post in “my_category”, and in one instance, I use several of these loops on one page to show the latest post in three different categories. Seems like each new query doesn’t conflict with any of the others.

    <?php $my_query = new WP_Query('category_name=my_category&showposts=1'); ?><?php while ($my_query->have_posts()) : $my_query->the_post(); ?><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a><?php endwhile; ?>

    Thread Starter jay.weeks

    (@jayweeks)

    cool, seems to be working

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘get latest post id by category’ is closed to new replies.