rawky

/widgets/recent.php

Jun 9th, 2011
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. <?
  2.  
  3. //Eliminar en modo de producción
  4. ini_set('display_errors','1');
  5. ini_set('display_startup_errors','1');
  6. error_reporting(E_ALL ^ E_NOTICE);
  7.  
  8. function ts_widget_recent_init() {
  9.  
  10. if (!function_exists('register_sidebar_widget'))
  11. return;
  12.  
  13. function ts_recent_widget($args) {
  14.  
  15. global $wpdb;
  16.  
  17. extract($args);
  18.  
  19. $options = get_option('ts_widget_recent');
  20. if (!is_array($options))
  21. $options = array('title' => 'Recent Posts',
  22. 'maxposts' => 3);
  23.  
  24. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  25. $maxposts = $options['maxposts'];
  26.  
  27. echo $before_widget . $before_title . $title . $after_title;
  28.  
  29. //$all = new WP_Query('category_name=-portfolio');
  30. ?>
  31. <div id="recentposts-list">
  32. <?
  33. ts_recent_request($maxposts);
  34. ?>
  35. </div>
  36. <?
  37. echo $after_widget;
  38.  
  39. }
  40.  
  41. function ts_widget_recent_control() {
  42.  
  43. $options = get_option('ts_widget_recent');
  44. if (!is_array($options))
  45. //Default values
  46. $options = array('title' => 'Recent Posts',
  47. 'maxposts' => 3);
  48.  
  49. if ($_POST['ts_recent_submit']) {
  50. $options['title'] = strip_tags(stripslashes($_POST['ts_recent_title']));
  51. $options['maxposts'] = strip_tags(stripslashes($_POST['ts_recent_maxposts']));
  52.  
  53. update_option('ts_widget_recent', $options);
  54. }
  55.  
  56. $title = htmlspecialchars($options['title'], ENT_QUOTES);
  57. $maxposts = htmlspecialchars($options['maxposts'], ENT_QUOTES);
  58.  
  59. ?>
  60.  
  61. <p>
  62.  
  63. <h3>&raquo; General Options:</h3><hr style="border: 1px Dotted" /><br />
  64.  
  65. <label for="ts_recent_title">
  66. Title:
  67. <input style="width: 200px;" id="ts_recent_title" name="ts_recent_title" type="text" value="<? echo $title; ?>" />
  68. </label><br /><br />
  69.  
  70. <label for="ts_recent_maxposts">
  71. Show
  72. <input style="width: 20px;" id="ts_recent_maxposts" name="ts_recent_maxposts" type="text" value="<? echo $maxposts; ?>" />
  73. posts
  74. </label><br /><br />
  75.  
  76. </p>
  77.  
  78. <?
  79.  
  80. echo '<input type="hidden" id="ts_recent_submit" name="ts_recent_submit" value="1" />';
  81.  
  82. }
  83.  
  84. function ts_recent_request($maxposts = 3, $offset = 0) {
  85.  
  86. echo '<ul class="widgetpostlist">';
  87.  
  88. $query = new WP_Query('cat=-45&showposts=' . $maxposts);
  89. while ($query->have_posts()) : $query->the_post(); ?>
  90.  
  91. <li class="widgetpost">
  92.  
  93. <a href="<? the_permalink(); ?>"><?php the_post_thumbnail(array(67, 67)); ?></a>
  94. <p><a href="<? the_permalink(); ?>"><? the_title(); ?></a><?php echo split_by_words(ts_getoption('ts_miniexcerpt_size'), get_the_excerpt()) . ' &raquo;'; ?></p>
  95. <div class="clearer"></div>
  96.  
  97. </li>
  98. <?
  99. endwhile;
  100. echo '<div class="clearer"></div></ul>';
  101. }
  102.  
  103. wp_register_sidebar_widget('ts_recent', '[Magzimus] Recent Posts', 'ts_recent_widget');
  104. register_widget_control('ts_recent', 'ts_widget_recent_control', 360, 100);
  105.  
  106. }
  107.  
  108. ?>
Advertisement
Add Comment
Please, Sign In to add comment