2015-09-10 30 views
0

我試圖對第一篇文章的風格與其他文章不同。它是針對index.php上的「精選」部分的。一個wordpress循環與不同的風格輸出

<?php 
$count = 0; 
// The Query 
$the_query = new WP_Query($args); 
// The Loop 
while ($the_query->have_posts()) : $the_query->the_post(); 
$count++; 
if ($count == 1) : ?> 

    <div class="big"> 

     <div class="details"> 
     <a class="cat" href="#">nike</a> 
     <a href="<?php the_permalink(); ?>"><p><?php the_title(); ?></p></a> 
     <ul class="stats"> 
     <li class="icon-calendar"><?php the_time('m.d.Y') ?></li> 
     <li class="icon-eye"><?php if(function_exists('the_views')) { the_views(); } ?></li> 
     </ul> 
     </div> 
     <?php echo get_first_inserted_image(); ?> 

    </div> 

<?php else : ?> 

    <div class="small"> 

     <div class="holder"> 
     <a href="<?php the_permalink(); ?>"><?php echo get_first_inserted_image(); ?></a> 
      <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> 
     </div>  

    </div> 

<?php endif; ?> 
<?php endwhile; ?> 

<?php wp_reset_postdata(); ?> 

上面的代碼似乎沒有任何顯示。我還想對此展開以顯示過去7天內只有4個隨機帖子。任何指導表示感謝!謝謝!

+1

沒有被顯示出來,因爲你已經通過'$ args'到查詢沒有定義'$ args' ... – rnevius

回答

0

這讓它做

<?php 

// WP_Query arguments 
$args = array (
    'orderby' => 'rand', 
    'showposts' => 5, 
    'date_query' => array(
     array(
      'after' => '1 week ago' 
     ) 
    ) 

); 


$count = 0; 
// The Query 
$the_query = new WP_Query($args); 
// The Loop 
while ($the_query->have_posts()) : $the_query->the_post(); 
$count++; 
if ($count == 1) : ?> 

    <div class="big"> 

     <div class="details"> 
     <a class="cat" href="#">nike</a> 
     <a href="<?php the_permalink(); ?>"><p><?php the_title(); ?></p></a> 
     <ul class="stats"> 
     <li class="icon-calendar"><?php the_time('m.d.Y') ?></li> 
     <li class="icon-eye"><?php if(function_exists('the_views')) { the_views(); } ?></li> 
     </ul> 
     </div> 
     <a href="<?php the_permalink(); ?>"><?php echo get_first_inserted_image(); ?></a> 

    </div> 

<?php else : ?> 

    <div class="small"> 

     <div class="holder"> 
     <a href="<?php the_permalink(); ?>"><?php echo get_first_inserted_image(); ?></a> 
      <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p> 
     </div>  

    </div> 

<?php endif; ?> 
<?php endwhile; ?> 

<?php wp_reset_postdata(); ?>