Advertisement
Guest User

The shortcode

a guest
Apr 1st, 2013
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.93 KB | None | 0 0
  1. <?php
  2.  
  3. add_shortcode('myplugin','myplugin_shortcode');
  4. /*   [myplugin category="0" order="ASC" orderby="date" post_not_in="233" limit="4"]
  5.  
  6.  * - category (default = all)
  7.  * - limit (default = all)
  8.  * - showimage (default = true)
  9.  * - imgwidth (default = 300)
  10.  * - tags (default = none)
  11.  * - sticky (default = false)
  12.  * - filter: latest, random, [popular] (default = latest)
  13.  *
  14.  * - order: (default = date)
  15.  * - orderby: (default = DESC)
  16.  */
  17. function myplugin_shortcode($atts,$data = '')
  18. {
  19.     echo '<link rel="Stylesheet" type="text/css" href="'.plugin_dir_url(__FILE__).'style.css">';
  20.     global $wpdb;
  21.      $limit = $atts['limit'] ? $atts['limit'] : 0;
  22.         $imgWidth = $atts['imgwidth'] ? $atts['imgwidth'] : "80";
  23.         $showImg = $atts['showimage'] == 'false' ? false : true;
  24.         $columns = isset($atts['columns']) ? $atts['columns'] : '4';
  25.         $args = array(
  26.                 'cat' => $atts['category'],
  27.                 'category_name' => $atts['slug'],
  28.                 'tag' => $atts['tags'],
  29.                 'post_type' => 'post',
  30.                 'posts_per_page' => (isset($atts['limit']) ? $atts['limit'] : 6),
  31.         'order' => $atts['order'],
  32.         'orderby' => $atts['orderby']
  33.         );
  34.         $wp_q = new WP_Query($args);
  35.         $ResponsiveCounter = 1;
  36.         while($wp_q->have_posts())
  37.         {
  38.         $wp_q->the_post();
  39.                 $post_class = '';
  40.                 if($ResponsiveCounter == 1)
  41.                         $post_class .= ' left-fit';
  42.                 if($columns == '4')
  43.                         $post_class .= ' grid col-220';
  44.                 else if($columns == '3')
  45.                         $post_class .= ' grid col-300';
  46.                 else if($columns == '2')
  47.                         $post_class .= ' grid col-460';
  48.                 if(($columns == '2' && $ResponsiveCounter == 2) || ($columns == '3' && $ResponsiveCounter == 3) || ($columns == '4' && $ResponsiveCounter == 4)){
  49.                         $post_class .= ' fit';
  50.                         $ResponsiveCounter = 0;
  51.                 }
  52.                 echo '<div class="'.$post_class.'">';
  53.         $id = $wp_q->post->ID;
  54.                 $myimage_html = '';
  55.                 if($atts['hidetext'] == 'true')
  56.                         echo '<li><a href="'.get_permalink($wp_q->post->ID).'">'.$wp_q->post->post_title.'</a></li>';
  57.                 else
  58.                         echo '<div id="nw_post_'.$id.'" class="plnaslov"><a href="'.get_permalink($wp_q->post->ID).'"><h4>'.$wp_q->post->post_title.'</h4></a></div>';
  59.                 if($showImg)
  60.                         $myimage_html = my_get_first_image($id);
  61.                
  62.                 echo '<div class="plcontent">';
  63.                 if($myimage_html != '')
  64.                         $myimage_html .= '<br>';
  65.                 echo $myimage_html.get_the_excerpt();
  66.                 echo '</div>';
  67.                 echo '</div>';
  68.                 $ResponsiveCounter++;
  69.         }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement