Posted By

miziomon on 11/20/06


Tagged

plugin wordpress


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


EzSticky


 / Published in: PHP
 

Show post_excerpt where categoty is sticky

  1. <?php
  2. /*
  3. Plugin Name: EzSticky
  4. Plugin URI: http://maurizio.mavida.com/ezsticky
  5. Description: Show post_excerpt of specified categoty, sticky is default. Usage: put the function ezsticky() anywhere in the template.
  6.  
  7. Version: 0.2
  8. Author: maurizio
  9. Author URI: http://maurizio.mavida.com
  10.  
  11. */
  12.  
  13. /*
  14. License: GPL
  15.  
  16. Installation:
  17. Place the ezsticky.php file in your /wp-content/plugins/ directory
  18. and activate through the administration panel.
  19. */
  20.  
  21. /*
  22.  
  23. This program is free software; you can redistribute it and/or modify
  24. it under the terms of the GNU General Public License as published by
  25. the Free Software Foundation; either version 2 of the License, or
  26. (at your option) any later version.
  27.  
  28. This program is distributed in the hope that it will be useful,
  29. but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. GNU General Public License for more details.
  32.  
  33. You should have received a copy of the GNU General Public License
  34. along with this program; if not, write to the Free Software
  35. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  36. */
  37.  
  38.  
  39. /* Changelog
  40. * 2006-11-21 - v0.2
  41. - add sticky_cat param for change category filter selection
  42. - add $wpdb before table name
  43. - add some comments
  44. * 2006-11-20 - v0.1
  45. - Initial release
  46. */
  47.  
  48. function ezsticky ($sticky_cat = 'sticky', $before_title = '<h3>', $after_title = '</h3>', $before_post = '<div>', $after_post = '</div>' ) {
  49.  
  50. global $wpdb, $tableposts;
  51.  
  52. $sql = '';
  53. $sql .= "SELECT ID, post_title, post_content, post_excerpt, category_id, cat_name ";
  54. $sql .= "FROM $wpdb->posts ";
  55. $sql .= "INNER JOIN $wpdb->post2cat ON $wpdb->posts.id = $wpdb->post2cat.post_id ";
  56. $sql .= "INNER JOIN $wpdb->categories ON $wpdb->post2cat.category_id = $wpdb->categories.cat_id ";
  57. $sql .= "WHERE post_status = 'publish' and cat_name = '$sticky_cat' ";
  58. $sql .= "ORDER BY post_date ";
  59.  
  60. $posts = $wpdb->get_results($sql);
  61. $output = '';
  62. foreach ($posts as $post) {
  63. $post_title = stripslashes($post->post_title);
  64. $post_title = str_replace('"', '', $post_title);
  65. //$post_title = substr($post_title, 0, 25);
  66. $permalink = get_permalink($post->ID);
  67. $post_content = strip_tags($post->post_content);
  68. $post_content = stripslashes($post_content);
  69.  
  70. $post_excerpt = stripslashes($post->post_excerpt);
  71.  
  72.  
  73. $output .= '<div class="ezsticky">';
  74. $output .= $before_title;
  75. $output .= '<a href="' . $permalink . '" rel="bookmark" title="' . $post_title . '">' . $post_title . '</a>';
  76. $output .= $after_title;
  77.  
  78. $output .= $before_post;
  79. $output .= $post_excerpt ;
  80. $output .= ' ( <a href="' . $permalink . '" rel="bookmark" title="' . $post_title . '">Continua ...</a> )';
  81. $output .= $after_post;
  82. $output .= '</div>';
  83. }
  84.  
  85. echo $output;
  86. }
  87. ?>

Report this snippet  

You need to login to post a comment.