-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmodule_sitemap.php
177 lines (141 loc) · 3.89 KB
/
module_sitemap.php
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
$biz_vektor_options = biz_vektor_get_theme_options();
/*------------------------
--SITEMAP ADVANCED OPTIONS
----------------------------*/
//post types to display on sitemap
$types = array(
array(
'post-type' => 'info',
'taxonomy' => array(
array(
'taxoName' => 'info-cat',
'taxoLabel' => '',
),
),
'label' => $biz_vektor_options['infoLabelName'],
'link' => get_post_type_archive_link( 'info' ),
),
array(
'post-type' => 'post',
'taxonomy' => array(
array(
'taxoName' => 'category',
'taxoLabel' => '',
),
),
'label' => $biz_vektor_options['postLabelName'],
'link' => get_post_type_archive_link( 'post' ),
),
);
//pages to exclude
$pages = '';
//gets advanced options saved by administrator from DB
$advancedOptions = Biz_Vektor_Advanced_Options::getAdvancedOptions();
if ( isset( $advancedOptions ) ) {
//adds custom post types names, hierarchical taxonomies (categories), details to $types array
if ( isset( $advancedOptions['types'] ) && ! empty( $advancedOptions['types'] ) ) {
$i = count( $types );
foreach ( $advancedOptions['types'] as $typeName ) {
//checks if post type exists
$typeObj = get_post_type_object( $typeName );
if ( isset( $typeObj ) ) {
$types[ $i ]['post-type'] = $typeName;
//gets custom post type infos based on default WordPress behaviour
$types[ $i ]['link'] = home_url( '/' . $typeName );
$types[ $i ]['label'] = get_post_type_object( $typeName )->labels->name;
//gets all taxonomies of custom type
$typeTaxo = get_object_taxonomies( $typeName, 'objects' );
//looks for category (hierarchical taxonomy)
if ( isset( $typeTaxo ) && ! empty( $typeTaxo ) ) {
$j = 0;
foreach ( $typeTaxo as $taxoName => $taxoObj ) {
if ( $taxoObj->hierarchical ) {
$types[ $i ]['taxonomy'][ $j ]['taxoName'] = $taxoName;
$types[ $i ]['taxonomy'][ $j ]['taxoLabel'] = $taxoObj->labels->name;
$j++;
}
}
}
$i++;
}
}
}
//adds id of pages to remove from sitemap (array to string)
if ( isset( $advancedOptions['pages'] ) && ! empty( $advancedOptions['pages'] ) ) {
$length = count( $advancedOptions['pages'] );
if ( $length > 1 ) {
$pages = implode( ',', $advancedOptions['pages'] );
} else {
$pages = $advancedOptions['pages'][0];
}
}
}
?>
<!-- [ #sitemapOuter ] -->
<div id="sitemapOuter">
<div id="sitemapPageList">
<ul class="linkList">
<?php
//pages
$args = array(
'title_li' => '',
'exclude_tree' => $pages, //hides children
);
wp_list_pages( $args );
?>
</ul>
</div>
<!-- [ #sitemapPostList ] -->
<div id="sitemapPostList">
<?php
foreach ( $types as $type ) {
//test query to know if there is posts in this post type
$args = array(
'posts_per__page' => 1,
'post_type' => $type['post-type'],
);
$query = new WP_Query( $args );
if ( $query->found_posts > 0 ) {
?>
<div class="sectionBox">
<h5>
<?php
if ( isset( $type['link'] ) && ! empty( $type['link'] ) ) {
?>
<a href="<?php echo $type['link']; ?>">
<?php echo isset( $type['label'] ) ? $type['label'] : ''; ?>
</a>
<?php
} else {
echo isset( $type['label'] ) ? $type['label'] : '';
}
?>
</h5>
<?php
foreach ( $type['taxonomy'] as $i => $taxonomy ) {
if ( count( $type['taxonomy'] ) > 1 ) {
?>
<h6><?php echo $taxonomy['taxoLabel']; ?></h6>
<?php
}
?>
<ul class="linkList">
<?php
$args = array(
'taxonomy' => $taxonomy['taxoName'],
'title_li' => '',
'orderby' => 'order',
'show_option_none' => '',
);
wp_list_categories( $args );
?>
</ul>
<?php } ?>
</div>
<?php
}
}
?>
</div><!-- [ /#sitemapPostList ] -->
</div><!-- [ /#sitemapOuter ] -->