Link to latest post by category
-
Hopefully someone can help me on this.
I have found this thread which is of great use.
This creates a link to the latest post from a certain category, however I would like to do this 6 times in a page, with each link to a different category.
I’ve tried a few simple edits on this but with no luck. This is my main query and would be delighted If I could resolve this.
Further to this (not as important!) I would like to have this linked by image rather than text. I am using the custom field function to insert an image but the code below does not show the image:
<?php //list post title for one post is specified category $cat = 5; //category ID $args=array( 'category__in' => array($cat), 'showposts'=>1, 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Fashion"><img src="<?php $fashion = get_post_meta($post->ID,'fashion',true); if ($fashion) { echo $fashion; } else { img(); }?>"/></a></p> <?php endwhile; } wp_reset_query(); // Restore global post data stomped by the_post(). ?>
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Link to latest post by category’ is closed to new replies.