我希望获得最后一篇文章,然后是特定类别的其他帖子。这是我到目前为止的代码: CHECK THE DESIGN >>HERE<<
<?php
$args = array(
'cat' => 140, // Category ID
'posts_per_page' => 10
);
$modone_qry = new WP_Query( $args );
?>
<?php if ( $modone_qry->have_posts() ) : while ( $modone_qry->have_posts() ) : $modone_qry->the_post(); ?>
<?php if ($modone_qry->post_count === 1): ?>
<div class="one-post"><h1> LATEST POST HERE </h1></div>
<?php else: ?>
<div class="multi-post"><h1>OTHERS POSTS HERE</h1></div>
<?php endif; ?>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
答案 0 :(得分:1)
我不知道wordpress,但是使用简单的php你可以像这样做
<?php
$args = array(
'cat' => 140, // Category ID
'posts_per_page' => 10
);
$modone_qry = new WP_Query( $args );
?>
<?php $post_number = 0; ?>
<?php if ( $modone_qry->have_posts() ) : while ( $modone_qry->have_posts() ) : $modone_qry->the_post(); ?>
<?php $post_number++; ?>
<?php if ($post_number === 1): ?>
<!-- HTML of latest post - First in loop -->
<?php else: ?>
<!-- HTML of others posts -->
<?php endif; ?>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
答案 1 :(得分:0)
感谢@Autista_z,工作代码:
<?php
$args = array(
'cat' => 140, // Category ID
'posts_per_page' => 10
);
$modone_qry = new WP_Query( $args );
?>
<?php $post_number = 0; ?>
<?php if ( $modone_qry->have_posts() ) : while ( $modone_qry->have_posts() ) : $modone_qry->the_post(); ?>
<?php $post_number++; ?>
<?php if ($post_number === 1): ?>
<h1><?php the_title(); ?> BIG</h1>
<?php else: ?>
<h1><?php the_title(); ?> SMALL</h1>
<?php endif; ?>
<?php endwhile; else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>