我有一个博客,主页上有3块帖子。所以,我用“get\\u post”获得这些帖子,我在页面上有3个类似的代码:
global $post;
$args = array( ... );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
.......
<?php endforeach; ?>
我的CPU负载很高,我想知道我是否会使用“wp\\u query”来节省我的CPU。谢谢
以下是我的get\\u posts()查询:
<?php
global $post;
$args = array( \'numberposts\' => 5, \'offset\'=> 0, \'category\' => "1" );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_title(); ?>
</div>
<?php endforeach; ?>
<小时>
<?php
global $post;
$args = array( \'numberposts\' => 7, \'offset\'=>0, \'category\' =>"2 , 4 , 6 , 7 , 9 ,10,11");
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php the_post_thumbnail(array(\'size\' => 300,300), array(\'title\' => \'\')); ?>
</div>
<?php endforeach; ?>
<小时>
<?php
$args = array( \'numberposts\' => 15, \'orderby\' => \'rand\' ,\'offset\'=>0, \'category\' =>"31");
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php the_title(); ?>
</div>
<?php endforeach; ?>