PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/list-category-posts/list_cat_posts.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 132 lines | 91 code | 7 blank | 34 comment | 17 complexity | c3143bb5d08f0a098c9d184dbf3ae85d MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: List category posts
  4. Plugin URI: http://picandocodigo.net/programacion/wordpress/list-category-posts-wordpress-plugin-english/
  5. Description: List Category Posts allows you to list posts from a category into a post/page using the [catlist] shortcode. This shortcode accepts a category name or id, the order in which you want the posts to display, and the number of posts to display. You can use [catlist] as many times as needed with different arguments. Usage: [catlist argument1=value1 argument2=value2].
  6. Version: 0.10.1
  7. Author: Fernando Briano
  8. Author URI: http://picandocodigo.net/
  9. */
  10. /* Copyright 2008-2010 Fernando Briano (email : fernando@picandocodigo.net)
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 3 of the License, or
  14. any later version.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software
  21. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. //Sidebar Widget:
  24. include('list_cat_posts_widget.php');
  25. //Shortcode [catlist parameter="value"]
  26. function catlist_func($atts, $content=null) {
  27. $atts=shortcode_atts(array(
  28. 'id' => '0',
  29. 'name' => 'default',
  30. 'orderby' => 'date',
  31. 'order' => 'desc',
  32. 'numberposts' => '5',
  33. 'date' => 'no',
  34. 'author' => 'no',
  35. 'dateformat' => get_option('date_format'),
  36. 'template' => 'default',
  37. 'excerpt' => 'no',
  38. 'exclude' => '0',
  39. 'excludeposts' => '0',
  40. 'offset' => '0',
  41. 'tags' => '',
  42. 'content' => 'no',
  43. 'catlink' => 'no'
  44. ), $atts);
  45. return list_category_posts($atts);
  46. }
  47. add_shortcode('catlist', 'catlist_func');
  48. function list_category_posts($atts){
  49. if($atts['name']!='default' && $atts['id']=='0'){
  50. $category = 'category_name=' . $atts['name'];
  51. $category_id = get_cat_ID($atts['name']);
  52. }else{
  53. $category = 'cat=' . $atts['id'];
  54. $category_id = $atts['id'];
  55. }
  56. //Link to the category:
  57. $cat_link_string = '';
  58. if ($atts['catlink'] == 'yes'){
  59. $cat_link = get_category_link($category_id);
  60. $cat_data = get_category($atts['id']);
  61. $cat_title = $cat_data->name;
  62. $cat_link_string = '<a href=' . $cat_link . ' title="' . $cat_title . '">' . $cat_title . '</a>';
  63. }
  64. //Build the query for get_posts()
  65. $catposts = get_posts($category.'&numberposts=' . $atts['numberposts'] .
  66. '&orderby=' . $atts['orderby'] .
  67. '&order=' . $atts['order'] .
  68. '&exclude=' . $atts['excludeposts'] .
  69. '&tag=' . $atts['tags'] .
  70. '&offset=' . $atts['offset'] );
  71. //Template code:
  72. $tplFileName = null;
  73. $possibleTemplates = array(
  74. // File locations lower in list override others
  75. dirname(__FILE__).'/templates/'.$atts['template'].'.php',
  76. STYLESHEETPATH.'/list-category-posts/'.$atts['template'].'.php',
  77. );
  78. foreach($possibleTemplates as $key => $file) {
  79. if (is_readable($file)) {
  80. $tplFileName = $file;
  81. }
  82. }
  83. if ((!empty($tplFileName)) && (is_readable($tplFileName))) {
  84. require($tplFileName);
  85. }else{
  86. if ($cat_link_string != ''){
  87. $output = '<p><strong>' . $cat_link_string . '</strong></p>';
  88. }else{
  89. $output = '';
  90. }
  91. $output .= '<ul class="lcp_catlist">';//For default ul
  92. foreach($catposts as $single):
  93. $output .= '<li><a href="' . get_permalink($single->ID).'">' . $single->post_title . '</a>';
  94. if($atts['date']=='yes'){
  95. $output .= ' - ' . get_the_time($atts['dateformat'], $single);//by Verex, great idea!
  96. }
  97. if($atts['author']=='yes'){
  98. $lcp_userdata = get_userdata($single->post_author);
  99. $output.=" - ".$lcp_userdata->display_name . '<br/>';
  100. }
  101. if($atts['content']=='yes' && $single->post_content){
  102. $lcpcontent = apply_filters('the_content', $single->post_content); // added to parse shortcodes
  103. $lcpcontent = str_replace(']]>', ']]&gt', $lcpcontent); // added to parse shortcodes
  104. $output.= '<p>' . $lcpcontent . '</p>'; // line tweaked to output filtered content
  105. }
  106. if($atts['excerpt']=='yes' && $single->post_excerpt && !($atts['content']=='yes' && $single->post_content) ){
  107. $output .= "<p>$single->post_excerpt</p>";
  108. }
  109. $output.="</li>";
  110. endforeach;
  111. $output .= "</ul>";
  112. }
  113. return $output;
  114. }
  115. function lcp_add_option_page(){
  116. add_options_page('List Category Posts', 'List Category Posts', 'manage_options','list-category-posts/list_cat_posts_options.php');
  117. }
  118. /** TODO
  119. * -Add auto excerpt
  120. * -Images (preview or thumbnail, whatever, I have to dig into this
  121. */
  122. ?>