2014-04-10 32 views
0

iam從類別「66」獲得10個職位,但我想顯示第一個職位與大縮略圖和其他職位與小縮略圖和mayby一些職位在中間與大縮略圖。我在CSS中的代碼,但我不知道如何指定當我從同一類別調用10個職位。我不想讓2個來自mysql的電話因爲我希望郵寄順序最新到最早...圖像大小自定義css的帖子

謝謝。

 <?php 
     global $post; 
     $args = array('numberposts' => 10, 'order' => 'ASC', 'category' => 66); 
     $myposts = get_posts($args); 
     foreach($myposts as $post) : setup_postdata($post); ?> 
      <div id="lajme-bllok-item-vogel"> 
       <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('lajmi-thumb'); ?></a> 
       <div id="lajme-bllok-item-title-vogel"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div> 
       <div id="top-news-title-linku"><?php for($i=1; $i<=4; $i++){ $prop_det_url = get_field('link'.$i); if($prop_det_url != ''){ ?> 
       <a href="<?php echo $prop_det_url; ?>" target="_blank">/ <?php the_field('link_titull'.$i); ?></a> <?php } } ?></div> 
      </div> 

     <?php endforeach; ?> 
+0

您可以定義不同的類/圖像大小,並在循環中運行計數器並根據計數器調用這些類/圖像大小。 – Ron

回答

1

一種解決方案: 把類別到HTML標記爲一個類名稱例如<div class="category66"> 然後使用nth-child爲每個類生成一個css選擇器?

例如

.category66 { 
    width: 100px; 
    height: 100px; 
} 


.category66:nth-child(1) { 
    width: 200px; 
    height: 200px; 
} 
0

您可以添加代碼周圍的if statement,並說,如果它是第一個結果集的大圖像,否則設置小之一。未經測試,但應該工作。

<?php 
    global $post; 
    $args = array('numberposts' => 10, 'order' => 'ASC', 'category' => 66); 
    $myposts = get_posts($args); 
    $count = 1; 
    foreach($myposts as $post) : setup_postdata($post); 
    if($count=1) 
    { 
    ?> 

     <div id="lajme-bllok-item-vogel"> 
      <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('lajmi-thumb'); ?></a> //Set the big thumbnail there 
      <div id="lajme-bllok-item-title-vogel"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div> 
      <div id="top-news-title-linku"><?php for($i=1; $i<=4; $i++){ $prop_det_url = get_field('link'.$i); if($prop_det_url != ''){ ?> 
      <a href="<?php echo $prop_det_url; ?>" target="_blank">/ <?php the_field('link_titull'.$i); ?></a> <?php } } ?></div> 
     </div> 
    <?php 
     $count = 2; 
    } 
    else 
    { 
    ?> 

     <div id="lajme-bllok-item-vogel"> 
      <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('lajmi-thumb'); ?></a> //Set the small thumbnail there 
      <div id="lajme-bllok-item-title-vogel"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></div> 
      <div id="top-news-title-linku"><?php for($i=1; $i<=4; $i++){ $prop_det_url = get_field('link'.$i); if($prop_det_url != ''){ ?> 
      <a href="<?php echo $prop_det_url; ?>" target="_blank">/ <?php the_field('link_titull'.$i); ?></a> <?php } } ?></div> 
     </div> 
    <?php 
    } 
    endforeach; ?>