首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wordpress get_excerpt() in循环

wordpress get_excerpt() in循环
EN

Stack Overflow用户
提问于 2013-08-26 05:33:04
回答 1查看 1.6K关注 0票数 0

更新:我在这里找到了一份工作,如下所示。我今天才开始使用wordpress。我似乎无法在这个循环中得到"the_excerpt“。它要么不显示,要么在第一个页面上发布。有什么想法吗?

它就在最底层,我正试图插入它。

代码语言:javascript
复制
<?
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
?>

更新:我在附近找到了一份工作.

代码语言:javascript
复制
<?
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;

}
?>
EN

回答 1

Stack Overflow用户

发布于 2013-08-26 07:57:17

您应该使用循环语法,从1.5开始就不再推荐wp_start();了。

代码语言:javascript
复制
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 Classget_posts();运行自己的查询。注意:如果要在同一页中使用一个或多个循环,请记住使用wp_reset_postdata();

代码语言:javascript
复制
//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;

希望能帮上忙!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18437249

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档