0

php我使用代码的文件上:

<div>
    <?php
        include('../blog/wp-blog-header.php');
        define('WP_USE_THEMES', false);
        $my_query = new WP_Query(array ('cat=11', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => '2' ));
        while ($my_query->have_posts()) : $my_query->the_post();
    ?>
    <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
    <?php the_excerpt() ?>
    <?php endwhile; ?>
    <?php wp_reset_postdata();?>
</div>
<ul>
    <?php
        $my_query = new WP_Query(array ('cat=11', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => '10','offset' => 2  ) );
        $i=0;
        while ($my_query->have_posts()) : $my_query->the_post();
    ?>
    <li  <?php if($i==4) echo 'class="except"'; ?>>
        <a href="<?php the_permalink() ?>" ><?php the_title(); ?></a>
    </li>
    <?php $i++;?>
    <?php endwhile; ?>
    <?php wp_reset_postdata();?>
</ul>

上面的代码不仅调用了id为11的category,还调用了其他category。为什么?

4

1 回答 1

1

代替

$my_query = new WP_Query(array ('cat=11', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => '10','offset' => 2  ) );

和:

$my_query = new WP_Query(array ('cat' => 11, 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page' => '10','offset' => 2  ) );

参考:http ://codex.wordpress.org/Class_Reference/WP_Query

于 2012-12-24T05:52:08.940 回答