在特定作者的循环中显示帖子

时间:2016-08-11 08:57:35

标签: php html css wordpress loops

大家好,我在创建一个新的wordpress网站时遇到了一些问题。我有一个名为“authors”的自定义帖子类型,我将所有作者都放在新网站中创建内容。现在,在使用CSS构建单个作者网站后,我想制作一个循环,这将在网站上显示他们的帖子。我怎样才能做到这一点?现在,当我使用标准循环时,它会显示所有用户的帖子,但不是那个特定的帖子,我实际上在哪个网站上。如果以这种方式无法实现,请告诉我如何实现它更方便吗?也许我应该删除自定义帖子类型,并以“用户”为基础。但是,我怎样才能将他们的“信息”选择到循环中(例如名称,生物以及他们已经写过的帖子数量)。下面是single-authors.php的代码

<?php get_header(); ?>

<main class="author">
<div class="container">
<h1>Author's articles</h1>
<a href="" class="see-all">Meet our team <i class="fa fa-angle-double-right" aria-hidden="true"></i></a>
<div class="breadcrumbs">
<span>You are here:</span>
<ol class="breadcrumb">
<li><a href="#">INFO</a></li>
<li><a href="#">About us</a></li>
</ol>
</div>
<div class="entries-authors">
<div class="single-author row">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
 <img src="<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full'); print_r($thumb[0]); ?>" alt="">
 </a>
<div class="author-info">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<h3><?php $title = get_the_title(); echo substr($title, 0 , 100); ?>
</h3>
</a>
<h4>
<?php
$terms = get_the_terms( $post->id, 'job' );
if ( !is_wp_error($terms)) {
$album_categories = array();
foreach ($terms as $term) {
$album_categories[] = $term->name;
$albums = join( ", ", $album_categories );
}
?>
<span><?php echo $albums; ?></span>
<?php } ?>
</h4>
<p>Follow me:</p>
<!--
<div class="author-social">
<ul class="nav nav-pills">
<li><a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
<li><a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
<li><a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
<li><a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
<li><a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
<li><a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a></li>
</ul>
</div>
-->
</div>
<div class="author-bio">
<div class="bio-desc">
<p class="more-toggle">
<?php 
echo get_post_field('post_content', $post_id);
?>
</p>
<button class="toggle">Show more <i class="fa fa-chevron-down" aria-hidden="true"></i></button>
</div>

<div class="genre-list"><img src="<?php echo get_template_directory_uri(); ?>/library/images/gamepad.png" alt="">Favourite genre:
<span class="genre-tags">
 <?php
$terms = get_the_terms( $post->id, 'genre' );
if ( !is_wp_error($terms)) {
$album_categories = array();
foreach ($terms as $term) {
$album_categories[] = $term->name;
$albums = join( ", ", $album_categories );
}
?>
<span><?php echo $albums; ?></span>
<?php } ?>
</div>
</div>
<div class="author-entries-count">
<span>Entries:</span>
<p href="<?php the_permalink(); ?>" class="count">
<?php 
$post_author_id = get_post_field( 'post_author', $post_id );
echo count_user_posts($post_author_id);
 ?>
</p>
</div>
</div>
</div>
<section class="articles">
<ul class="nav nav-tabs">
<li class="active"><a data-toggle="tab" href="#news">News (18)</a></li>
<li><a data-toggle="tab" href="#reviews">Reviews (2)</a></li>
<li><a data-toggle="tab" href="#features">Features (6)</a></li>
</ul>

<div class="tab-content">
<div id="news" class="tab-pane fade in active">

<?php $loop = new WP_Query( array( 'posts_per_page' => 7)); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

<?php echo the_content(); ?>

<?php endwhile; wp_reset_query(); ?>


<div class="single-post">
<div class="thumb">
<img src="<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full'); print_r($thumb[0]); ?>" alt="">
<span>nintendo</span>
</div>
<div class="content">
<h2>Nintendo Explains Why Zelda Games Rarely Come Out on Time</h2>
<p>Some of the key designers behind Nintendo's famous Legend of Zelda series have spoken up to explain why new installments in the iconic... <a href="">Read more <i class="fa fa-angle-double-right" aria-hidden="true"></i></a></p>
<div class="news-info">
<div class="time-stamp">
<span>
<i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>
</span>
</div>
<div class="comments-stamp">
<span>
<img src="<?php echo get_template_directory_uri(); ?>/library/images/comments-gray.png" alt=""><?php comments_number( '0', '1', '%' ); ?>
</span>
</div>
</div>
</div>
</div>

<?php 
$post_author_id = get_post_field( 'post_author', $post_id );
 count_user_posts($post_author_id);
?>

</div>
<div id="reviews" class="tab-pane fade">

</div>
<div id="features" class="tab-pane fade">

</div>
</div>
</section>
<aside class="sidebar">
<sidebar>
<div class="hot-news">
<h3>hot topics</h3>
<?php $loop = new WP_Query( array( 'post_type' => 'hot_topics', 'posts_per_page' => 5)); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

<div class="single-hot-news">
<img src="<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full'); print_r($thumb[0]); ?>">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<h3><?php $title = get_the_title(); echo substr($title, 0 , 40); ?></h3>
</a>
<span><img src="<?php echo get_template_directory_uri(); ?>/library/images/comments.png" alt=""><?php comments_number( '0', '1', '%' ); ?></span>
</div>
<?php endwhile; wp_reset_query(); ?>

<div class="show-more">
<a href="">See more</a>
</div>
</div>
<div class="interesting-news">
<h3>You might be interested in</h3>
<?php $loop = new WP_Query( array('posts_per_page' => 5)); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

<div class="single-interesting-news">
<img src="<?php $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full'); print_r($thumb[0]); ?>">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<h3><?php $title = get_the_title(); echo substr($title, 0 , 40); ?></h3>
</a>
<span><img src="<?php echo get_template_directory_uri(); ?>/library/images/author-comments.png" alt=""><?php comments_number( '0', '1', '%' ); ?></span>
</div>
<?php endwhile; wp_reset_query(); ?>

<div class="show-more">
<a href="">See more</a>
</div>
</div>
</sidebar>
</aside>
</div>
</main>


<?php get_footer(); ?>

干杯

1 个答案:

答案 0 :(得分:0)

这就是我需要的东西

<?php query_posts('author=' . $post->post_author . '&order=ASC&showposts=7'); ?>