获取最新帖子,然后在循环中获取其他帖子 - Wordpress



我想获得最后一篇文章,然后是特定类别的其他帖子。这是我到目前为止得到的代码:检查设计>>这里

<<

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

我不懂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; ?>

感谢@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; ?>

最新更新