Php 按类别列出的相关文章:{if id=to current page id}不应显示在相关文章中
我按类别列出了wordpress相关的帖子。 我的问题是我不想在相关文章中显示当前文章中的项目 例如:我有一个属于Php 按类别列出的相关文章:{if id=to current page id}不应显示在相关文章中,php,wordpress,Php,Wordpress,我按类别列出了wordpress相关的帖子。 我的问题是我不想在相关文章中显示当前文章中的项目 例如:我有一个属于颜色类别的项目列表,它是红色、蓝色、绿色、黑色,红色是我的当前页面,我不想红色出现在相关帖子 <?php foreach((get_the_category()) as $category) {$id = $category->cat_ID;} ?> <ul class="recentWorks"> <?php
颜色类别的项目列表
,它是红色、蓝色、绿色、黑色
,红色
是我的当前页面,我不想红色
出现在相关帖子
<?php foreach((get_the_category()) as $category) {$id = $category->cat_ID;} ?>
<ul class="recentWorks">
<?php
if (have_posts()) : {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts("&cat={echo $id;}&showposts=6&paged=$paged&order=ASC");
}
while(have_posts()) : the_post();
?>
<li>
<a class="imageHover" href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>"><?php the_title(); ?></a>
<?php if ( has_post_thumbnail()) the_post_thumbnail('post-thumbnails'); ?>
<span><?php the_title(); ?></span>
</li>
<?php endwhile; ?>
<?php endif; ?>
</ul>
-
之后
if($post->ID == get_the_ID())
continue;
while(have_posts()):the_post()代码>
尝试添加此内容
if($post->ID == get_the_ID())
continue;
您可以使用参数:-
'post__not_in' => array (get_the_ID())
这将从列表中排除当前帖子
像这样,您可以使用Wp_Query()
$args=array(
'cat'=>'{echo$id;}',
'post\u not\u in'=>数组(获取\u ID())
);
$query1=新的WP_查询($args);
//环路
而($query1->have_posts()){
$query1->the_post();
回显“”。获取标题();
}
thank's,但不幸的是,它不起作用,或者可能将新线放错位置<代码>while(have_posts()):the_post();如果($post->ID==get_,则_ID())继续
您是否检查了post->ID
有哪些值,以及在每个循环中获取了\u ID()
返回值?没有返回值,但是我应该在代码中的何处插入此行?您需要使用Wp\u query而不是query\u post。这样,您可以将其作为参数传递纠正我的错误我将query\u posts
替换为Wp\u query
并获得此错误致命错误:调用C:\xampp\htdocs\mm\Wp content\themes\mm\single.php中未定义的函数Wp\u query(),在第22行我已经编辑了我的答案。您可以在其中添加更多参数。请参阅