2017-04-10 106 views
-3

我想获得最后一篇文章,然后从特定类别的其他帖子。这个代码我走到这一步: CHECK THE DESIGN >>HERE<<获取最新的帖子,然后在循环中的其他帖子 - 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; ?>

+3

这是什么问题? –

+0

它仍然循环所有帖子不是第一个然后其他 –

+0

请检查设计参考:https://i.stack.imgur.com/KKs0Y.png –

回答

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

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

如果你看看这个设计,我认为Eiad需要循环的文章,其中第一个设计更大,其他更小。而做这件事的“愚蠢”方式,就是我写的。 –

+0

是的你是对的。 –

+0

@ Autista_z你是对的,也可以请帮助更多的细节?最新帖子的HTML和其他帖子循环在哪里?请检查设计在这里:https://i.stack.imgur.com/KKs0Y.png –

相关问题