简体   繁体   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

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.

相关问题 WordPress侧边栏:使自定义循环显示与单个帖子相同类别的帖子,从列表中排除当前单个帖子 - WordPress sidebar: make custom loop display posts in same category as single post, EXCLUDING current single post from the list 从“其他相同类别的帖子”循环中排除当前帖子 - Exclude current post from “Other posts of same category” loop WordPress:获取最新帖子,不包括当前帖子 - Wordpress: Get recent posts, exclude current post 在WordPress中显示当前帖子的所有类别名称 - Display all category names for current post in wordpress WordPress获得当前帖子类别中最受欢迎的帖子 - Wordpress get most popular posts in current post category 帖子类型:当前帖子在帖子列表中选中 - Post Type: Current Post Checked in the list of posts 显示最近的博客文章,但排除当前文章 - Show recent blog posts, but exclude current post 仅显示比当前帖子旧的Wordpress帖子 - Only display Wordpress posts that are older than current post 为自定义帖子类型类别列表添加类“ current_page_item”(注意:该类别属于自定义分类法) - Adding class “current_page_item” for custom post type category list(note: the category is belong in custom taxonomy) 来自以下帖子的同一类别的Wordpress帖子 - Wordpress posts from the same category below post
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM