帖子的图像大小自定义css



iam从类别"66"中获得10篇帖子,但我想显示第一篇带有大缩略图的帖子,其余的帖子带有小缩略图,中间可能有一些带有大缩略图。我有CSS中的代码,但我不知道如何指定何时调用同一类别中的10篇帖子。我不想从mysql打两个电话,因为我想要最新到最旧的订单。。。

谢谢。

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

一个解决方案:将类别作为类名放入HTML标记中,例如<div class="category66">然后使用nth-child为每个类生成一个css选择器?

例如

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

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

您可以在代码周围添加一个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; ?>

最新更新