wordpress查询获取文章、页面

[php]
<?
//获取特定分类文章名称
query_posts(‘cat=15&showposts=10’);//如果不设定文章显示数量,默认显示5篇
//获取相关页面
query_posts(‘p=3’);//page_id=3
query_posts(‘page_id=3’);
query_posts(‘pagename=about’);
//从主页中移除特定分类,本例中移除ID为3的分类
if(is_home()){
query_posts(‘cat=-3’);
}
//获取文章,采用循环
$posts=get_posts(‘numberposts=15,category=,off=,orderby=,category_name=’);
foreach($posts as $post):
setup_postdata($post);
the_permalink();//获取文章链接
the_title();//获取文章标题
the_content();//获取文章内容
endforeach;

?>

[/php]

解决数据库或网页显示乱码问题

网页显示问题有两种可能:

1.网页编码问题

(1)设置:<meta http-equiv=”content-Type” content=”text/html; charset=gb2312″> 或:<meta http-equiv=”content-Type” content=”text/html; charset=utf-8″>

(2)用编辑器重新打开网页源程序,另存为utf-8编码。

(3)php源程序 头部加上Header(“Content-type:text/html;charset=utf-8”);

2.数据库乱码问题

加一条命令“set names utf8”