sitemap-seo.php
5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
require_once('./wp-load.php');
global $wpdb;
//获取自定义分类url
function get_cate_zdy_url($cat_type = 'news',$per_page_num = 0,$has_parent = 1){
$count_g = 0;
$ar_show = ['news','project','aboutch','solutions','applications','download','video','service','blog','application','case','project-case'];
$taxnomy = $cat_type.'_category';
if(in_array($cat_type,$ar_show)){
$taxnomy = $cat_type.'_catalog';
}
$arg = array(
'taxonomy' => $taxnomy,
'orderby' => 'name',
'show_count' => 1,
'pad_counts' => 0,
'hierarchical' => 0
);
$ar_url = array();
$categories = get_categories( $arg );
if(isset($categories['errors'])){
return $ar_url;
}
foreach($categories as $category){
$categoryid = $category->term_id;
$category_link = home_url("/").$cat_type.'-categories/'.$category->slug.'/';
if(in_array($cat_type,$ar_show)){
$category_link = home_url("/").$cat_type.'_catalog/'.$category->slug.'/';
}
$ar_url[] = $category_link;
if($category->count > $per_page_num){
$page_count = ceil($category->count/$per_page_num);
for($i=2;$i<=$page_count;$i++){
$ar_url[] = $category_link.'page/'.$i.'/';
}
}
if($has_parent == 0){
$count_g += $category->count;
}
}
if($has_parent == 0){
$ar_url[] = home_url("/").$cat_type.'/';
$g_page_count = ceil($count_g/$per_page_num);
for($i=2;$i<=$g_page_count;$i++){
$ar_url[] = home_url("/").$cat_type.'/page/'.$i.'/';
}
}
return $ar_url;
}
$except_post_type = ['3code','acf','admin','ad_img','attachment','banner','banner-sidebar','banner_sidebar','cf7_entry','dw_license','fl-builder-template','gd-admin','helppage','home','import_users','lianxi','nav_menu_item','p','pro','pro_detail','pro_shuxing','skype','sns','title','transall','v','wpcf7_contact_form','ww','post','page','revision','vs','wp_automatic'];
$post_types_res = $wpdb->get_results('select post_type from wp_posts group by post_type',ARRAY_A);
$post_types = [];
foreach ($post_types_res as $v){
if(!in_array($v['post_type'],$except_post_type)){
$post_types[] = $v['post_type'];
}
}
$ar_url = array();
$ar_url[] = home_url("/");
$args = array(
'hide_empty' => 0
);
$categories = get_categories( $args );
$per_page_num = get_option('posts_per_page');
$cat_ids = array();
foreach($categories as $category){
if($category->name != 'Featured' && $category->name != 'Featured Products'){
$cat_ids[] = $category->term_id;
$categoryid = $category->term_id;
$category_link = get_category_link( $categoryid );
$ar_url[] = $category_link;
if($category->count > $per_page_num){
$page_count = ceil($category->count/$per_page_num);
for($i=2;$i<=$page_count;$i++){
$ar_url[] = $category_link.'page/'.$i.'/';
}
}
}
}
if($post_types){
foreach ($post_types as $v){
$gallery_url = get_cate_zdy_url($v,$per_page_num);
if($gallery_url){
$ar_url = array_merge($ar_url,$gallery_url);
}
$ar_url[] = home_url("/").$v.'/';
$news_num = count(query_posts(array( 'post_type' => $v,'posts_per_page'=>-1)));
if($news_num>$per_page_num){
$page_count = ceil($news_num/$per_page_num);
for($i=2;$i<=$page_count;$i++){
$ar_url[] = home_url("/").$v.'/'.'page/'.$i.'/';
}
}
query_posts(array( 'post_type' => $v,'showposts' => 5000) ); while (have_posts()) : the_post();
$ar_url[] = get_permalink($post->ID);
endwhile; wp_reset_query();
}
}
query_posts(array( 'post_type' => 'page','showposts' => 5000) ); while (have_posts()) : the_post();
$ar_url[] = get_permalink($post->ID);
endwhile; wp_reset_query();
$ar_url_cnt = count($ar_url);
foreach($categories as $category){
if($category->name != 'Featured' && $category->name != 'Featured Products'){
query_posts(array( 'cat' => $category->term_id,'post_type' => 'post','showposts' => 10000));while ( have_posts() ) : the_post();
$cur_url = get_permalink($post->ID);
if(!in_array($cur_url,$ar_url) && $ar_url_cnt <= 30000){
$ar_url[] = $cur_url;
$ar_url_cnt++;
}
endwhile; wp_reset_query();
}
}
$ar_url = array_unique($ar_url);
$ar_url = array_unique($ar_url);
echo implode('<br>',$ar_url);
echo '<br/>' ;
$tags = get_tags();
foreach($tags as $tag){
echo get_tag_link ($tag->term_id);
echo '<br/>' ;
}
?>
<hr>
<?php wp_tag_cloud('smallest=12&largest=12&unit=px&number=500&orderby=count&order=DESC&taxonomy=category');?>
<?php wp_tag_cloud('smallest=12&largest=12&unit=px&number=500&orderby=count&order=DESC');?><hr>
<?php
$args = array(
'hide_empty' => 0
);
$categories = get_categories( $args );
//上面的代码获取所有分类
?>
<?php foreach($categories as $category){ ?>
<?php $categoryid = $category->term_id;
$categoryname = $category->cat_name;
$category_link = get_category_link( $categoryid );?>
<?php echo $category_link; ?>{<?php echo $categoryname; ?>}<br />
<?php } ?>
<?php
//tag地址
$tags = get_tags();
foreach($tags as $tag){
echo get_tag_link ($tag->term_id);
echo '{' .$tag->name.'}<br/>' ;
}
echo '<hr>';
$posts = query_posts(array('post_type' => 'post','showposts' => 10000));while ( have_posts() ) : the_post();
echo get_permalink($post->ID);
echo '{' .$post->post_title.'}<br/>' ;
endwhile; wp_reset_query();
?>