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代码结构可以任意调整。
Copyright © 2013-2023 xikunyun.com. All Rights Reserved 西昆云版权所有 南通西昆云计算有限公司 苏ICP备20014144号-2