我试图首先获取单个页面(被查询的页面)的内容,然后在下面的一个小部分中,我想将我的博客文章的标题显示为“最新新闻”部分。
问题是如果我第一次使用<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
获取页面内容。然后尝试使用$posts_array = get_posts( $args );
为了获取博客帖子,我只需获取两次页面标题。显然get_posts
函数接受页面的id,而不是通过blogpost循环。有没有办法告诉get\\u posts搜索前5个blogpost id而不是当前页面id?
感谢所有答案、建议、提示或提示:)
这是我的代码:
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<div class="mcenter">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> role="article">
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->
<div class="entry-content">
<?php the_content(); ?>
<?php wp_link_pages( array( \'before\' => \'<div class="page-link">\' . __( \'Pages:\', \'monster\' ), \'after\' => \'</div>\' ) ); ?>
<?php edit_post_link( __( \'Edit\', \'monster\' ), \'<span class="edit-link">\', \'</span>\' ); ?>
</div><!-- .entry-content -->
</article><!-- #post-<?php the_ID(); ?> -->
</div>
<?php endwhile; // end of the loop. ?>
<?php
$args = array(
\'numberposts\' => 5,
\'offset\' => 0,
\'category\' => ,
\'orderby\' => \'post_date\',
\'order\' => \'DESC\',
\'include\' => ,
\'exclude\' => ,
\'meta_key\' => ,
\'meta_value\' => ,
\'post_type\' => \'post\',
\'post_mime_type\' => ,
\'post_parent\' => ,
\'post_status\' => \'publish\');
$posts_array = get_posts( $args );
?>
<div id="news">
<div id="news-roll" class="mcenter">
<h3><?php _e(\'Siste nytt:\', \'monster\'); ?></h3>
<?php
$count = 1;
foreach ($posts_array as $monster_news) {
setup_postdata($monster_news);
if ($count == 1) {
echo \'<p class="first-news">\';
} else {
echo \'<p>\';
}
the_title();
echo \'</p>\';
}
$count = null;
?>
</div>
</div>