2015-01-13 40 views
0

我循环通过定义的类别中的前几个职位,第一个是从其余的分开,但第一个然后仍然包括在内。我需要$ i号码2等,不要包含已显示的第一个帖子。独立的第一篇文章,并忽略重复

我推测在$我有某种休息。我尝试将$ i切换为2,作为我现在玩的初学者。

enter image description here

<div class="article-block-v1"> 
<?php 
//get terms (category ids 11,2,33,34), then display one post in each term 
$taxonomy = 'category';// e.g. post_tag, category 
$param_type = 'category__in'; // e.g. tag__in, category__in 
$term_args=array(
    'include' => '1459', 
    'orderby' => 'date', 
    'order' => 'DESC' 
); 
$terms = get_terms($taxonomy,$term_args); 

if ($terms) { 
    foreach($terms as $term) { 
    $args=array(
     "$param_type" => array($term->term_id), 
     'post_type' => 'post', 
     'post_status' => 'publish', 
     'posts_per_page' => 3, 
    ); 
    $my_query = null; 
    $my_query = new WP_Query($args); 

    $i = 1; 

    if($my_query->have_posts()) { 
    echo '<ul>'; 
    while ($my_query->have_posts()) : $my_query->the_post(); ?> 

    <?php if ($i == 1): ?> 

    <div class="article-block-v1"> 

    <div class="category-label-large category-news-analysis"> 
     <a href="<?php the_permalink(); ?>"><p><?php echo $term->name; ?></p></a> 
    </div> 
    <div class="view2 third-effect"> 
    <?php the_post_thumbnail(); ?> 
     <div class="mask"> 
      <a href="<?php the_permalink() ?>" class="info" ><i class="fa fa-search"></i></a> 
     </div> 
    </div> 
    <ul class="homepagewhitebg"> 
     <li><h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5></li> 
    </ul> 

    </div> 

    <?php $i = 2; ?> 

    <?php endif; ?> 

    <li><a href="<?php the_permalink(); ?>"><p><?php the_title(); ?></p></a></li> 

    <?php 
     $i++; 
      endwhile; 
      echo '</ul>'; 
     } 
     } 
    } 
    wp_reset_query(); // Restore global post data stomped by the_post(). 
?> 

回答

0

我整理这到底,想通我只是需要让$ I不再等于1,因此显示剩余的帖子后else语句。然后也增加了每页帖子。

<div class="article-block-v1"> 
<?php 
//get terms (category ids 11,2,33,34), then display one post in each term 
$taxonomy = 'category';// e.g. post_tag, category 
$param_type = 'category__in'; // e.g. tag__in, category__in 
$term_args=array(
    'include' => '1459', 
    'orderby' => 'date', 
    'order' => 'DESC' 
); 
$terms = get_terms($taxonomy,$term_args); 

if ($terms) { 
    foreach($terms as $term) { 
    $args=array(
     "$param_type" => array($term->term_id), 
     'post_type' => 'post', 
     'post_status' => 'publish', 
     'posts_per_page' => 4, 
    ); 
    $my_query = null; 
    $my_query = new WP_Query($args); 

    $i = 1; 

    if($my_query->have_posts()) { 
    echo '<ul>'; 
    while ($my_query->have_posts()) : $my_query->the_post(); ?> 

    <?php if ($i == 1): ?> 

    <div class="article-block-v1"> 

    <div class="category-label-large category-news-analysis"> 
     <a href="<?php the_permalink(); ?>"><p><?php echo $term->name; ?></p></a> 
    </div> 
    <div class="view2 third-effect"> 
    <?php the_post_thumbnail(); ?> 
     <div class="mask"> 
      <a href="<?php the_permalink() ?>" class="info" ><i class="fa fa-search"></i></a> 
     </div> 
    </div> 
    <ul class="homepagewhitebg"> 
     <li><h5><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5></li> 
    </ul> 

    </div> 

    <?php else: ?> 

    <li><a href="<?php the_permalink(); ?>"><p><?php the_title(); ?></p></a></li> 

    <?php endif; ?> 

    <?php 
     $i++; 
      endwhile; 
      echo '</ul>'; 
     } 
     } 
    } 
    wp_reset_query(); // Restore global post data stomped by the_post(). 
?>