简体   繁体   English

WordPress在博客页面上显示私人和公共帖子

[英]Wordpress display private and public posts on Blog Page

Is there away in Wordpress to display both my private and public posts on the blog page. 在Wordpress中是否可以在博客页面上同时显示我的私人帖子和公共帖子。

I am also looking for a way on the single post page if it is private displaying a message indicating it is. 我还在单一帖子页面上寻找一种方法,如果它是私密的,则显示一条消息表明它是。

So is there away to display both private and public posts on my blog page and is there a if condition for if private post? 那么,是否可以在我的博客页面上同时显示私人帖子和公共帖子?是否存在if帖子的if条件?

Yes, you can add this into query let say wp_query where you use for getting all post, in template or function anywhere. 是的,您可以将其添加到查询中,比如说wp_query,您可以在哪里使用它获取模板或函数中任何位置的所有帖子。

just you can put below query into your template. 只是您可以将以下查询放入模板中。

$args = array(
    'post_type' => 'blog',
    'post_status' => array( 'publish', 'private')
);
$query = new WP_Query( $args );

just put this into your template and you cat get all your private and publish post into template. 只需将其放入您的模板中,您就可以将所有私密内容发布到模板中。

You can get your 'private' and 'public' posts in this way 您可以通过这种方式获得“私人”和“公开”职位

$args = array(
    'post_status' => array( 'publish', 'private')
);
$query = new WP_Query( $args );

And then you can use get_post_status() inside the loop to get the status and indicate the message. 然后,您可以在循环内使用get_post_status()来获取状态并指示消息。

For your reference: https://developer.wordpress.org/reference/classes/wp_query/ https://developer.wordpress.org/reference/functions/get_post_status/ 供您参考: https : //developer.wordpress.org/reference/classes/wp_query/ https://developer.wordpress.org/reference/functions/get_post_status/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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