0

Hi I am needing some help trying to add the recent post excerpt to the bottom left div of my webpage.

below is the piece of code that I'm having problems with in-between the p tags. I can display the post title and the ID, But cant get the recent post content or the recent post excerpt.

     <!-- //start -->
               <h2>Recent Post</h2>
            <div class="recent-post-holder">

           
             <div class="recent-image-holder"><img  class="recent-image" src="images/feeding.jpg" alt=""></div>

            
             <?php 
              $args = array( 'numberposts' => '1' );
               $recent_posts = wp_get_recent_posts( $args );
                 
               foreach( $recent_posts as $recent ) {

                echo ' <div class="recent-text-holder"><a href="' . get_permalink($recent["ID"]) . '">' . $recent["post_title"]. '</a>
                <p>' . get_the_excerpt(). '</p> </div> '; 

     } ?>

I just want to add the post content in-between the <p> tags not sure were I'm going wrong iv tried the following in-between the p tags:

    $recent[post_excerpt]
    the_content()

I have been trying to find a solution to this I've looked through other similar post, But I cant get it to display the content. I was not sure if I need to create a while loop within the code to then return the post content, I'm not sure.

I am new to php and any help on this I would be grateful

Many thanks

1 Answer 1

1

You need to specify the ID, like you did for the link and title.

Try:

get_the_excerpt( $recent["ID"] ) 
2
  • That did work thanks alot, Funny I did try the_except($recent["ID]) before but now im reading the difference between the two and the_except($recent["ID]) does not take in a argument from what I read and the one you recommended get_the_excerpt( $recent["ID"] ) does. Thanks again for your help.
    – luke
    Commented Aug 18, 2021 at 12:59
  • If you found the answer useful, please accept it by clicking on the green check mark next to the answer.
    – shanebp
    Commented Aug 18, 2021 at 13:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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