Advertisement
Guest User

Category Thumbnails

a guest
Dec 2nd, 2012
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Category Thumbnail List
  4. Plugin URI: http://jonk.pirateboy.net/blog/category/bloggeriet/wordpress/plugins/
  5. Description: Creates a list of thumbnail images, using the_post_thumbnail() in WordPress 2.9 and up.
  6. Version: 1.1
  7. Author: Jonk
  8. Author URI: http://jonk.pirateboy.net
  9. */
  10.  
  11.  
  12. $categoryThumbnailList_Order = stripslashes( get_option( 'category-thumbnail-list_order' ) );
  13. if ($categoryThumbnailList_Order == '') {
  14. $categoryThumbnailList_Order = 'date';
  15. }
  16. $categoryThumbnailList_OrderType = stripslashes( get_option( 'category-thumbnail-list_ordertype' ) );
  17. if ($categoryThumbnailList_OrderType == '') {
  18. $categoryThumbnailList_OrderType = 'DESC';
  19. }
  20.  
  21. $categoryThumbnailList_Path = get_option('siteurl')."/wp-content/plugins/categoy-thumbnail-list/";
  22.  
  23. define("categoryThumbnailList_REGEXP", "/\[categorythumbnaillist ([[:print:]]+)\]/");
  24.  
  25. define("categoryThumbnailList_TARGET", "###CATTHMBLST###");
  26.  
  27.  
  28. function categoryThumbnailList_callback($listCatId) {
  29. global $post;
  30. global $categoryThumbnailList_Order;
  31. global $categoryThumbnailList_OrderType;
  32. $tmp_post = $post;
  33.  
  34.  
  35. $args=array(
  36. 'showposts'=> 5,
  37. 'category'=> $listCatId[1],
  38. 'orderby'=> $categoryThumbnailList_OrderType,
  39. 'order'=> $categoryThumbnailList_Order
  40. );
  41.  
  42.  
  43.  
  44. $myposts = get_posts( $args);
  45.  
  46. $output = '<div class="categoryThumbnailList">';
  47. foreach($myposts as $post) :
  48. setup_postdata($post);
  49. if ( has_post_thumbnail() ) {
  50. $link = get_permalink($post->ID);
  51. $thmb = get_the_post_thumbnail($post->ID,'thumbnail');
  52. $url = get_post_meta( $post->ID, 'ExternalURL', true );
  53. $title = get_the_title();
  54. $excerpt = substr(get_the_excerpt(), 0,275);
  55. $date = get_the_date();
  56. $comments = get_the_date();
  57. $output .= '<div class="categoryThumbnailList_item">';
  58.  
  59. if ( $url ) {
  60. $output .= '<a href="'. esc_url_raw($url) . '" title="' .$title . '" target="_blank"><div id="newsthumb">' .$thmb . '</div></a><br/>';
  61. $output .= '<div class="tntitle"><a href="'. esc_url_raw($url) . '" title="' .$title . '" target="_blank">' .$title . '</a></div>';
  62.  
  63. $output .= '<div class="tndate">' .$date . '</div>';
  64.  
  65. $output .= '<div class="tnexcerpt">' .$excerpt . '...</div>';
  66.  
  67. $output .= '<div class="tncomments"><a href="'. esc_url_raw($url) . '" title="' .$title . '" target="_blank">0 Comments and 0 Reactions</a></div>';
  68.  
  69. $output .= '</div>';
  70.  
  71.  
  72. }
  73.  
  74. else {
  75. $output .= '<a href="'. $link. '" title="' .$title . '"><div id="newsthumb">' .$thmb . '</div></a><br/>';
  76.  
  77. $output .= '<div class="tntitle"><a href="'. $link . '" title="' .$title . '">' .$title . '</a></div>';
  78.  
  79. $output .= '<div class="tndate">' .$date . '</div>';
  80.  
  81. $output .= '<div class="tnexcerpt">' .$excerpt . '...</div>';
  82.  
  83. $output .= '<div class="tncomments"><a href="'. $link . '#disqus_thread" title="' .$title . '">' .$title . '</a></div>';
  84.  
  85. $output .= '</div>';
  86.  
  87. }
  88.  
  89. }
  90. endforeach;
  91. /*
  92. $output .= '</div>';
  93. $output .= '<div class="categoryThumbnailList_clearer"></div>';
  94. return ($output);
  95. $output = '';
  96. $post = $tmp_post;
  97. setup_postdata($post);
  98. */
  99. $output .= '</div>';
  100. $output .= '<div class="categoryThumbnailList_clearer"></div>';
  101. $post = $tmp_post;
  102. wp_reset_postdata();
  103. return ($output);
  104. $output = '';
  105. }
  106.  
  107. function categoryThumbnailList($content) {
  108. return (preg_replace_callback(categoryThumbnailList_REGEXP, 'categoryThumbnailList_callback', $content));
  109. }
  110.  
  111. function categoryThumbnailList_css() {
  112. global $categoryThumbnailList_Path;
  113. echo "
  114. <style type=\"text/css\">
  115. @import url(\"".$categoryThumbnailList_Path."categoy-thumbnail-list.css\");
  116. </style>
  117. ";
  118. }
  119. add_action('wp_head', 'categoryThumbnailList_css');
  120. add_filter('the_content', 'categoryThumbnailList',1);
  121. ?>
  122. <?php
  123. add_action('admin_menu', 'my_plugin_menu');
  124.  
  125. function my_plugin_menu() {
  126. add_options_page('Category Thumbnail List Options', 'Category Thumbnail List', 'manage_options', 'category-thumbnail-list', 'my_plugin_options');
  127. }
  128.  
  129. function my_plugin_options() {
  130. global $categoryThumbnailList_Order;
  131. global $categoryThumbnailList_OrderType;
  132.  
  133. if( $_POST['save_category-thumbnail-list_settings'] ) {
  134. // update order type
  135. if( !$_POST['category-thumbnail-list_ordertype'] )
  136. {
  137. $_POST['category-thumbnail-list_ordertype'] = 'date';
  138. }
  139. update_option('category-thumbnail-list_ordertype', $_POST['category-thumbnail-list_ordertype'] );
  140.  
  141. // update order
  142. if( !$_POST['category-thumbnail-list_order'] )
  143. {
  144. $_POST['category-thumbnail-list_order'] = 'DESC';
  145. }
  146. update_option('category-thumbnail-list_order', $_POST['category-thumbnail-list_order'] );
  147.  
  148. $categoryThumbnailList_Order = stripslashes( get_option( 'category-thumbnail-list_order' ) );
  149. $categoryThumbnailList_OrderType = stripslashes( get_option( 'category-thumbnail-list_ordertype' ) );
  150.  
  151. echo "<div id=\"message\" class=\"updated fade\"><p>Your settings are now updated</p></div>\n";
  152.  
  153. }
  154. ?>
  155. <div class="wrap">
  156. <h2>Category Thumbnail List Settings</h2>
  157. <form method="post">
  158. <table class="form-table">
  159. <tr valign="top">
  160. <th scope="row">Order by</th>
  161. <td>
  162. <select name="category-thumbnail-list_ordertype" id="category-thumbnail-list_ordertype">
  163. <option <?php if ($categoryThumbnailList_OrderType == 'date') { echo 'selected="selected"'; } ?> value="date">Date</option>
  164. <option <?php if ($categoryThumbnailList_OrderType == 'title') { echo 'selected="selected"'; } ?> value="title">Title</option>
  165. </select>
  166. </td>
  167. </tr>
  168. <tr valign="top">
  169. <th scope="row">Display order</th>
  170. <td>
  171. <select name="category-thumbnail-list_order" id="category-thumbnail-list_order">
  172. <option <?php if ($categoryThumbnailList_Order == 'DESC') { echo 'selected="selected"'; } ?> value="DESC">Descending (z-a/9-1/2010-2001)</option>
  173. <option <?php if ($categoryThumbnailList_Order == 'ASC') { echo 'selected="selected"'; } ?> value="ASC">Ascending (a-z/1-9/2001-2010)</option>
  174. </select>
  175. </td>
  176. </tr>
  177. </table>
  178.  
  179. <div class="submit">
  180. <!--<input type="submit" name="reset_category-thumbnail-list_settings" value="<?php _e('Reset') ?>" />-->
  181. <input type="submit" name="save_category-thumbnail-list_settings" value="<?php _e('Save Settings') ?>" class="button-primary" />
  182. </div>
  183. <div>
  184. <a href="options-media.php">Update the thumbnail sizes here</a>
  185. </div>
  186. <div>
  187. <a href="plugin-editor.php?file=categoy-thumbnail-list/categoy-thumbnail-list.css&plugin=categoy-thumbnail-list/categoy-thumbnail-list.php">You may need to update your css when changing the thumbnail size</a>
  188. </div>
  189.  
  190. </form>
  191. </div>
  192. <?php
  193. }
  194. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement