Support » Fixing WordPress » Display most recent blog post from category

  • Resolved Claire

    (@clairewickenden)


    Hey! I would like to know how to add the following to my homepage:

    I need to display the most recent blog post from a certain category, with only the title and summary (content before the Insert More Tag), plus the featured image beside it.

    I am assuming this is some php code I would need to add?

Viewing 3 replies - 1 through 3 (of 3 total)
  • viky081

    (@viky081)

    Hi,
    You could read the codex of wordpress here
    http://codex.wordpress.org/Function_Reference/wp_get_recent_posts
    That above link contain more and more example which is really helpful for you.

    Thanks,
    vicky

    Jeremy Green

    (@endocreative)

    You could WP Query to pull in one post from a certain category and use it to pull in the data you need. Something like:

    <?php 
    
    $args = array(
    'posts_per_page' => 1,
    'cat' => $your_category_id
    );
    $the_query = new WP_Query( $args );
    
    if ( $the_query->have_posts() ) {
            echo '<div>';
    	while ( $the_query->have_posts() ) {
    		$the_query->the_post();
                    get_the_post_thumbnail();
    		echo '<h3><a href="' . get_permalink() . '">'  . get_the_title() . '</a></h3>';
                    echo  get_the_content('Read more');
    	}
            echo '</div>';
    } else {
    	// no posts found
    }
    
    wp_reset_postdata();
    ?>
    Claire

    (@clairewickenden)

    Thank you so much!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display most recent blog post from category’ is closed to new replies.