我正在寻找一种方法来修改此代码以使第一个样式不同,然后下 2 个帖子的样式也不同,而帖子的其余部分的样式也将不同。
<?php
$queryObject = new Wp_Query( array(
'showposts' => 5,
'post_type' => array('post'),
'category_name' => videos,
'orderby' => 1,
));
// The Loop
if ( $queryObject->have_posts() ) :
$i = 0;
while ( $queryObject->have_posts() ) :
$queryObject->the_post();
if ( $i == 0 ) : ?>
<div class="first-post">
<a href="<?php the_permalink(); ?>" title="<?php printf(__( 'Read %s', 'wpbx' ), wp_specialchars(get_the_title(), 1)) ?>">
<?php the_post_thumbnail('sidethumbs'); ?>
</a>
<?php endif;
if ( $i != 0 ) : ?>
<div class="secondary-post">
<?php endif; ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<?php the_title(); ?>
</a>
</div>
<?php $i++;
endwhile;
endif;
?>
我已经尝试过,但这是我迄今为止所拥有的。请帮忙。
所以一个 switch case 可能看起来像这样 - 这样你就可以指定第一个、第二个和其余的应该是什么样子 - 但你也可以只使用 if(){} elseif(){} else{}
<?php
$queryObject = new Wp_Query( array(
'showposts' => 5,
'post_type' => array('post'),
'category_name' => videos,
'orderby' => 1,
));
// The Loop
if ( $queryObject->have_posts() ) :
$i = 0;
while ( $queryObject->have_posts() ) :
$queryObject->the_post();
$postClass = "";
switch ($i) {
case 0:
$postClass = "firstpost";?>
<div class="<?php echo $postClass;?>">
<a href="<?php the_permalink(); ?>" title="<?php printf(__( 'Read %s', 'wpbx' ), wp_specialchars(get_the_title(), 1)) ?>">
<?php the_post_thumbnail('sidethumbs'); ?>
</a>
</div>
<?php break;
case 1:
$postClass = "secondpost";
//More of the same stuff.
break;
default:
$postClass = "restOfPosts";
//How the rest of the posts should look like
break;
}
$i++;
endwhile;
endif;
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句