簡體   English   中英

拉所有帶有特定標簽WordPress的帖子

[英]Pull all posts with certain tag WordPress

我有以下代碼:

    <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列中?

任何鏈接/幫助

沒關系,簡單修復!!

 <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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM