首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress中同一帖子上的多个作者

问Wordpress中同一帖子上的多个作者
EN

Stack Overflow用户
提问于 2011-05-10 12:39:54
回答 2查看 1.9K关注 0票数 0

我有一个朋友,他让我为他建一个网站,还有两个朋友写影评。我对Wordpress很在行,所以它是这个网站显而易见的选择。我唯一的困难是,他们每个人都计划为同一部电影写一篇评论,而我无法想象如何在一篇文章中实现多个作者。

我已经检查了一些插件,比如Co-Author Plus,它允许多个作者加入同一篇文章,但它不提供保持每个作者内容独立的功能。

我能想到的唯一解决方案是使用自定义字段,但我更希望作者可以使用主内容编辑器进行评论。任何帮助都是非常感谢的!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-05-10 22:46:42

就像我说的,1条评论=1条帖子应该更好。

所以,我认为实现这个目标的最好方法应该是创建post类型:

带有电影引用字段的

  • movie
  • review,

并修改帖子模板以在同一页面上显示电影和相关评论。

另一种解决方案应该是使用分类法来处理电影并将post附加到电影上。

票数 0
EN

Stack Overflow用户

发布于 2011-10-20 18:03:12

我也遇到了同样的问题,我听从了烧酒的建议,想出了一个解决方案。也许有一个更好的解决方案,但我就是这么做的。我和我的朋友正在写一个动漫评论博客,我和他都会写一篇关于同一个动漫的评论。

我首先创建了两个post类型:

  • 动漫:关于特定动漫的主页,如描述、图片等。
  • 评论:作者对动漫的评论。我在这里启用的选项是编辑器、标题和作者。以及相关的动漫分类。这就是这里所需要的

然后,我为动漫标题创建了一个分类法,以便当用户需要在尚未添加为评论的动漫上写评论时,他们可以将标题添加到分类法中。

我将分类法与post_types和wala关联起来!这几乎就是您所需要的。

所以现在,当你想为一个新的动漫写一篇新的评论时,你首先要添加一个动漫帖子类型,写下动漫是关于什么的,并包括图片等。将标题添加到分类中并检查它。在这之后,你创建了一个新的帖子类型评论,并写你的评论,记得检查你的分类中的正确标题,这将是什么动画,然后你就可以开始了!

问题1:如何将其包含到我的循环中?

嗯,你不想在你的循环中包含两种帖子类型,你只想在你的循环中包含帖子和另一种帖子类型的动画,所以你在你的functions.php文件中做如下操作:

代码语言:javascript
复制
function include_custom_post_types( $query ) { 
    global $wp_query;
    // Get all custom post types
    $custom_post_type = get_query_var( 'post_type' );
    // Get all post types
    $post_types = get_post_types();

    // If what you are getting is a category or a tag or that there are no custom
    // post types you just want to set the post types to be the current post types          
    if ( (is_category() || is_tag()) && empty( $custom_post_type ))
       $query->set( 'post_type' , $post_types );

    // Set the custom post types you want to ignore
    $ignore_types = array('reviews');

    //Unset the post types that are gonna be ignored
    foreach($post_types as $key=>$type)
    {
       if(in_array($type,$ignore_types))
       {
          unset($post_types[$key]);
       }
    }

    // Set the post types for the query
    if ( (is_home() && false == $query->query_vars['suppress_filters']) || is_feed())
         $query->set( 'post_type', $post_types);

    return $query;
}
add_filter( 'pre_get_posts' , 'include_custom_post_types' );

问题2:如何显示评论?

我通过创建另一个single.php文件解决了这个问题,并将其重命名为single-post_type_name.php。所以在这个例子中,我为我的post类型的动画创建了一个单一的Anime.php文件。然后,为了代替内容,我想要获得这个特定动画的所有评论,所以我在主要内容区域的文件中添加了以下内容:

代码语言:javascript
复制
<?php  
    //You grab the taxonomy that you have selected for this post
    $terms = wp_get_post_terms(get_the_ID(), 'animes_reviewed');
    // This is the args array for the criteria that the posts need to be in
   $args = array(
       // This is the post type of where your reviews are at
       post_type' => 'reviews',
       // this is for searching the taxonomy usually it's 
       // taxonomy_name => checked_taxonomy
       'anime' => $terms[0]->name, 
       'post_status' => 'publish'
    );

    // Grab the posts
    $posts = get_posts($args);

    //Here I echo out the information for debugging purpose, but 
    //Here is where you can do HTML to display your reviews
    foreach($posts as $post)
    {
        echo($post->post_content);
        the_author_meta( 'nickname', $post->post_author);
    }
?>

你可以用这个做更多的事情,添加更多的分类法等等。我实际上已经实现了一个剧集评论,只需添加一个分类法,并在帖子部分添加一个要查找的标准。希望这会对你有所帮助,不过可能有点晚了:(感谢soju推荐定制的帖子类型!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5945224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档