【问题标题】:Pull all posts with certain tag WordPress拉取所有带有特定标签 WordPress 的帖子
【发布时间】:2015-08-02 22:12:20
【问题描述】:

我有这个代码:

    <div class="col-md-4 col-sm-4 col-xs-12 mob">
  <?php 
  $args = array('tag_slug__and' => array('testtag'));
  $loop = new WP_Query( $args );
  while ($loop->have_posts() ) : $loop->the_post();
  ?>
  <a style="color:#333; text-decoration:none;" href="<?php echo get_permalink(); ?>">
    <?php 
    if(has_post_thumbnail()) {                    
      $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
      echo '<img src="' . $image_src[0]  . '" width="100%"  />';
    } 
    ?>
    <h4><?php the_title(); ?></h4>   

    <?php the_excerpt(); ?>

  <?php endwhile; ?>
  <?php wp_reset_query(); ?>
</a>

获得带有标签“testtag”的帖子。

而不是复制这段代码,并使用'testtag1','testtag2'

我怎样才能抓取所有带有“testtag”标签的帖子并继续将它们添加到 4 列中?

任何链接/帮助

【问题讨论】:

    标签: php html wordpress loops


    【解决方案1】:

    没关系,简单修复!!

     <div class="row" style="margin-top:20px;">
    
          <?php 
          $args = array('tag_slug__and' => array('testtag'));
          $loop = new WP_Query( $args );
          while ($loop->have_posts() ) : $loop->the_post();
          ?>
          <div class="col-md-4 col-sm-4 col-xs-12 mob">
          <a style="color:#333; text-decoration:none;" href="<?php echo get_permalink(); ?>">
            <?php 
            if(has_post_thumbnail()) {                    
              $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
              echo '<img src="' . $image_src[0]  . '" width="100%"  />';
            } 
            ?>
            <h4><?php the_title(); ?></h4>   
    
            <?php $trimexcerpt = get_the_excerpt();
    
            $shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 10, $more = '… <br/> <a href="">Read More ...</a>' ); 
    
            echo '<a style="color:#333; text-decoration:none;" href="' . get_permalink() . '"><p>' . $shortexcerpt . '</p></a>'; 
    
            ?>
      </div>
          <?php endwhile; ?>
          <?php wp_reset_query(); ?>
        </a>
    
    </div>
    

    【讨论】:

      猜你喜欢
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多