WordPress.org

Forums

Recent posts on homepage showing full post not excerpt (4 posts)

  1. chocula
    Member
    Posted 1 year ago #

    I have managed to get recent posts showing on my homepage which is working well. They only problem i have is that the full post and not the excerpt is showing.

    <div id="home-news-container">
    
    <?php query_posts('cat=#&posts_per_page=3'); ?>
    <?php while (have_posts()) : the_post(); ?>
    
        <div class="home-post-container">
    
              <div class="home-post-thumb">
                  <a href="<?php echo get_permalink(); ?>">
                            <?php the_post_thumbnail('large_wide'); ?>
                  </a>
              </div>
    
              <div class="home-post-copy">
                      <h4>
                          <a href="<?php echo get_permalink(); ?>">
                               <?php the_title(); ?>
                          </a>
                     </h4>
                     <h5>
                          <?php the_date(); ?>
                      </h5>
                  <?php the_excerpt(); ?>
    
                  <div class="home-news-readmore">
                        <a href="<?php echo get_permalink(); ?>">read more</a>
                  </div>
            </div>
    
       </div> <!-- end home-post-container -->
    
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
    
              <div class="home-news-readmore news-extra">
                   <a href="">more news</a>
              </div>  
    
    </div> <!--- end home-post-container -->

    I don't understand what the problem is to be honest. I created a new full width template for the homepage which i thought might be causing it but its not. Bit stumped to be honest. Any help would be greatly appreciated

  2. You have an issue with this line:

    <?php query_posts('cat=#&posts_per_page=3'); ?>

    You are not using a valid "cat" value. Either enter a category number, like this (if category id 8 was desired):

    <?php query_posts(array('cat' => '8', 'posts_per_page' => '3'); ?>

    Or, remove the "cat" value altogether:

    <?php query_posts('posts_per_page=3'); ?>
  3. chocula
    Member
    Posted 1 year ago #

    Good point, I don't need a category so i removed it. Unfortunately it hasn't made any difference

  4. chocula
    Member
    Posted 1 year ago #

    I managed to fix it using this code instead of the_excerpt

    <?php
    
    $content = get_the_excerpt();
    
    echo wp_trim_words( $content , '30' ); ?>

    incase anyone else has this issue

Topic Closed

This topic has been closed to new replies.

About this Topic