在WordPress类别档案中显示特色帖子?

时间:2018-12-19 17:01:13

标签: php wordpress archive taxonomy

我正在构建一个WordPress存档文件(archive.php),我想在顶部显示一个精选文章(来自“精选”类别)。

我的工作很好,但是当存档是类别存档时,我希望特色帖子成为正在显示的类别中的特色帖子,并且我不确定如何实现。

这是我正在使用的当前代码-它正确显示了精选类别中的第一篇文章,但我不知道如何在类别档案中对其进行过滤。

   <div class="row featured-blog">
        <?php
            $args = array(
            'post_type' => 'post',
            'post_status' => 'publish',
            'category_name' => 'featured',
            'posts_per_page' => 1,
            );
            $arr_posts = new WP_Query( $args );
 
            if ( $arr_posts->have_posts() ) :
 
             while ( $arr_posts->have_posts() ) :
            $arr_posts->the_post();
	          $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
	          $thumb_id = get_post_thumbnail_id();
	          $alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);

        ?>

    <div class="featured-post">
      <div class="featured-post-image" style="background-image: url(<?php echo $image[0] ?>);"></div>
      <div class="featured-post-content">
        <h2 class="entry-title">
          <?php the_title(); ?>
        </h2>
        <div class="featured-excerpt">
          <?php the_excerpt(); ?>
        </div>
        <a class="featured-post-link" href="<?php the_permalink(); ?>">Read More</a>
      </div>
    </div>
    <?php endwhile; endif; ?>
    </div>



  <?php if (have_posts()) :
		$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
		$thumb_id = get_post_thumbnail_id();
		$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true); ?>
		

  <?php while (have_posts()) : the_post(); ?>
  <div class="row new blog-posts">
  <div class="new-blog-post six columns">
    <div class="blog-content">
      <a href="<?php the_permalink(); ?>">
			<div class="blog-image-area" style="background-image: url(<?php echo $image[0]?>"></div>
			<h3><?php the_title( );?></h3>
			<div class="blog-excerpt"><?php the_excerpt();?></div>
	  </a>
    </div>
  </div>

  <?php endwhile; ?>

  <div class="row pagination">
    <div class="four columns older-post tablet-half">
      <?php next_posts_link('<svg><use xlink:href="/wp-content/themes/balance/images/icons.svg#left-arrow"></use></svg> <h4>Older Entries</h4>', $blog->max_num_pages) ?>

    </div>
    <div class="four columns offset-four newer-post tablet-half">
      <?php previous_posts_link('<h4>Newer Entries</h4> <svg><use xlink:href="/wp-content/themes/balance/images/icons.svg#right-arrow"></use></svg>') ?>
    </div>
  </div>

  </div>
  <?php endif; ?>

0 个答案:

没有答案