[英]In a wordpress post, display the list of posts that belong to the same category as the current post but exclude the current post itself
On my blog, I have a category called "TGIF XACML". 在我的博客上,我有一个名为“ TGIF XACML”的类别。 At the end of each post, I want to display posts in the same category except for the current post using the wordpress short code 在每个帖子的末尾,我想使用wordpress短代码显示与当前帖子不同的同一类别的帖子
[display-posts category="tgif-xacml"]
I'm trying to figure out how to automatically exclude the current post. 我正在尝试弄清楚如何自动排除当前帖子。 The reference page for display-posts does not list that as an option. 显示信息的参考页没有将此列为选项。 Is there a way? 有办法吗?
If you want to see the current state, check out this example . 如果要查看当前状态,请查看此示例 。
Thanks. 谢谢。
I'm not sure about the shortcode, but using functions you could do it like this: 我不确定简码,但是使用函数可以这样:
<?php
global $post;
$this_post = $post->ID;
$related_query = new WP_Query( $args = array(
'post_type' => 'my_post_type',
'post_status' => 'publish',
'category' => 'tgif-xacml',
'post__not_in' => array($this_post)
));
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.