繁体   English   中英

在wordpress帖子中,显示与当前帖子属于同一类别但不包括当前帖子本身的帖子列表

[英]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

在我的博客上,我有一个名为“ TGIF XACML”的类别。 在每个帖子的末尾,我想使用wordpress短代码显示与当前帖子不同的同一类别的帖子

[display-posts category="tgif-xacml"]

我正在尝试弄清楚如何自动排除当前帖子。 显示信息的参考页没有将此列为选项。 有办法吗?

如果要查看当前状态,请查看此示例

谢谢。

我不确定简码,但是使用函数可以这样:

<?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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM