北极寒流 » 网络资源 » wordpress首页输出所有分类的最新文章 - 2013.09.20

wordpress首页输出所有分类的最新文章

wordpress首页输出所有分类的最新文章这个功能主要用在CMS的主题上,当然,除了能显示所有分类外,也可以排除分类,代码收集备忘

<div id="catalog">
<div id="tips">
<div class="layout">
<div class="guide">
<span class="mark">
<i class="mark-hot">热门网址</i> <i class="mark-new">最新收入</i>
</span>
</div>
<span class="hot-words"></span>
</div>
<?php if(get_option('T_share') == "On") {?>
<?php include (TEMPLATEPATH . '/share.php'); ?>
<?php } ?>
</div>
<div class="clear"></div>
<?php
$cat_args=array(
'orderby' => 'id',
'order' => 'ASC',
'exclude' =>  array(86)//排除分类的ID值
);
$categories=get_categories($cat_args);
foreach($categories as $category) {
$args=array(
'showposts' => 8,
'category__in' => array($category->term_id),
'caller_get_posts'=>1
);
$posts=get_posts($args);
if ($posts) {
echo '<div id="'.$category->category_nicename.'" class="cat">';
echo '<div class="cat_list"><span><a href="'.get_category_link( $category->term_id ).'" title="'. sprintf( __( "更多 %s 网站推荐" ), $category->name ) .'">'. $category->name.'</a></span><span class="more"> »更多</span></div> ';
echo '<ul class="website-list">';
foreach($posts as $post) {
setup_postdata($post); ?>
<li<?php if(date("ymd") - get_the_time("ymd") <= 1) {echo ' class=new';} elseif (is_sticky()){echo ' class=hot';} else {echo ' class=website';}?>>
<?php $link = get_post_meta($post->ID, 'link', true);
if(!empty($link)) {?>
<a class="title" href="<?php print_post_title() ?>" title="<?php the_title_attribute(); ?>" ><?php the_title(); ?></a>
<p class="desc"><?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 168,"..."); ?></p>
<?php } else { ?>
<a class="title" href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>" target="_blank" ><?php the_title(); ?></a>
<p class="desc"><?php echo mb_strimwidth(strip_tags(apply_filters('the_content', $post->post_content)), 0, 168,"..."); ?></p>
<?php } ?>
</li>
<?php
}}
echo '</ul>';
echo '</div>';
}
?>
</div>

20

wordpress首页输出所有分类的最新文章

分享到: