【问题标题】:Multiple Authors on same post in Wordpress多个作者在 Wordpress 中的同一帖子上
【发布时间】:2011-05-10 04:39:54
【问题描述】:

我有一个朋友让我为他和两个朋友建立一个网站来写电影评论。我对 Wordpress 非常熟悉,因此它是该网站的明显选择。我唯一的困难是他们每个人都计划为同一部电影写评论,我想不出如何在一篇文章中实现多个作者。

我查看了一些插件,例如 Co-Author Plus,它允许多位作者在同一篇文章中发表文章,但它不提供将每个作者的内容分开的功能。

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

【问题讨论】:

  • 最好有 1 条评论 = 1 条帖子,不是吗?
  • 最好,是的。但是我该如何对它们进行分组呢?

标签: wordpress


【解决方案1】:

就像我说的,最好有 1 条评论 = 1 条帖子。

所以,我认为实现这一点的最佳方法应该是创建帖子类型:

  • 电影
  • 评论,带有电影参考字段

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

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

【讨论】:

    【解决方案2】:

    我在试图弄清楚如何做到这一点时也遇到了同样的问题,我遵循了烧酒的建议并想出了一个解决方案。可能有更好的解决方案,但这就是我的做法。我和我的朋友正在写一个动漫评论博客,我和他都会写一篇关于同一部动漫的评论。

    我首先创建了两种帖子类型:

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

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

    我将分类法与 post_types 和 wala 相关联!这就是你所需要的。

    因此,现在当您想为新动漫撰写新评论时,您首先添加动漫帖子类型并写下动漫的内容并包含图片等。将标题添加到分类并检查它。之后,您然后创建一个帖子类型评论的新帖子并撰写您的评论,记得在您的分类中检查正确的标题以了解这将是什么动漫,然后您就可以开始了!

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

    好吧,您不想在循环中包含两种帖子类型,您只想在循环中包含帖子和其他帖子类型动画,因此您在 functions.php 文件中执行以下操作:

    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 解决了这个问题。所以在这种情况下,我为我的帖子类型动漫创建了一个 single-anime.php 文件。然后代替内容,我想获得这个特定动漫的所有评论,所以我在主要内容区域的文件中添加了以下内容:

    <?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);
        }
    ?>
    

    通过添加更多分类法等,您可以做更多事情。实际上,我通过添加分类法并在帖子部分添加要查找的标准来实现剧集审查。希望这会对您有所帮助,但可能有点晚了:(感谢烧酒推荐自定义帖子类型!

    【讨论】:

      猜你喜欢
      • 2020-02-05
      • 1970-01-01
      • 2013-10-10
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 2013-10-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多