Advertisement
Guest User

Untitled

a guest
Jul 8th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.83 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Featured Image Thumbnail Grid
  4. Plugin URI: http://www.nomadcoder.com/thumbnail-grid-wordpress-plugin/
  5. Description: Display Thumbnail Grid using Featured Images
  6. Version: 2.0
  7. Author: A. R. Jones
  8. Author URI: http://www.nomadcoder.com
  9. */
  10.  
  11. /*
  12. Copyright (C) 2013 Nomad Coder
  13. Contact me at http://www.nomadcoder.com
  14.  
  15. This program is free software: you can redistribute it and/or modify
  16. it under the terms of the GNU General Public License as published by
  17. the Free Software Foundation, either version 3 of the License, or
  18. (at your option) any later version.
  19.  
  20. This program is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. GNU General Public License for more details.
  24.  
  25. You should have received a copy of the GNU General Public License
  26. along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. */
  28. /*
  29. Order By for links
  30. orderby
  31. (string) Value to sort bookmarks on. Defaults to 'name'. Valid options:
  32. 'url'
  33. 'name' - Default
  34. 'owner' - User who added bookmark through bookmarks Manager.
  35. 'rating'
  36. 'visible'
  37. 'length' - The length of the bookmark name, shortest to longest.
  38. 'rand' - Display bookmarks in random order.
  39. Order By for Posts
  40. 'none' - No order (available with Version 2.8).
  41. 'ID' - Order by post id. Note the captialization.
  42. 'author' - Order by author.
  43. 'title' - Order by title.
  44. 'name' - Order by post name (post slug).
  45. 'date' - Order by date.
  46. 'modified' - Order by last modified date.
  47. 'parent' - Order by post/page parent id.
  48. 'rand' - Random order.
  49. 'comment_count' - Order by number of comments (available with Version 2.9).
  50. 'menu_order' - Order by Page Order. Used most often for Pages (Order field in the Edit Page Attributes box) and for Attachments (the integer fields in the Insert / Upload Media Gallery dialog), but could be used for any post type with distinct 'menu_order' values (they all default to 0).
  51. 'meta_value' - Note that a 'meta_key=keyname' must also be present in the query. Note also that the sorting will be alphabetical which is fine for strings (i.e. words), but can be unexpected for numbers (e.g. 1, 3, 34, 4, 56, 6, etc, rather than 1, 3, 4, 6, 34, 56 as you might naturally expect). Use 'meta_value_num' instead for numeric values.
  52. 'meta_value_num' - Order by numeric meta value (available with Version 2.8). Also note that a 'meta_key=keyname' must also be present in the query. This value allows for numerical sorting as noted above in 'meta_value'.
  53. 'post__in' - Preserve post ID order given in the post__in array (available with Version 3.5).
  54. */
  55. add_shortcode("thumbnailgrid", "thumbnailgrid_handler");
  56. add_shortcode("bkthumbnailgrid", "bkthumbnailgrid_handler");
  57.  
  58. add_filter('query_vars', 'tbpage_vars');
  59.  
  60. function tbpage_vars($qvars)
  61. {
  62.     $qvars[] = 'tg_page';
  63.     return $qvars;
  64. }
  65.      /**
  66.      * Handler for Shortcode.
  67.      * $atts = array of options
  68.      *
  69.      */
  70. function bkthumbnailgrid_handler($atts) {
  71.     //Include Stylesheet
  72.      wp_enqueue_style('thumbnailgrid', plugins_url('css/thumbnailgrid.css', __FILE__));
  73.      $tg = new thumbnailgrid();
  74.     $output = $tg->bkthumbnailgrid_function($atts);
  75.  
  76.     return $output;
  77. }
  78. $output;
  79. function thumbnailgrid_handler($atts) {
  80.     //Include Stylesheet
  81.      wp_enqueue_style('thumbnailgrid', plugins_url('css/thumbnailgrid.css', __FILE__));
  82.      $tg = new thumbnailgrid();
  83.     $output = $tg->thumbnailgrid_function($atts);
  84.  
  85.     return $output;
  86. }
  87.  
  88.      /**
  89.      * Function for Shortcode.
  90.      * $atts = array of options
  91.      *
  92.      */
  93.  
  94. class thumbnailgrid
  95. {
  96.    
  97.  
  98.     function thumbnailgrid_function($atts) {
  99.         wp_reset_query();
  100.         if ($atts)
  101.         {
  102.               extract( shortcode_atts( array(
  103.                 'height' => '',                
  104.                 'width' => ''
  105.             ), $atts ) );
  106.            unset($atts["height"]);
  107.            unset($atts["width"]);
  108.          
  109.            $the_query = new WP_Query($atts);
  110.         }
  111.  
  112.  
  113.         else
  114.         {
  115.             $the_query = new WP_Query('posts_per_page  = -1');
  116.         }
  117.         // The Loop
  118.      
  119.         $ret = '<div class="thumbnailblock"><div class="thumbnailgridcontainer">';
  120.         $style = "";
  121.         if ($height || $width)
  122.         {
  123.             $style = ' style="';
  124.             if ($height)
  125.                 $style .= 'height:' .$height . ';';
  126.            
  127.             if ($width)
  128.                 $style .= 'width:' .$width . ';';
  129.             $style .= '"';
  130.          }
  131.           while ( $the_query->have_posts() ) :$the_query->the_post();
  132.             $titlelength = 20;
  133.             $permalink = get_permalink();
  134.             $title = get_the_title();
  135.             //$thumbnail = get_the_post_thumbnail();
  136.             $image_id = get_post_thumbnail_id();
  137.             $image_url = wp_get_attachment_image_src($image_id,'thumbnail', true);
  138.             if ($image_id)
  139.                 $thumbnail = '<img src="' .$image_url[0] .'"' .$style . '/>';
  140.             else
  141.                 $thumbnail = '';
  142.             $tt = $title;
  143.             $im = '<div class="postimage"' .$style .'>
  144.                <a href="'. $permalink .'" title="'.$title.'">'. $thumbnail .'</a>
  145.                 </div><!-- .postimage -->';
  146.                
  147.                 $ret .=
  148.                 '<div class="griditemleft"' .$style .'>'
  149.                 . $im ;
  150.  
  151.                 $ret .= '<div class="postimage-title">
  152.                     <a href="'. $permalink .'" title="'. $title .'">'.$tt .'</a>
  153.                 </div>
  154.            </div><!-- .griditemleft -->';
  155.        
  156.          
  157.  
  158.         endwhile;
  159.         wp_reset_postdata();
  160.         $ret .=  '</div></div>';
  161.         return $ret;
  162.     }
  163.  
  164.  
  165.          /**
  166.          * Function for Shortcode.
  167.          * $atts = array of options
  168.          *
  169.          */
  170.     function bkthumbnailgrid_function($atts) {
  171.         if ($atts)
  172.         {
  173.            extract( shortcode_atts( array(
  174.                 'height' => '',                
  175.                 'width' => ''
  176.             ), $atts ) );
  177.            unset($atts["height"]);
  178.            unset($atts["width"]);
  179.          
  180.            $the_query = new WP_Query($atts);
  181.         }
  182.         $style = "";
  183.         if ($height || $width)
  184.         {
  185.             $style = ' style="';
  186.             if ($height)
  187.                 $style .= 'height:' .$height . ';';
  188.            
  189.             if ($width)
  190.                 $style .= 'width:' .$width . ';';
  191.             $style .= '"';
  192.          }
  193.         $titlelength = 20; // Length of the post titles shown below the thumbnails
  194.    
  195.         $bookmarks = get_bookmarks( $atts );
  196.  
  197.     // Loop through each bookmark and print formatted output
  198.         $ret = '';
  199.          $titlelength = 20;
  200.         foreach ( $bookmarks as $bookmark ) {
  201.    
  202.  
  203.        
  204.             $permalink = $bookmark->link_url;
  205.             $title = $bookmark->link_name;
  206.             $target = $bookmark->link_target;
  207.             $thumbnail = $bookmark->link_image;
  208.             if ($target != '')
  209.             {
  210.                 $target = ' target="' .$target .'"';
  211.        
  212.            
  213.             }
  214.            
  215.            if (strlen($title) > $titlelength)
  216.                 $tt = mb_substr($title, 0, $titlelength) . ' ...';
  217.             else
  218.                  $tt = $title;
  219.                 $im = '<div class="postimage"' .$style .'>
  220.                    <a href="'. $permalink .'" title="'.$title.'"'. $target .'><img src="'. $thumbnail .'"' . $style .'/></a>
  221.                 </div><!-- .postimage -->';
  222.                 $ret .=
  223.                 '<div class="griditemleft"' .$style .'>'
  224.                 . $im .
  225.                 '<div class="postimage-title">
  226.                     <a href="'. $permalink .'" title="'. $title .'">'.$tt .'</a>
  227.                 </div>
  228.            </div><!-- .griditemleft -->';
  229.      
  230.        
  231.         }
  232.         wp_reset_postdata();
  233.         return $ret;
  234.     }
  235. }
  236. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement