Any ideas, how I should do this:

Recent post (with comments) shown in page? I need fixed url example.com/question that shows the most recent post, style should be same as in normal one post? Can I use somehow single.php and loop.php?

EDIT: Simple example(?): I want single, recent post same way as single post, but with url that provides always the most recent post.

  • Can you add more details to your question, now it is not clear. Adding details with examples will also help. – Maruti Mohanty Apr 24 '14 at 7:31
  • What additional info is needed, I can provide if needed. – guestar Apr 24 '14 at 7:54

Here is a start. This is how I display related posts from the category the post are in. You will just need to add your own loop and CSS

Create a template called content-related.php

Inside that paste the following code

 * The default template for displaying realted posts
 * @package WordPress
 * @subpackage Pieter Goosen
 * @since pietergoosen 1.0

global $post;

// Define shared post arguments
$categories = get_the_category($post->ID);
if ($categories) :
$category_ids = array();
foreach($categories as $individual_category) 
$category_ids[] = $individual_category->term_id;

'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=>3, // Number of related posts that will be shown.

$query = new wp_query($args);

if ( $query->have_posts() ): ?>

<div class="related-posts block">

<h4 class="heading">
<?php _e('You may also like &hellip;','pietergoosen'); ?>

<div class="related-posts group">

<?php while ( $query->have_posts() ) : $query->the_post(); ?>


<?php endwhile; ?>

This code checks for the category (using WP_Query)of the post that is displayed using get_the_category($post->ID). From this, posts from this category is fetched. In this code, three posts ('posts_per_page'=>3,) will be displayed from the category of the post currently displayed. You can customize the query to suite your needs, also, you can customize your loop just the way you want to.

You can now call this in your single.php where you need to display your related posts using

get_template_part('content', 'related');

As for the styling, you will need to sort that out yourself. CSS related stuff is off-topic here BTW

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.