PluginProbe
Archive Page / trunk
Archive Page vtrunk
archive-page / archive-page.php

archive-page.php in Archive Page trunk, at archive-page.php

415 lines 12.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Archive Page
4 Plugin URI: https://wp-plugins.in/archive-page
5 Description: Make archive page easily with full customize and in all languages of the world.
6 Version: 1.0.3
7 Author: Alobaidi
8 Author URI: https://wp-plugins.in
9 License: GPLv2 or later
10 */
11
12 /* Copyright 2025 Alobaidi (email: wp-plugins@outlook.com)
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License, version 2, as
16 published by the Free Software Foundation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
28
29 defined( 'ABSPATH' ) or die( 'Silence of gold.' );
30
31
32 function alobaidi_archive_page_plugin_row_meta( $links, $file ) {
33
34 if ( $file == plugin_basename(__FILE__) ) {
35
36 $new_links = array(
37 '<a href="https://wp-plugins.in/archive-page" target="_blank">Explanation of Use</a>',
38 '<a href="https://wordpress.org/plugins/video-popup/" target="_blank" style="font-weight:700;">Video Popup</a>',
39 '<a href="https://wordpress.org/plugins/the-preloader/" target="_blank" style="font-weight:700;">Preloader</a>'
40 );
41
42 $links = array_merge( $links, $new_links );
43
44 }
45
46 return $links;
47
48 }
49 add_filter( 'plugin_row_meta', 'alobaidi_archive_page_plugin_row_meta', 10, 2 );
50
51
52 // Include shortcodes page
53 include(plugin_dir_path(__FILE__).'/shortcodes-page.php');
54
55
56 // Check if blog posts equal 1 or more than 1
57 function obi_ch_more_than_1_post(){
58 $count_posts = wp_count_posts();
59 $get_posts_count = $count_posts->publish;
60 return $get_posts_count >= 1;
61 }
62
63
64 // Check if blog pages equal 1 or more than 1
65 function obi_ch_more_than_1_page(){
66 $count_pages = wp_count_posts('page');
67 $get_pages_count = $count_pages->publish;
68 return $get_pages_count >= 1;
69 }
70
71
72 // Get latest posts
73 function obi_get_latest_posts($posts_number = '10'){
74 $posts_number = trim($posts_number);
75 $posts_number = intval($posts_number);
76 $posts_number = $posts_number > 0 ? $posts_number : '10';
77
78 $latest_post_args = array( 'numberposts' => $posts_number, 'post_type' => 'post', 'post_status' => 'publish' );
79 $recent_posts = wp_get_recent_posts( $latest_post_args );
80 $html = '';
81
82 foreach( $recent_posts as $recent ){
83 $html .= '<li><a href="'.esc_url(get_permalink($recent["ID"])).'" title="'.esc_attr($recent["post_title"]).'">'.esc_html($recent["post_title"]).'</a></li>';
84 }
85
86 return $html;
87 }
88
89
90 // Get tags list
91 function obi_get_tags_list($tags_number = '10'){
92 $tags_number = trim($tags_number);
93 $tags_number = intval($tags_number);
94 $tags_number = $tags_number > 0 ? $tags_number : '10';
95
96 $tags = get_tags("orderby=count&hide_empty=1&number=$tags_number");
97 $html = '';
98
99 foreach ( $tags as $tag ) {
100 $tag_link = get_tag_link( $tag->term_id );
101 $html .= "<li><a href='".esc_url($tag_link)."' title='".esc_attr($tag->name)." Tag'>".esc_html($tag->name)."</a></li>";
102 }
103
104 return $html;
105 }
106
107
108 // Validate heading tag
109 function obi_validate_heading($heading) {
110 $heading = trim($heading);
111 $allowed_headings = array('h1', 'h2', 'h3', 'h4', 'h5', 'h6');
112 return in_array(strtolower($heading), $allowed_headings) ? strtolower($heading) : 'h3';
113 }
114
115
116 // Validate list tag
117 function obi_validate_list($list) {
118 $list = trim($list);
119 $allowed_lists = array('ul', 'ol');
120 return in_array(strtolower($list), $allowed_lists) ? strtolower($list) : 'ol';
121 }
122
123
124 // Daily archive shortcode
125 function obi_daily_archive( $atts, $content = null ){
126
127 extract(
128 shortcode_atts(
129 array(
130 "number" => '', // default is empty (no limit).
131 "heading" => 'h3', // default is <h3></h3>.
132 "list" => 'ul', // default is unordered list <ul></ul>.
133 "title" => 'Daily Archive' // default title is Daily Archive.
134 ),$atts
135 )
136 );
137
138 $title = trim($title);
139 $number = trim($number);
140
141 ?>
142 <?php if ( obi_ch_more_than_1_post() ) : ?>
143 <?php
144 $number = !empty($number) && intval($number) > 0 ? intval($atts['number']) : '';
145 $heading = obi_validate_heading($heading);
146 $list = obi_validate_list($list);
147
148 $result = "<{$heading} class=\"obi-archive-title obi-archive-daily-t\">".esc_html($title)."</{$heading}>";
149 $result .= "<{$list} class=\"obi-archive-list obi-archive-daily-l\">";
150 $result .= wp_get_archives( array( 'type' => 'daily', 'limit' => $number, 'echo' => 0 ) );
151 $result .= "</{$list}>";
152 return $result;
153 ?>
154 <?php endif; ?>
155 <?php
156
157 }
158 add_shortcode("obi_daily_archive", "obi_daily_archive");
159
160
161 // Monthly archive shortcode
162 function obi_monthly_archive( $atts, $content = null ){
163
164 extract(
165 shortcode_atts(
166 array(
167 "number" => '', // default is empty (no limit).
168 "heading" => 'h3', // default is <h3></h3>.
169 "list" => 'ul', // default is unordered list <ul></ul>.
170 "title" => 'Monthly Archive' // default title is Monthly Archive.
171 ),$atts
172 )
173 );
174
175 $title = trim($title);
176 $number = trim($number);
177
178 ?>
179 <?php if ( obi_ch_more_than_1_post() ) : ?>
180 <?php
181 $number = !empty($number) && intval($number) > 0 ? intval($atts['number']) : '';
182 $heading = obi_validate_heading($heading);
183 $list = obi_validate_list($list);
184
185 $result = "<{$heading} class=\"obi-archive-title obi-archive-monthly-t\">".esc_html($title)."</{$heading}>";
186 $result .= "<{$list} class=\"obi-archive-list obi-archive-monthly-l\">";
187 $result .= wp_get_archives( array( 'type' => 'monthly', 'limit' => $number, 'echo' => 0 ) );
188 $result .= "</{$list}>";
189 return $result;
190 ?>
191 <?php endif; ?>
192 <?php
193
194 }
195 add_shortcode("obi_monthly_archive", "obi_monthly_archive");
196
197
198 // Yearly archive shortcode
199 function obi_yearly_archive( $atts, $content = null ){
200
201 extract(
202 shortcode_atts(
203 array(
204 "number" => '', // default is empty (no limit).
205 "heading" => 'h3', // default is <h3></h3>.
206 "list" => 'ul', // default is unordered list <ul></ul>.
207 "title" => 'Yearly Archive' // default title is Yearly Archive.
208 ),$atts
209 )
210 );
211
212 $title = trim($title);
213 $number = trim($number);
214
215 ?>
216 <?php if ( obi_ch_more_than_1_post() ) : ?>
217 <?php
218 $number = !empty($number) && intval($number) > 0 ? intval($atts['number']) : '';
219 $heading = obi_validate_heading($heading);
220 $list = obi_validate_list($list);
221
222 $result = "<{$heading} class=\"obi-archive-title obi-archive-yearly-t\">".esc_html($title)."</{$heading}>";
223 $result .= "<{$list} class=\"obi-archive-list obi-archive-yearly-l\">";
224 $result .= wp_get_archives( array( 'type' => 'yearly', 'limit' => $number, 'echo' => 0 ) );
225 $result .= "</{$list}>";
226 return $result;
227 ?>
228 <?php endif; ?>
229 <?php
230
231 }
232 add_shortcode("obi_yearly_archive", "obi_yearly_archive");
233
234
235 // Latest posts shortcode
236 function obi_latest_posts( $atts, $content = null ){
237
238 extract(
239 shortcode_atts(
240 array(
241 "number" => '10', // default is 10 posts.
242 "heading" => 'h3', // default is <h3></h3>.
243 "list" => 'ul', // default is unordered list <ul></ul>.
244 "title" => 'Latest Posts' // default title is Latest Posts.
245 ),$atts
246 )
247 );
248
249 $title = trim($title);
250 $number = trim($number);
251
252 ?>
253 <?php if ( obi_ch_more_than_1_post() ) : ?>
254 <?php
255 $number = !empty($number) && intval($number) > 0 ? intval($atts['number']) : '10';
256 $heading = obi_validate_heading($heading);
257 $list = obi_validate_list($list);
258
259 $result = "<{$heading} class=\"obi-archive-title obi-archive-latest-posts-t\">".esc_html($title)."</{$heading}>";
260 $result .= "<{$list} class=\"obi-archive-list obi-archive-latest-posts-l\">";
261 $result .= obi_get_latest_posts($number);
262 $result .= "</{$list}>";
263 return $result;
264 ?>
265 <?php endif; ?>
266 <?php
267
268 }
269 add_shortcode("obi_latest_posts", "obi_latest_posts");
270
271
272 // Get categories shortcode
273 function obi_get_cats( $atts, $content = null ){
274
275 extract(
276 shortcode_atts(
277 array(
278 "number" => '', // default is empty (no limit).
279 "heading" => 'h3', // default is <h3></h3>.
280 "list" => 'ul', // default is unordered list <ul></ul>.
281 "title" => 'Categories' // default title is Categories.
282 ),$atts
283 )
284 );
285
286 $title = trim($title);
287 $number = trim($number);
288
289 ?>
290 <?php
291 $number = !empty($number) && intval($number) > 0 ? intval($atts['number']) : '';
292 $heading = obi_validate_heading($heading);
293 $list = obi_validate_list($list);
294
295 $result = "<{$heading} class=\"obi-archive-title obi-archive-cats-t\">".esc_html($title)."</{$heading}>";
296 $result .= "<{$list} class=\"obi-archive-list obi-archive-cats-l\">";
297 $result .= wp_list_categories("title_li=0&number=$number&echo=0");
298 $result .= "</{$list}>";
299 return $result;
300 ?>
301 <?php
302
303 }
304 add_shortcode("obi_get_cats", "obi_get_cats");
305
306
307 // Get tags shortcode
308 function obi_get_tags( $atts, $content = null ){
309
310 extract(
311 shortcode_atts(
312 array(
313 "number" => '10', // default is 10 tags.
314 "heading" => 'h3', // default is <h3></h3>.
315 "list" => 'ul', // default is unordered list <ul></ul>.
316 "title" => 'Tags' // default title is Tags.
317 ),$atts
318 )
319 );
320
321 $title = trim($title);
322 $number = trim($number);
323
324 ?>
325 <?php if( wp_count_terms( array('taxonomy' => 'post_tag', 'hide_empty' => true) ) >= 1 ) : ?>
326 <?php
327 $number = !empty($number) && intval($number) > 0 ? intval($atts['number']) : '10';
328 $heading = obi_validate_heading($heading);
329 $list = obi_validate_list($list);
330
331 $result = "<{$heading} class=\"obi-archive-title obi-archive-tags-t\">".esc_html($title)."</{$heading}>";
332 $result .= "<{$list} class=\"obi-archive-list obi-archive-tags-l\">";
333 $result .= obi_get_tags_list($number);
334 $result .= "</{$list}>";
335 return $result;
336 ?>
337 <?php endif; ?>
338 <?php
339
340 }
341 add_shortcode("obi_get_tags", "obi_get_tags");
342
343
344 // Get pages shortcode
345 function obi_get_pages( $atts, $content = null ){
346
347 extract(
348 shortcode_atts(
349 array(
350 "number" => '', // default is empty (no limit).
351 "heading" => 'h3', // default is <h3></h3>.
352 "list" => 'ul', // default is unordered list <ul></ul>.
353 "title" => 'My Pages' // default title is My Pages.
354 ),$atts
355 )
356 );
357
358 $title = trim($title);
359 $number = trim($number);
360
361 ?>
362 <?php if( obi_ch_more_than_1_page() ) : ?>
363 <?php
364 $number = !empty($number) && intval($number) > 0 ? intval($atts['number']) : '';
365 $heading = obi_validate_heading($heading);
366 $list = obi_validate_list($list);
367
368 $result = "<{$heading} class=\"obi-archive-title obi-archive-pages-t\">".esc_html($title)."</{$heading}>";
369 $result .= "<{$list} class=\"obi-archive-list obi-archive-pages-l\">";
370 $result .= wp_list_pages("title_li=0&number=$number&echo=0");
371 $result .= "</{$list}>";
372 return $result;
373 ?>
374 <?php endif; ?>
375 <?php
376
377 }
378 add_shortcode("obi_get_pages", "obi_get_pages");
379
380
381 // Get authors shortocode
382 function obi_get_authors( $atts, $content = null ){
383
384 extract(
385 shortcode_atts(
386 array(
387 "number" => '', // default is empty (no limit).
388 "heading" => 'h3', // default is <h3></h3>.
389 "list" => 'ul', // default is unordered list <ul></ul>.
390 "title" => 'Authors' // default title is Authors.
391 ),$atts
392 )
393 );
394
395 $title = trim($title);
396 $number = trim($number);
397
398 ?>
399 <?php if ( obi_ch_more_than_1_post() ) : ?>
400 <?php
401 $number = !empty($number) && intval($number) > 0 ? intval($atts['number']) : '';
402 $heading = obi_validate_heading($heading);
403 $list = obi_validate_list($list);
404
405 $result = "<{$heading} class=\"obi-archive-title obi-archive-author-t\">".esc_html($title)."</{$heading}>";
406 $result .= "<{$list} class=\"obi-archive-list obi-archive-author-l\">";
407 $result .= wp_list_authors("hide_empty=1&show_fullname=1&style=list&optioncount=1&orderby=id&html=1&number=$number&echo=0");
408 $result .= "</{$list}>";
409 return $result;
410 ?>
411 <?php endif; ?>
412 <?php
413
414 }
415 add_shortcode("obi_get_authors", "obi_get_authors");