更新:我在这里找到了一份工作,如下所示。我今天才开始使用wordpress。我似乎无法在这个循环中得到"the_excerpt“。它要么不显示,要么在第一个页面上发布。有什么想法吗?
它就在最底层,我正试图插入它。
<?
if(!$_GET[id])
{
$args = array( 'numberposts' => '5' );
$recent_posts = wp_get_recent_posts( $args );
start_wp();
foreach( $recent_posts as $recent ) {
set_post_thumbnail_size( 33, 33);
$excerpt = get_the_excerpt();
{ ?>
<table width="100%" cellpadding="0" cellspacing="0" id="blogHolder">
<tr>
<td width="21%" rowspan="2" align="center" valign="middle"><div class="blogImage"><? echo get_the_post_thumbnail($recent["ID"], array(133,133) ); ?></div> <img src="images/blogImageBox.png" width="177" height="177" /></td>
<td width="79%" height="23" valign="middle" class="blogTitle"><? echo $recent["post_title"]; ?></td>
</tr>
<tr>
<td height="24" valign="middle" class="blogTitle"><? echo $excerpt; ?></td>
</tr>
<tr>
</tr>
</table>
<? }
}
}/// End if no ID
?>更新:我在附近找到了一份工作.
<?
if(!$_GET[id])
{
$posts = get_posts();
foreach ($posts as $post) : start_wp(); ?>
<table width="100%" cellpadding="0" cellspacing="0" id="blogHolder">
<tr>
<td width="21%" rowspan="2" align="center" valign="middle"><div class="blogImage"><? echo get_the_post_thumbnail($recent["ID"], array(133,133) ); ?></div> <img src="images/blogImageBox.png" width="177" height="177" /></td>
<td width="79%" height="23" valign="middle" class="blogTitle"><? echo the_title(); ?></td>
</tr>
<tr>
<td height="24" valign="top" ><blockquote class="blogContent">
<p><? echo the_excerpt(); ?></p>
</blockquote></td>
</tr>
<tr>
</tr>
</table>
<?php
endforeach;
}
?>发布于 2013-08-26 07:57:17
您应该使用循环语法,从1.5开始就不再推荐wp_start();了。
if( have_posts() ) : while( have_posts() ) : the_post();
//Display my single post title
the_title();
//Display post thumbnail image
if( has_thumbnail ) : the_post_thumbnail();
//Display post excerpt
the_excerpt();
endwhile; endif;您可以使用WP_Query Class或get_posts();运行自己的查询。注意:如果要在同一页中使用一个或多个循环,请记住使用wp_reset_postdata();
//Set up array of arguments, please check WP_Query/get_posts() docs please
$args = array( 'posts_per_page' => '5' );
$query = new WP_Query( $args );
if( $query->have_posts() ) : while( $query->have_posts() ) : $query->the_posts();
//Display my single post title
the_title();
//Display post thumbnail image
if( has_thumbnail ) : the_post_thumbnail();
//Display post excerpt
the_excerpt();
endwhile;
wp_reset_postdata();
endif;希望能帮上忙!
https://stackoverflow.com/questions/18437249
复制相似问题