如何将wordpress首页设置cms布局?wordpress调用多个分类生成首页cms布局代码
来源:互联网 浏览:881次 时间:2021-04-28 11:34:08
wordpress首页cms布局就需要调用多个分类的内容,一开始接触wordpress的时候这段代码是从另外一个主题里面借鉴过来的,用的是while循环,用的我百般不习惯。
后来直接抄了zblog的foreach循环,也不知道对不对,反正能用…
分享出来,可以互相参政。
- <?php
- $themecateid = '1,2,3';
- $flids = explode(',',$themecateid);
- foreach ($flids as $cid){
- ?>
- <?php
- <ul>
- query_posts('posts_per_page=8&caller_get_posts=1&orderby=rand&cat='.$cid);
- while (have_posts()) : the_post();
- echo '<li><a href="'.get_permalink().'" title="'.$post->post_title.'" target="_blank">'
- .$post->post_title.'</a></li>';
- endwhile;
- wp_reset_query();
- </ul>
- ?>
- <?php } ?>
以上代码的“1,2,3”为调用的分类id,里面的一层还是用了while循环。html代码结构可以任意调整。