首页 > php教程 > php手册 > 正文

wordpress列出所有分类目录下一定数量的文章

php中文网
发布: 2016-06-06 20:09:19
原创
1659人浏览过

不影响主LOOP, 分页正常工作 限制每个分类下文章数量 列出所有分类, 不用指定 ul ?php/** * wordpress list limited number of posts group by all categories * without destroying the main hook * coded by xiaohudie * i promised i'd use English to an

  1. 不影响主LOOP, 分页正常工作
  2. 限制每个分类下文章数量
  3. 列出所有分类, 不用指定
<ul> 
	<?php
	/**
	 * wordpress list limited number of posts group by all categories
	 * without destroying the main hook
	 * coded by xiaohudie
	 * i promised i'd use English to annotate my code, and now i did it
	 * 2013-05-08
	 */
	global $post;
	$reset_post = $post;
	$cat =get_categories();
	foreach($cat as $category) :
		$args=array(
			'numberposts' => 5, // limit number
			//'ignore_sticky_posts'=>1,// defult:0 not ignore
			'category__in' => array($category->term_id) //use category id to hook the category parameters
		);
		$xhdpost = get_posts( $args );
		echo '<h3> Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </h3> ';
		foreach ( $xhdpost as $post ) : setup_postdata($post); ?>
			<li><a href="http://xiaohudie.net/code/&lt?php the_permalink(); ?>"><?php the_title(); ?></a></li>
	<?php
	endforeach; 
	endforeach;
	$post = $reset_post; // most important step to reset after postlists with offset 
	?>
</ul>
登录后复制

Demo:
20130508132438
WPS零基础入门到精通全套教程!
WPS零基础入门到精通全套教程!

全网最新最细最实用WPS零基础入门到精通全套教程!带你真正掌握WPS办公! 内含Excel基础操作、函数设计、数据透视表等

下载
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号