是否可以列出所有发布了特定类别视频的作者,并像列表一样一起显示它们?

问题描述 投票:0回答:1

请帮助我使用此网站https://desarrollowebtotal.space/yoentrenoencasa/

我正在使用touchsize的goWatch主题作为父主题。

我需要的是:

当我单击主页上列出的任何类别时,例如瑜伽,网站将导航到该分类法中创建的所有视频的存档,这不是我想要的行为。

我想要的是该档案库返回已发布该类别视频并嵌套在列表中的作者列表,以显示与该类别中该作者相关的视频。

可以这样做吗?

  // This query brings the videos within the videos_categories taxonomy that match the current slug
    $term = get_queried_object();
      $loop = new WP_Query( array(
        'post_type' => 'video',
        'posts_per_page' => 10,

        'tax_query' => array( //(array) - use taxonomy parameters (available with Version 3.1).
            'relation' => 'AND', //(string) - Possible values are 'AND' or 'OR' and is the equivalent of running a JOIN for each taxonomy
            array(
                'taxonomy' => 'videos_categories', //(string) - Taxonomy.
                'field' => 'slug', //(string) - Select taxonomy term by ('id' or 'slug')
                terms' => $term->slug, //(int/string/array) - Taxonomy term(s).
                include_children' => true, //(bool) - Whether or not to include children for hierarchical taxonomies. Defaults to true.
                'operator' => 'IN' //(string) - Operator to test. Possible values are 'IN', 'NOT IN', 'AND'.
              ),

            ),
    ) );

这是我到目前为止所做的,我不知道如何嵌套视频列表,以便父级是作者,子级是与该作者关联的视频

//更新1

     $argsA = array(
        'orderby'       => 'name', 
        'order'         => 'ASC', 
        'number'        => null,
        'optioncount'   => false, 
        'exclude_admin' => true, 
        'show_fullname' => false,
        'hide_empty'    => false,
        'echo'          => true,
        // 'feed'          => [empty string], 
        // 'feed_image'    => [empty string],
        // 'feed_type'     => [empty string],
        'style'         => 'list',
        'html'          => true,
    );

    $authors = wp_list_authors($argsA);


     // This query brings the videos within the videos_categories taxonomy that match the current slug
    $term = get_queried_object();

我在其中查看结果的HTML部分

  <div class="container airkit-archive-content">
        <div class="row">
            <?php if (!empty($authors)): ?>
                <?php foreach ($authors as $author): ?>

                    <?php  
                        $author_id = $author->ID;
                        $author_display_name = $author->name;

                        $query_args = array(
                          'author' => $author_id,
                          'post_type' => 'video',
                          'tax_query' => array(
                            'relation' => 'AND',
                            array(
                                'taxonomy' => 'videos_categories',
                                'field'    => 'slug',
                                'terms'    => $term->slug,
                                'include_children' => true,
                                'operator' => 'IN'

                            ),
                          ),

                       );
                    ?>

                <?php endforeach; ?> 

            <?php endif ?>


        </div>
    </div>


输出

  • Cristian Entrenador
  • j.b
  • Jose Miguel
  • Yonatan T。

我需要

  • 教练名称
    • 他/她在当前类别中发布的视频
php wordpress wordpress-theming custom-wordpress-pages
1个回答
0
投票

您可以为所有作者执行WP_Query。在每个作者的循环中,您首先要获得作者的ID,然后为“视频”帖子类型创建一个WP_Query,就像您已经做过的一样,只是在$ args中添加身份的ID,如下所示:

$authors_args = array(
    'echo'          => false,
    'orderby'       => 'name',
    'order'         => 'ASC',
);
$authors = wp_list_authors($args);
if (!empty($authors)):
foreach ($authors as $author):
   $author_id = $author->ID;
   $author_display_name = $author->name;

   $query_args = array(
      'author' => $author_id,
      [your args]
   );
   $the_query = new WP_Query( $query_args );
   if ( $the_query->have_posts() ) :
   [output authour name]
   while ( $the_query->have_posts() ) : $the_query->the_post();
      [output list of posts/videos]
   endwhile;
   wp_reset_postdata();
   endif;

endforeach;
endif;
© www.soinside.com 2019 - 2024. All rights reserved.