WordPress 中的同一篇文章有​​多个作者

发布于 2024-11-05 22:26:57 字数 245 浏览 0 评论 0原文

我有一个朋友要求我为他和两个朋友建立一个网站来写电影评论。我很擅长使用 Wordpress,所以它是该网站的明显选择。我唯一的困难是他们每个人都计划对同一部电影写一篇评论,我想不出如何在一篇文章中实现多个作者。

我已经检查了一些插件,例如 Co-Author Plus,它允许多个作者署名同一篇文章,但它不提供将每个作者的内容分开的功能。

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

I have a friend who has asked me to build a site for him and two friends to write movie reviews. I'm pretty good with Wordpress, so it was the obvious choice for the site. The only difficulty I have is that they each plan to write a review on the same movie, and I can't think of how to achieve multiple authors in one post.

I've checked out a few plugins such as Co-Author Plus which allows multiple authors credited to the same post, but it doesn't provide the functionality for keeping each author's content separate.

The only solution I can think of is to use custom fields, but I would prefer if the authors can use the main content editor for their reviews. Any help is greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

哆啦不做梦 2024-11-12 22:26:57

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

因此,我认为实现这一目标的最佳方法应该是创建帖子类型:

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

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

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

Like I said, it should be better to have 1 review = 1 post.

So, I think the best way to achieve this should be to create post types :

  • movie
  • review, with a movie reference field

And modify post template to display movie and associated reviews on the same page.

An alternate solution should be to use taxonomy to handle movies and attach post to them.

百变从容 2024-11-12 22:26:57

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

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

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

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

我将分类法与 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);
    }
?>

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

I ran into the same problem with trying to figure out how to do this as well and I followed soju's advice and came up with a solution. There might be a better solution to this, but this is how I went about it. Me and my friend are doing an anime review blog and both me and him will be writing a review on the same anime.

I first created two post types:

  • anime: main page on the specific anime, like the description, pictures, etc.
  • reviews: the author's review on the anime. the options i have enabled on here are the editor, the title, and the author. Along with the associated anime taxonomy. That's all that's needed here

Then I created a taxonomy for anime titles so when a user needs to write a review on an anime that hasn't been added as a review yet they can add the title into the taxonomy.

I associated the taxonomy to both post_types and wala! That's pretty much all you need.

So now when you want to write a new review for a new anime you add a anime post type first and write down what the anime is about and include pictures etc. Add the title to the taxonomy and check it. After that you then create a new post of the post type reviews and write your review, remember to check the correct title in your taxonomy for what anime this is going to, then you are ready to go!

Problem 1: How do I include this into my loop?

Well you don't want to include both post types in your loop you just want to include posts and the other post type anime in your loop so you do the following in your functions.php file:

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' );

Problem 2: How do I display the reviews?

I solved this by creating another single.php file and renamed it to single-post_type_name.php. So in this case i created a single-anime.php file for my post type anime. Then in place of the contents i want to get all the reviews for this specific anime so I added the following within the file in the main content area:

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

You can do a lot more with this adding more taxonomies etc. I have actually implemented an episode review by just adding a taxonomy and adding a criteria to look for in the post section. Hopefully this will help you out, might be a bit late though :( Thanks soju for recommending the custom post types!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文