Php Wordpress-显示最后5篇帖子-请假回复问题
我之前问过一个问题,以便获得帮助,展示特定类别问题的最后5篇文章。这已经解决了,但出现了一个新问题,只有在我使用短代码时才明显 问题Php Wordpress-显示最后5篇帖子-请假回复问题,php,wordpress,function,Php,Wordpress,Function,我之前问过一个问题,以便获得帮助,展示特定类别问题的最后5篇文章。这已经解决了,但出现了一个新问题,只有在我使用短代码时才明显 问题 function Last5posts() { $args = array( 'showposts' => 5, 'cat' => '3'); $last_5_posts_query = new WP_Query( $args ); while($last_5_posts_query-&g
function Last5posts() {
$args = array( 'showposts' => 5, 'cat' => '3');
$last_5_posts_query = new WP_Query( $args );
while($last_5_posts_query->have_posts()) :
$last_5_posts_query->the_post();
$link = get_permalink();
$title = get_the_title();
$date = get_the_date();
$content .= '<div class="latest-posts">';
$content .= '<h3><a href='.$link.' target="_top">'.$title.' / '.$date. '</a></h3>';
$content .= '<p class="excerpt">' .get_the_excerpt(). '</p>';
$content .= '</div>';
endwhile;
return $content;
}
add_shortcode('Last5Posts', 'Last5posts' );
使用下面的代码,当我将短代码添加到我的一个页面时,它会在页面底部添加一个“留下回复”框。我已经关闭了评论,当短代码未被使用时,“留下回复”在网站上并不明显——它只发生在我添加短代码时,这让我相信问题与下面添加到我的functions.PHP中的PHP代码有关
代码
function Last5posts() {
$args = array( 'showposts' => 5, 'cat' => '3');
$last_5_posts_query = new WP_Query( $args );
while($last_5_posts_query->have_posts()) :
$last_5_posts_query->the_post();
$link = get_permalink();
$title = get_the_title();
$date = get_the_date();
$content .= '<div class="latest-posts">';
$content .= '<h3><a href='.$link.' target="_top">'.$title.' / '.$date. '</a></h3>';
$content .= '<p class="excerpt">' .get_the_excerpt(). '</p>';
$content .= '</div>';
endwhile;
return $content;
}
add_shortcode('Last5Posts', 'Last5posts' );
函数Last5posts(){
$args=数组('showposts'=>5,'cat'=>3');
$last_5_posts_query=新的WP_query($args);
while($last\u 5\u posts\u query->have\u posts()):
$last_5_posts_query->the_post();
$link=get_permalink();
$title=获取标题();
$date=获取日期();
$content.='';
$content.='';
$content.=''。获取摘录()。
';
$content.='';
结束时;
返回$content;
}
添加快捷码(“Last5Posts”、“Last5Posts”);
在代码中使用自定义WP\u查询。在查询中调用_post()时,全局$post变量会发生变化。因此,在shortcode方法之后运行的代码将与新的$post值一起工作
在endwhile之后添加wp_reset_postdata,应该可以。该问题是由“showposts”被擦洗造成的,替换为“post_per_page”,一切正常。什么是
获取_摘录()
的样子?对不起,你是什么意思?你在问输出是什么吗?我想知道get\u摘录()
是否包括leave a reply。您可以将其更改为:$content.='test
'
并查看是否删除了回复链接。我按照您的建议尝试了,但“留下回复”仍然存在。“我将用其余的钩子试试,看看是不是其中一个钩子引起的。”尼基玛瑟出于好奇,为什么要使用短代码?请把你使用短码的地方贴出来。。。例如在php代码或页面/帖子编辑器中,等等