WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display most recent blog post from category (4 posts)

  1. Claire
    Member
    Posted 8 months ago #

    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?

  2. viky081
    Member
    Posted 8 months ago #

    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

  3. endocreative
    Member
    Posted 8 months ago #

    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();
    ?>
  4. Claire
    Member
    Posted 8 months ago #

    Thank you so much!

Reply

You must log in to post.

About this Topic