2 回答

TA贡献1845条经验 获得超8个赞
大家早上好,多亏了 Tokant,我才能够以自己的方式找到解决方案。
我所做的是将布局放在一起,这样层次结构就会像这样。
作者 - 在当前类别中发布的视频。
这是解决方案:
您必须安装 Buddypress 插件才能使“orden”键正常工作,并将此脚本添加到子主题的 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 ?>

TA贡献1847条经验 获得超7个赞
您可以为所有作者执行 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 author name]
while ( $the_query->have_posts() ) : $the_query->the_post();
[output post/video]
endwhile;
wp_reset_postdata();
endif;
endforeach;
endif;
- 2 回答
- 0 关注
- 75 浏览
添加回答
举报