2016-04-05 3 views
0

Ich habe Beiträge in einem Abschnitt einer Seite hinzugefügt, in dem ich eine Abfrage geschrieben habe, um nur zwei aktuelle Beiträge mit ihrem Thumbnail auf einer Seite und Text parallel zum Thumbnail anzuzeigen, was ich nach jeder Iteration machen möchte die zu invertierende Anzeige, dh: in der ersten Iteration wäre die Miniaturansicht auf der rechten Seite und der Text auf der linken Seite, während ich in der nächsten Iteration die Miniaturansicht links und den Text rechts hätte.Gibt es eine Möglichkeit, das Layout von Posts nach jeder Iterations-WordPress zu invertieren?

Hier ist mein Code für Beiträge:

<div class="container"> 
    <div class="col-md-12"> 
     <h2 class="main-hadding">our blog news</h2> 
    </div> 
    <div class="blog-section"> 
     <div class="row"> 

    <?php 
//display 2 posts for category id 47 
    $args=array(
    // 'cat' => 47, 
     'post_type' => 'post', 
     'post_status' => 'publish', 
     'posts_per_page' => 2, 
     'caller_get_posts'=> 1 
    ); 
    $my_query = null; 
    $my_query = new WP_Query($args); 
    if($my_query->have_posts()) { 

     while ($my_query->have_posts()) : $my_query->the_post(); 
      $Post_ID = get_the_ID(); 


     ?> 

<!--  Post Thumbnail--> 
      <div class="col-md-6 col-sm-6"> 
       <?php 
if (has_post_thumbnail()) { 
    the_post_thumbnail(); 
} 
    ?>  
     </div> 

<!--  Post Title and Content--> 
    <div class="col-md-6 col-sm-6"> 
      <div class=" blog-contant"> 
       <h1> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1> 
       <p><?php the_excerpt();?></p> 
      </div> 
     </div> 

     <?php 
     endwhile; 
    } 
wp_reset_query(); // Restore global post data stomped by the_post(). 
?> 
     </div> 


</div> 
    <div class="col-md-12 text-center btn-more"> <a href="#!" class="">MORE BLOG NEWS</a> </div> 

</div> 
+0

auch auf Ihrer Schleife Sie einen Zähler oder Bedingung hinzufügen können in dort ... und fügen Sie eine separate Ansicht für die 2. –

+0

können Sie es bitte ausführen, wie ich es gesucht habe, konnte aber nicht, t nichts nützliches gefunden –

Antwort

0

Eine lange und schmutzige Lösung, aber dies funktionieren wird ..: D

$count = 0; 
while ($my_query->have_posts()) : 
    $my_query->the_post(); 
    $Post_ID = get_the_ID(); 
    if($count == 0) : ?> 
     <!--Post Thumbnail--> 
     <div class="col-md-6 col-sm-6"> 
      <?php 
       if (has_post_thumbnail()) { 
        the_post_thumbnail(); 
       } 
      ?>  
     </div> 

     <!--Post Title and Content--> 
     <div class="col-md-6 col-sm-6"> 
      <div class=" blog-contant"> 
       <h1> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1> 
       <p><?php the_excerpt();?></p> 
      </div> 
     </div> 
    <?php else: ?> 

     <!--Post Title and Content--> 
     <div class="col-md-6 col-sm-6"> 
      <div class=" blog-contant"> 
       <h1> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1> 
       <p><?php the_excerpt();?></p> 
      </div> 
     </div> 
     <!--Post Thumbnail--> 
     <div class="col-md-6 col-sm-6"> 
      <?php 
       if (has_post_thumbnail()) { 
        the_post_thumbnail(); 
       } 
      ?>  
     </div> 
    <?php 
    endif; 
    $count++; 
endwhile; 
Verwandte Themen