我想在单个帖子模式下返回 2 个最新帖子,但不包括当前帖子。我做到了。问题是,它刚刚停止工作。它没有更改代码,它在服务器以及我的本地主机上停止。
这是代码:
<section id='recent_posts'>
<header class='recent_header'>
Recent posts
</header>
<?php
$id = $post->ID;
$recent_posts = wp_get_recent_posts("numberposts=2&exclude=$id");
foreach( $recent_posts as $recent ) { ?>
<article class='single_recent'>
<header>
<a href="<?php echo get_permalink($recent["ID"]); ?>"><?php echo $recent["post_title"]; ?></a>
</header>
<p>
<?php echo get_excerpt_by_id($recent["ID"]); ?>
</p>
</article>
<?php } ?>
</section>
有人有解释吗?
我尝试删除参数,仍然没有。它返回一个空数组。
我应该使用哪个其他功能来达到相同的效果有什么建议吗?
编辑:
<?php
get_header();
get_sidebar();
?>
<?php the_post() ?>
<article class='post-single'>
<header class='post_header'>
<h1><?php the_title(); ?></h1>
<div class='post_header_bottom'>
<strong class='post_category'><?php echo get_the_category_list(', '); ?></strong>
<strong class='post_author'><span class='symbol'>U</span> by <?php the_author(); ?></strong>
</div>
</header>
<?php if (has_post_thumbnail()) : ?>
<figure class='post_single_image'>
<?php the_post_thumbnail(); ?>
<figcaption>No Will No Skill</figcaption>
</figure>
<?php endif; ?>
<div class='post_perex'>
<?php the_content(); ?>
</div>
<footer class='post_footer'>
<div class='post_footer_top'>
<div class='post_tags'>
<?php the_tags('', '', ''); ?>
</div>
<div class='post_time'>
<time datetime='<?php the_time('Y-m-d'); ?>' pubdate>
<span class='symbol'>P </span>
<?php relative_post_the_date(); ?>
</time>
</div>
</div>
<div class='post_share'>
<div class='share_show'>
<span class='symbol'>f</span> Like
|
<span class='symbol'>g</span> +1
|
<span class='symbol'>t</span> Tweet
<?php
if(function_exists('display_social4i'))
echo display_social4i("large","align-left");
?>
</div>
</div>
</footer>
</article>
<?php comments_template(); ?>
<section id='recent_posts'>
<header class='recent_header'>
Recent posts
</header>
<?php
global $post;
$id = $post->ID;
$qargs = array(
'post__not_in'=> array($id),
'posts_per_page' => 2
);
$recent_posts = new WP_Query($qargs);
if ($recent_posts->have_posts()) echo 'yes'; else echo 'nope';
if($recent_posts->have_posts()) : while($recent_posts->have_posts()) : $recent_posts->the_post(); ?>
<article class='single_recent'>
<header>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</header>
<p>
<?php the_excerpt(); ?>
</p>
</article>
<?php endwhile;endif; ?>
</section>
<div class='space'></div>
</div>
<?php
get_footer();
?>