有没有一种方法可以列出某个类别中所有发布过视频的作者并将它们一起显示,就像列表一样?
Is there a way to list all the authors who have published videos in a certain category and show them together, like a list?
请帮我做这个网站https://desarrollowebtotal.space/yoentrenoencasa/
我使用来自 touchsize 的 goWatch 主题作为父主题。
我需要的是这个:
当我点击主页上列出的任何类别时,例如Yoga,该站点将导航到一个存档,其中包含在该分类法中创建的所有视频,这不是我想要的行为。
我想要的是将该存档 return 已发布该类别视频的作者列表,并作为列表嵌套显示与该类别中该作者相关的视频。
可以这样做吗?
// 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>
输出
- 克里斯蒂安恩特雷纳多
- j.b
- 何塞·米格尔
- Yonatan T.
我需要什么
- 教练姓名
- 在当前类别
中发布的视频 he/she
更新 2:
像@Tokant requested/recommended 我 copy/pasted 他的片段一样,它起作用了,它打印了一个作者,我认为这是因为他是唯一一个发布视频的人
<div class="row">
<?php $term = get_queried_object(); ?>
<?php $authors_args = array(
'echo' => false,
'orderby' => 'name',
'order' => 'ASC',
);
$author_list = wp_list_authors($authors_args);
if (!empty($author_list)):
echo $author_list;
foreach ($author_list as $author):
$author_id = $author->ID;
$author_display_name = $author->name;
$query_args = array(
'author' => $author_id,
);
$the_query = new WP_Query( $query_args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
endwhile;
wp_reset_postdata();
endif;
endforeach;
endif; ?>
</div>
输出这个
- 何塞·米格尔
您可以为所有作者做一个 WP_Query。在每个作者的循环中,您首先获取作者的 ID,然后为 'video' post 类型创建一个 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 author name]
while ( $the_query->have_posts() ) : $the_query->the_post();
[output post/video]
endwhile;
wp_reset_postdata();
endif;
endforeach;
endif;
早上好伙计们,多亏了 Tokant,我才能够以自己的方式找到解决方案。
我做的就是把布局放在一起,这样层次就变成这样了。
作者
- 当前类别中发布的视频。
这是解决方案:
您必须为 'orden' 键安装 Buddypress 插件才能工作,并将此脚本添加到您子主题的 functions.php
/*Función para ordenar los autores*/
add_action('show_user_profile', 'extra_user_profile_fields');
add_action('edit_user_profile', 'extra_user_profile_fields');
function extra_user_profile_fields($user)
{ ?>
<?php if (current_user_can('administrator')) { ?>
<h3><?php _e("Administrar Posiciones", "blank"); ?></h3>
<table class="form-table">
<tr>
<th><label for="orden"><?php _e("Modificar Orden"); ?></label></th>
<td>
<input type="number" name="orden" id="orden" value="<?php echo esc_attr(get_the_author_meta('orden', $user->ID)); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Campo solo para administradores"); ?></span>
</td>
</tr>
<tr>
</table>
<?php } ?>
<?php }
add_action('personal_options_update', 'save_extra_user_profile_fields');
add_action('edit_user_profile_update', 'save_extra_user_profile_fields');
function save_extra_user_profile_fields($user_id)
{
if (!current_user_can('edit_user', $user_id)) {
return false;
}
update_user_meta($user_id, 'orden', $_POST['orden']);
}
- 作者循环:
<?php
// Theme's WP_Query arguments
$airkit_video = '';
$figure_attributes = array();
$airkit_is_img = airkit_single_option('img');
$airkit_img_src =wp_get_attachment_url(get_post_thumbnail_id($videos->ID));
$airkit_video_type = get_post_meta($videos->ID, 'video_type', true);
$airkit_external_video = get_post_meta($videos->ID, 'video_url', true);
$airkit_embedded_video = get_post_meta($videos->ID, 'video_embed', true);
$airkit_uploaded_video = get_post_meta($videos->ID, 'video_upload', true);
//Arguments for users Query
$arg_user = array(
'role__in' => ['author'],
'post_type' => 'video',
'has_published_posts' => ['video'],
'fields' => ['ID'],
'meta_query' => array(
array(
'relation' => 'OR',
array('key' => 'orden', 'value' => '0', 'compare' => '!='),
array('key' => 'orden', 'compare' => 'NOT EXISTS'),
),
),
'orderby' => 'meta_value',
'order' => 'ASC',
);
//var_dump($arg_user);
$yec_args = get_users($arg_user); //We obtain the list of all the users of the site to compare with the criteria of the query, it will look for in the author role, the users that have published entries in the custom post type video and it will avoid to bring the ones that do not have entries.
$yec_user_id = wp_list_pluck($yec_args, 'ID');
//print_r($yec_user_id);
?>
?>
然后我们遍历每个作者并输出 html
<div class="container container-todo" style="transform: none; display: flex;">
<div class="post-details-row current-reading" style="transform: none;">
<?php
// Loop & retrieve el ID authors ID
foreach ($yec_user_id as $author_id): //main FOREACH
// We get the ID of the current author who is returning the loop
$curauth = get_userdata($author_id);
//var_dump($curauth->user_nicename);
$args = array(
'posts_per_page' => -1,
'post_type' => 'video',
'author' => $author_id,
'groupby' => 'author',
'tax_query' => array(
array(
'taxonomy' => 'videos_categories',
'field' => 'slug',
'terms' => get_queried_object()->slug,
),
),
'meta_key' => 'airkit_views',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
//We return the videos and count them.
$posts = get_posts($args);
$number_post = count($posts);
//var_dump($number_post);
//if this author has posts, then include his name in the list otherwise don't
if (isset($posts) && !empty($posts)) { // MAIN IF?>
<div class="row" style="display: flex; align-items: center;">
<div class="sidebar-right col-lg-12 col-md-12 col-xs-12" style="display: flex; justify-content: center; flex-wrap: wrap;">
<!-- Datos del autor -->
<div class="tszf-author-body">
<div class="item col-md-12 col-xs-12" style="text-align: center;">
<div class="yec-user-image">
<img src="<?php echo esc_url(get_avatar_url($author_id)); ?>" />
</div>
<div class="item col-xs-12">
<span class="yec-authors"> <a href=" <?php echo get_option('siteurl') . '/members/' . $curauth->user_nicename . '/posts' ?>" class="post-link"> <?php echo "" . $curauth->first_name . " " . $curauth->last_name . ""; ?> </a></span>
</div>
</div>
</div>
<div class="tszf-user-name">
<ul class="social"><?php echo airkit_var_sanitize($social_icons, 'the_kses'); ?></ul>
</div>
<!-- Fin de datos del autor -->
<!-- Aquí deben ir los vídeos de ese autor -->
<?php $count = 0; ?>
<?php foreach ($posts as $post) { ?>
<?php if ($count == "4") {
// Si hay vídeos no imprimas más de 2 y salte del condicional
break;
} else{ ?>
<!-- Este es el bloque iterable -->
<div class="item col-lg-4 col-md-6 col-sm-6 col-xs-12">
<article class="video type-video status-publish has-post-thumbnail hentry has-lazy-placeholder airkit_view-article text-left below-image effect-always hidden-excerpt has-image" itemscope="" itemtype="http://schema.org/Article">
<figure class="image-holder has-background-img lazy lazyloaded" style="background-image: url(<?php echo get_the_post_thumbnail_url($post->ID, 'full') ?>); display: block;">
<a class="post-format-link" href="<?php the_permalink(); ?>" title="<?php echo $post->post_title; ?>">
<span class="post-type"><i class="icon-play-full"></i></span>
</a>
<a href="<?php the_permalink(); ?>" class="post-link"></a>
<div class="overlay-effect ">
<a href="<?php the_permalink(); ?>" class="overlay-link darken">
</a>
</div>
</figure>
<header class="entry-content-below">
<div class="entry-content">
<ul class="entry-categories">
<li class="term">
<?php $slug = get_queried_object()->slug; ?>
<a href="<?php the_permalink(); ?>"><?php echo $post->post_title; ?></a>
<!-- <a href="<?php echo $post->guid; ?>"><?php echo $slug; ?></a> -->
</li>
</ul>
<h2 class="entry-title" itemprop="name headline">
<a href="<?php the_permalink(); ?>" title="<?php echo $post->post_title; ?>"><?php echo $video->post_title; ?></a>
<div class="widget-meta">
<ul class="list-inline">
<li class="red-comments">
<a href="<?php echo get_permalink($post->ID) . '#comments' ?>">
<i class="icon-comments"></i>
<span class="comments-count">
<?php echo airkit_var_sanitize($post->comment_count, 'the_kses') . ' '; ?>
</span>
</a>
</li>
<li class="meta-views">
<i class="icon-views-1"></i> <?php airkit_get_views($post->ID, true); ?>
</li>
</ul>
</div>
</h2>
</div> <!-- Aquí termina el contenido de los vídeos -->
</header>
</article>
</div>
<!--Fin del bloque iterable -->
<?php $count++; } //CIERRE DEL IF DEL COUNT ?>
<?php } //CIERRE FOREACH DE POST ?>
</div>
<!-- Flecha que nos lleva al perfil del autor -->
<a href=" <?php echo get_option('siteurl') . '/members/' . $curauth->user_nicename . '/posts' ?>" class="post-link">
<span style="font-size: 3em; color: rgba(60,185,207,1);">
<i class="fas fa-angle-double-right" style="margin-top:50px"></i>
</span>
<br />
</a>
<span style="color: rgba(60,185,207,1);"> (<?php echo $number_post; ?>) <i class="fas fa-video"></i> </span>
</div>
<?php } // END of MAIN IF ?>
<?php endforeach; //END OF MAIN FOREACH ?>
请帮我做这个网站https://desarrollowebtotal.space/yoentrenoencasa/
我使用来自 touchsize 的 goWatch 主题作为父主题。
我需要的是这个:
当我点击主页上列出的任何类别时,例如Yoga,该站点将导航到一个存档,其中包含在该分类法中创建的所有视频,这不是我想要的行为。
我想要的是将该存档 return 已发布该类别视频的作者列表,并作为列表嵌套显示与该类别中该作者相关的视频。
可以这样做吗?
// 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>
输出
- 克里斯蒂安恩特雷纳多
- j.b
- 何塞·米格尔
- Yonatan T.
我需要什么
- 教练姓名
- 在当前类别 中发布的视频 he/she
更新 2:
像@Tokant requested/recommended 我 copy/pasted 他的片段一样,它起作用了,它打印了一个作者,我认为这是因为他是唯一一个发布视频的人
<div class="row">
<?php $term = get_queried_object(); ?>
<?php $authors_args = array(
'echo' => false,
'orderby' => 'name',
'order' => 'ASC',
);
$author_list = wp_list_authors($authors_args);
if (!empty($author_list)):
echo $author_list;
foreach ($author_list as $author):
$author_id = $author->ID;
$author_display_name = $author->name;
$query_args = array(
'author' => $author_id,
);
$the_query = new WP_Query( $query_args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
endwhile;
wp_reset_postdata();
endif;
endforeach;
endif; ?>
</div>
输出这个
- 何塞·米格尔
您可以为所有作者做一个 WP_Query。在每个作者的循环中,您首先获取作者的 ID,然后为 'video' post 类型创建一个 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 author name]
while ( $the_query->have_posts() ) : $the_query->the_post();
[output post/video]
endwhile;
wp_reset_postdata();
endif;
endforeach;
endif;
早上好伙计们,多亏了 Tokant,我才能够以自己的方式找到解决方案。
我做的就是把布局放在一起,这样层次就变成这样了。
作者 - 当前类别中发布的视频。
这是解决方案:
您必须为 'orden' 键安装 Buddypress 插件才能工作,并将此脚本添加到您子主题的 functions.php
/*Función para ordenar los autores*/
add_action('show_user_profile', 'extra_user_profile_fields');
add_action('edit_user_profile', 'extra_user_profile_fields');
function extra_user_profile_fields($user)
{ ?>
<?php if (current_user_can('administrator')) { ?>
<h3><?php _e("Administrar Posiciones", "blank"); ?></h3>
<table class="form-table">
<tr>
<th><label for="orden"><?php _e("Modificar Orden"); ?></label></th>
<td>
<input type="number" name="orden" id="orden" value="<?php echo esc_attr(get_the_author_meta('orden', $user->ID)); ?>" class="regular-text" /><br />
<span class="description"><?php _e("Campo solo para administradores"); ?></span>
</td>
</tr>
<tr>
</table>
<?php } ?>
<?php }
add_action('personal_options_update', 'save_extra_user_profile_fields');
add_action('edit_user_profile_update', 'save_extra_user_profile_fields');
function save_extra_user_profile_fields($user_id)
{
if (!current_user_can('edit_user', $user_id)) {
return false;
}
update_user_meta($user_id, 'orden', $_POST['orden']);
}
- 作者循环:
<?php
// Theme's WP_Query arguments
$airkit_video = '';
$figure_attributes = array();
$airkit_is_img = airkit_single_option('img');
$airkit_img_src =wp_get_attachment_url(get_post_thumbnail_id($videos->ID));
$airkit_video_type = get_post_meta($videos->ID, 'video_type', true);
$airkit_external_video = get_post_meta($videos->ID, 'video_url', true);
$airkit_embedded_video = get_post_meta($videos->ID, 'video_embed', true);
$airkit_uploaded_video = get_post_meta($videos->ID, 'video_upload', true);
//Arguments for users Query
$arg_user = array(
'role__in' => ['author'],
'post_type' => 'video',
'has_published_posts' => ['video'],
'fields' => ['ID'],
'meta_query' => array(
array(
'relation' => 'OR',
array('key' => 'orden', 'value' => '0', 'compare' => '!='),
array('key' => 'orden', 'compare' => 'NOT EXISTS'),
),
),
'orderby' => 'meta_value',
'order' => 'ASC',
);
//var_dump($arg_user);
$yec_args = get_users($arg_user); //We obtain the list of all the users of the site to compare with the criteria of the query, it will look for in the author role, the users that have published entries in the custom post type video and it will avoid to bring the ones that do not have entries.
$yec_user_id = wp_list_pluck($yec_args, 'ID');
//print_r($yec_user_id);
?>
?>
然后我们遍历每个作者并输出 html
<div class="container container-todo" style="transform: none; display: flex;">
<div class="post-details-row current-reading" style="transform: none;">
<?php
// Loop & retrieve el ID authors ID
foreach ($yec_user_id as $author_id): //main FOREACH
// We get the ID of the current author who is returning the loop
$curauth = get_userdata($author_id);
//var_dump($curauth->user_nicename);
$args = array(
'posts_per_page' => -1,
'post_type' => 'video',
'author' => $author_id,
'groupby' => 'author',
'tax_query' => array(
array(
'taxonomy' => 'videos_categories',
'field' => 'slug',
'terms' => get_queried_object()->slug,
),
),
'meta_key' => 'airkit_views',
'orderby' => 'meta_value_num',
'order' => 'DESC'
);
//We return the videos and count them.
$posts = get_posts($args);
$number_post = count($posts);
//var_dump($number_post);
//if this author has posts, then include his name in the list otherwise don't
if (isset($posts) && !empty($posts)) { // MAIN IF?>
<div class="row" style="display: flex; align-items: center;">
<div class="sidebar-right col-lg-12 col-md-12 col-xs-12" style="display: flex; justify-content: center; flex-wrap: wrap;">
<!-- Datos del autor -->
<div class="tszf-author-body">
<div class="item col-md-12 col-xs-12" style="text-align: center;">
<div class="yec-user-image">
<img src="<?php echo esc_url(get_avatar_url($author_id)); ?>" />
</div>
<div class="item col-xs-12">
<span class="yec-authors"> <a href=" <?php echo get_option('siteurl') . '/members/' . $curauth->user_nicename . '/posts' ?>" class="post-link"> <?php echo "" . $curauth->first_name . " " . $curauth->last_name . ""; ?> </a></span>
</div>
</div>
</div>
<div class="tszf-user-name">
<ul class="social"><?php echo airkit_var_sanitize($social_icons, 'the_kses'); ?></ul>
</div>
<!-- Fin de datos del autor -->
<!-- Aquí deben ir los vídeos de ese autor -->
<?php $count = 0; ?>
<?php foreach ($posts as $post) { ?>
<?php if ($count == "4") {
// Si hay vídeos no imprimas más de 2 y salte del condicional
break;
} else{ ?>
<!-- Este es el bloque iterable -->
<div class="item col-lg-4 col-md-6 col-sm-6 col-xs-12">
<article class="video type-video status-publish has-post-thumbnail hentry has-lazy-placeholder airkit_view-article text-left below-image effect-always hidden-excerpt has-image" itemscope="" itemtype="http://schema.org/Article">
<figure class="image-holder has-background-img lazy lazyloaded" style="background-image: url(<?php echo get_the_post_thumbnail_url($post->ID, 'full') ?>); display: block;">
<a class="post-format-link" href="<?php the_permalink(); ?>" title="<?php echo $post->post_title; ?>">
<span class="post-type"><i class="icon-play-full"></i></span>
</a>
<a href="<?php the_permalink(); ?>" class="post-link"></a>
<div class="overlay-effect ">
<a href="<?php the_permalink(); ?>" class="overlay-link darken">
</a>
</div>
</figure>
<header class="entry-content-below">
<div class="entry-content">
<ul class="entry-categories">
<li class="term">
<?php $slug = get_queried_object()->slug; ?>
<a href="<?php the_permalink(); ?>"><?php echo $post->post_title; ?></a>
<!-- <a href="<?php echo $post->guid; ?>"><?php echo $slug; ?></a> -->
</li>
</ul>
<h2 class="entry-title" itemprop="name headline">
<a href="<?php the_permalink(); ?>" title="<?php echo $post->post_title; ?>"><?php echo $video->post_title; ?></a>
<div class="widget-meta">
<ul class="list-inline">
<li class="red-comments">
<a href="<?php echo get_permalink($post->ID) . '#comments' ?>">
<i class="icon-comments"></i>
<span class="comments-count">
<?php echo airkit_var_sanitize($post->comment_count, 'the_kses') . ' '; ?>
</span>
</a>
</li>
<li class="meta-views">
<i class="icon-views-1"></i> <?php airkit_get_views($post->ID, true); ?>
</li>
</ul>
</div>
</h2>
</div> <!-- Aquí termina el contenido de los vídeos -->
</header>
</article>
</div>
<!--Fin del bloque iterable -->
<?php $count++; } //CIERRE DEL IF DEL COUNT ?>
<?php } //CIERRE FOREACH DE POST ?>
</div>
<!-- Flecha que nos lleva al perfil del autor -->
<a href=" <?php echo get_option('siteurl') . '/members/' . $curauth->user_nicename . '/posts' ?>" class="post-link">
<span style="font-size: 3em; color: rgba(60,185,207,1);">
<i class="fas fa-angle-double-right" style="margin-top:50px"></i>
</span>
<br />
</a>
<span style="color: rgba(60,185,207,1);"> (<?php echo $number_post; ?>) <i class="fas fa-video"></i> </span>
</div>
<?php } // END of MAIN IF ?>
<?php endforeach; //END OF MAIN FOREACH ?>