Displaying post titles from specific category in WordPress

I would like to display a few post titles from a specific category on homepage. First one have to be with a small thumbnail and excerpt and rest of them just title. Below this section I would like to have a link clicking on which will show all the posts under this category.

like this http://i.stack.imgur.com/N5jUA.jpg

Related posts

Leave a Reply

3 comments

  1. As arslaan ejaz said, you can use wp_query. But I think that answer is not enough for your question. You want to show first post with thumbnail and others with titles only right?. It can be done by php count. Here is what I am using on my site. check below code, it will show first post with thumbnail, title and excerpt, other three posts with title only from category ID 1.

    <div class="main-div">
    <div class="thumbnaildiv">
    <?php $count=1; $query = new WP_Query('showposts=4&cat=1&offset=0'); if ($query->have_posts()) : ?>
    <?php while ($query->have_posts()) : $query->the_post(); ?> 
    <?php if($count==1){ ?> 
        <h2>
            <a href="<?php the_permalink() ?>" rel="bookmark">
            <?php the_title(); ?></a>
       </h2>
       <div class="thumb">
            <a href="<?php the_permalink(); ?>">
            <?php the_post_thumbnail('thumbnail'); ?>
            </a>
            <p><?php the_excerpt(); ?> ...</p>
       </div>
    </div><!--div with thumbnail, title, and excerpt end-->
    <div style="clear:both"></div>
       <div class="without-thumb">
           <ul>
           <?php } if($count>1){ ?> 
               <li>
                   <a href="<?php the_permalink() ?>" rel="bookmark">
                   <?php the_title(); ?></a>
               </li>
          <?php }  if($count==4){ ?>
          </ul>
          <?php } ?>
          <?php $count++; endwhile; else: endif; wp_reset_postdata(); ?> 
       </div><!--div without thumbnail end-->
    </div><!--main div end-->
    

    The div’s I have used is for information purpose only. You can change and style it as desired.

  2. Use WP-Query:

    <?php    
    $args = array('cat'=>1);
    
    // The Query
    $query = new WP_Query( $args );
    
    // The Loop
    if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
            $query->the_post();
            echo '<li>' . get_the_title() . '</li>';
                echo '<li>' . the_permalink() . '</li>';
                echo '<li>' . the_excerpt() . '</li>';
        }
    } else {
        // no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();
    

    It will list all posts of category 1, with title, permalink, and excerpt

    More info: wp_query

  3. I can recommend you to add ‘Elementor’ plugin. With this plugin, you can add ‘read more’ and split your text. If you add ‘read more’ in the beginning of your text then there will be shown only title and under the title a ‘read more’ link.

    Here is the Screenshot