admin管理员组文章数量:1310237
How do I get a highlight with only one category but with a different style for each ?
Exemple:
My Code is:
<?php
$args=array(
'cat' => 2,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 3,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'larger' ); ?>
<div class="col-lg-4 col-md-6">
<div class="single-services mb-80">
<div class="services-thumb mb-35">
<img src="<?php echo $image[0]; ?>" alt="img">
</div>
<div class="services-content">
<h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p>
</div>
</div>
</div>
<?php endwhile; ?>
<?php } wp_reset_query(); ?>
How do I get a highlight with only one category but with a different style for each ?
Exemple:
My Code is:
<?php
$args=array(
'cat' => 2,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => 3,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) { ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'larger' ); ?>
<div class="col-lg-4 col-md-6">
<div class="single-services mb-80">
<div class="services-thumb mb-35">
<img src="<?php echo $image[0]; ?>" alt="img">
</div>
<div class="services-content">
<h4><?php the_title(); ?></h4>
<p><?php the_excerpt(); ?></p>
</div>
</div>
</div>
<?php endwhile; ?>
<?php } wp_reset_query(); ?>
Share
Improve this question
asked Jan 19, 2021 at 15:28
Everton GouveiaEverton Gouveia
1011 bronze badge
2
- Can you explain a bit more? I'm not entirely clear on what you're asking. – Tony Djukic Commented Jan 20, 2021 at 15:29
- @TonyDjukic I would like to show a list of the last posts with only one category but with different layouts like the example: i.sstatic/4gM7Z.png – Everton Gouveia Commented Jan 24, 2021 at 20:13
1 Answer
Reset to default 2The concept is that you have queried WP for a defined number of posts, so you can presume you have a total or 3 posts returned thanks to 'posts_per_page' => 3,
-- remember, this might not be true, is there are not enough posts or other parts of the query reduce this number, perhaps because of the wrong category ID.
Here is some pseudo-code to show how you can affect the markup used for each post you render, using the loop ( the rest of your code would still be required ):
// track post loops ##
$loop = 0;
while ($my_query->have_posts()) : $my_query->the_post();
switch( $loop ) {
case 0: // $loop = 0
?>
<h4>Loop One:<?php the_title(); ?></h4>
<?php
break;
case 1: // $loop == 1 etc..
default: // works for all other values not defined in switch cases..
?>
<h4>Loop Two:<?php the_title(); ?></h4>
<?php
break;
}
// iterate post loop count ##
$loop ++;
endwhile;
本文标签: phpFeatured or last post with a different WordPress style without plugin
版权声明:本文标题:php - Featured or last post with a different WordPress style without plugin 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741821636a2399400.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论