0

I'm using this code to display a recent WordPress post on my homepage (I am using this code to display a post as I use a static homepage):

<?php 
$arguments = array('numberposts' => '1');
$posts = wp_get_recent_posts($arguments);
foreach($posts as $post){
the_post_thumbnail('full');
the_title();
the_excerpt();
}
?>  

However, I need to be able to add specific classed to the title and excerpt, so the output would be similar to:

<h1> The Title </h1>
<div class="large-8 columns"> Content from the_excerpt </div>

Currently, it simply outputs the code with no classes or divs.

1 Answer 1

3
<?php 
$arguments = array('numberposts' => '1');
$posts = wp_get_recent_posts($arguments);
foreach($posts as $post):
?>

<?php the_post_thumbnail('full'); ?>
<h1><?php the_title(); ?></h1>
<div class="large-8 columns"><?php the_excerpt(); ?></div>

<?php endforeach; ?> 

You can break out of php to write html. There should be many examples of this in the default wordpress template files.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.