仅显示GET_POST中第一个条目的_DATE和_EXCEPT

时间:2014-12-23 作者:fff333

下面的代码显示了get\\u帖子中5篇帖子的标题和链接没问题,但只显示了第一篇帖子的日期和摘录。。。有什么帮助吗?

<?php
$args = array(
    \'posts_per_page\' => 5,
    \'post_type\' => \'my\',  
    \'order_by\' => \'post_date\',
    \'tax_query\' => array(
                        array(
                    \'taxonomy\' => \'mycategory\',
                    \'field\' => \'id\',
                    \'terms\' => array(36, 38, 83, 84),
                    \'operator\' => \'NOT IN\'
                    ),
                    ),
);
$last_five_posts = get_posts( $args );

foreach ( $last_five_posts as $post ) : setup_postdata( $post ); ?>
    <div><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" id="frontpagelatestposttitle"><?php the_title(); ?></a></div>
    <div><?php the_date(); ?></div>
    <div id="frontpagelatestpostexcerpt"> <p>
    <?php the_excerpt(); ?>

    </p> </div>
<?php endforeach;
wp_reset_postdata();
?>

1 个回复
最合适的回答,由SO网友:Robert hue 整理而成

我想你和我之前有同样的问题。在这个question.

这是固定代码。这应该行得通。我将这两个函数都替换为get_the_dateget_the_excerpt. 有关为什么/为什么不做这项工作的详细解释,请阅读@kaiser在同一个问题中的回答。

<?php
$args = array(
    \'posts_per_page\' => 5,
    \'post_type\' => \'my\',  
    \'order_by\' => \'post_date\',
    \'tax_query\' => array(
        array(
            \'taxonomy\' => \'mycategory\',
            \'field\' => \'id\',
            \'terms\' => array(36, 38, 83, 84),
            \'operator\' => \'NOT IN\'
        ),
    ),
);
$last_five_posts = get_posts( $args );

foreach ( $last_five_posts as $post ) : setup_postdata( $post ); ?>
    <div><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" id="frontpagelatestposttitle"><?php the_title(); ?></a></div>
    <div><?php echo get_the_date(); ?></div>
    <div id="frontpagelatestpostexcerpt">
        <p><?php echo get_the_excerpt(); ?></p>
    </div>
<?php endforeach;
wp_reset_postdata();
?>

结束