简体   繁体   中英

How to Add HTML inside of PHP in WordPress

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.

<?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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM