wordpress查询

WP_Query

获取当前页面内容

1
2
3
$now_id=get_the_ID();
$now_post=get_post($now_id);
$now_content=$now_post->post_content;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
获取当前文章内容,根据文章内容来获取
*/
$now_id=get_the_ID();
$now_post=get_post($now_id);
$now_content=$now_post->post_content;
$content_json=json_decode($now_content,true);
//print_r($content_json);
$text_title=$content_json["title"];
$text_small=$content_json["title-small"];
$category_text=$content_json["category"];
$args = array(
'post_type' => 'post',
'showposts' => 8,
"category_name"=>$category_text,
'orderby' => 'date',
'paged' => $paged,
);
$loop = new WP_Query($args);

查询说明

1
2
3
4
5
6
7
$args = array(
'post_type' => 'post',
'showposts' => 8,
"category_name"=>$category_text,
'orderby' => 'date',
'paged' => $paged,
);

post_type为查询类型
category_name为文章的别名

剩下的看API即可..以后会逐步更新