当前位置:蚂蚁分类目录 » 站长资讯 » 站长运营 » WordPress教程 » 文章详细 订阅RssFeed

如何将wordpress首页设置cms布局?wordpress调用多个分类生成首页cms布局代码

来源:互联网 浏览:881次 时间:2021-04-28 11:34:08

wordpress首页cms布局就需要调用多个分类的内容,一开始接触wordpress的时候这段代码是从另外一个主题里面借鉴过来的,用的是while循环,用的我百般不习惯。

后来直接抄了zblog的foreach循环,也不知道对不对,反正能用…

分享出来,可以互相参政。

  1. <?php
  2. $themecateid = '1,2,3';
  3. $flids = explode(',',$themecateid);
  4. foreach ($flids as $cid){
  5. ?>
  6. <?php
  7. <ul>
  8. query_posts('posts_per_page=8&caller_get_posts=1&orderby=rand&cat='.$cid);
  9. while (have_posts()) : the_post();
  10. echo '<li><a href="'.get_permalink().'" title="'.$post->post_title.'" target="_blank">'
  11. .$post->post_title.'</a></li>';
  12. endwhile;
  13. wp_reset_query();
  14. </ul>
  15. ?>
  16. <?php } ?>

以上代码的“1,2,3”为调用的分类id,里面的一层还是用了while循环。html代码结构可以任意调整。