Advertisement
Guest User

Untitled

a guest
Apr 28th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.35 KB | None | 0 0
  1. function mycustom_popular_blog_posts($atts, $content = null) {
  2.     extract(shortcode_atts(array(
  3.         "number_of_posts" => '5'
  4.     ), $atts));
  5. ob_start();
  6. ?><div class="shortcode-popular-posts">
  7.  
  8. <div class="shortcode-popular-posts-title">
  9.     <span id="tab-news-1-title" class="tab-news-content-title current"><?php _e('Most Liked', 'mycustom-shortcodes'); ?></span>
  10.     <span id="tab-news-2-title" class="tab-news-content-title"><?php _e('Commented', 'mycustom-shortcodes'); ?></span>
  11.     <span id="tab-news-3-title" class="tab-news-content-title"><?php _e('Featured', 'mycustom-shortcodes'); ?></span>
  12.     <span id="tab-news-4-title" class="tab-news-content-title"><?php _e('Events', 'mycustom-shortcodes'); ?></span>
  13.  
  14.  <div class="shortcode-popular-posts-menu"><?php _e('Change', 'mycustom-shortcodes'); ?></div>
  15.  <div class="shortcode-popular-posts-menu-drop-down">
  16.     <span data-tab="tab-news-1" data-tab-title="tab-news-1-title" class="current"><?php _e('Most Liked', 'mycustom-shortcodes'); ?></span> 
  17.     <span data-tab="tab-news-2" data-tab-title="tab-news-2-title"><?php _e('Most commented', 'mycustom-shortcodes'); ?></span>
  18.     <span data-tab="tab-news-3" data-tab-title="tab-news-3-title"><?php _e('Featured', 'mycustom-shortcodes'); ?></span>
  19.     <span data-tab="tab-news-4" data-tab-title="tab-news-4-title"><?php _e('Events', 'mycustom-shortcodes'); ?></span> 
  20.  </div>
  21. </div>
  22.  
  23.  
  24. <ul id="tab-news-1" class="tab-news-content current">
  25. <?php
  26. $counter_1 = null;
  27. $row = null;
  28. $wp_query = null;
  29. $temp = $wp_query;
  30. $wp_query = new WP_Query();
  31. $wp_query->query('orderby=meta_value_num&meta_key=_liked&posts_per_page=' . $number_of_posts . ''.'&paged=null');
  32. while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
  33.  
  34.     <li>
  35.         <div class="shortcode-popular-posts-counter"><?php echo(++$counter_1 . $row['foo']); ?>.</div>
  36.         <div class="shortcode-popular-post-title"><a href="<?php the_permalink(); ?>"><?php $thetitle = get_the_title(); $getlength = strlen($thetitle); $thelength = 57; echo mb_substr($thetitle, 0, $thelength, 'UTF-8'); if ($getlength > $thelength) echo "..."; ?></a></div>
  37.         <div class="shortcode-popular-posts-details"><?php the_category(', ') ?>
  38.         <span class="shortcode-popular-posts-time"><?php the_time('l, M j'); ?> </span>
  39.         <span class="shortcode-popular-posts-likes"><?php if (function_exists('wp_ulike_get_post_likes')): echo wp_ulike_get_post_likes(get_the_ID()); endif; ?> <?php _e('Likes', 'mycustom-shortcodes'); ?></span>
  40.     </div>
  41.     </li>
  42.  
  43. <?php
  44. endwhile;
  45. wp_reset_query();
  46. ?>
  47. </ul>
  48.  
  49. <ul id="tab-news-2" class="tab-news-content">
  50. <?php
  51. $counter_2 = null;
  52. $wp_query = null;
  53. $temp = $wp_query;
  54. $wp_query = new WP_Query();
  55. $wp_query->query('orderby=comment_count&posts_per_page=' . $number_of_posts . ''.'&paged=null');
  56. while ($wp_query->have_posts()) : $wp_query->the_post();
  57. ?>
  58.  
  59.     <li>
  60.         <div class="shortcode-popular-posts-counter"><?php echo(++$counter_2 . $row['foo']); ?>.</div>
  61.         <div class="shortcode-popular-post-title"><a href="<?php the_permalink(); ?>"><?php $thetitle = get_the_title(); $getlength = strlen($thetitle); $thelength = 57; echo mb_substr($thetitle, 0, $thelength, 'UTF-8'); if ($getlength > $thelength) echo "..."; ?></a></div>
  62.         <div class="shortcode-popular-posts-details"><?php the_category(', ') ?><span class="shortcode-popular-posts-time"><?php the_time('l, M j'); ?></span></div>
  63.     </li>
  64.  
  65. <?php
  66. endwhile;
  67. wp_reset_query();
  68. ?>
  69. </ul>
  70.  
  71.  
  72. <ul id="tab-news-3" class="tab-news-content">
  73. <?php
  74. $counter_3 = null;
  75. $wp_query = null;
  76. $temp = $wp_query;
  77. $wp_query = new WP_Query();
  78. $wp_query->query('tag=Featured&orderby=comment_count&posts_per_page=' . $number_of_posts . ''.'&paged=null');
  79. while ($wp_query->have_posts()) : $wp_query->the_post();
  80. ?>
  81.  
  82.     <li>
  83.         <div class="shortcode-popular-posts-counter"><?php echo(++$counter_3 . $row['foo']); ?>.</div>
  84.         <div class="shortcode-popular-post-title"><a href="<?php the_permalink(); ?>"><?php $thetitle = get_the_title(); $getlength = strlen($thetitle); $thelength = 57; echo mb_substr($thetitle, 0, $thelength, 'UTF-8'); if ($getlength > $thelength) echo "..."; ?></a></div>
  85.         <div class="shortcode-popular-posts-details"><?php the_category(', ') ?><span class="shortcode-popular-posts-time"><?php the_time('l, M j'); ?></span></div>
  86.     </li>
  87.  
  88. <?php
  89. endwhile;
  90. wp_reset_query();
  91. ?>
  92. </ul>
  93.  
  94.  
  95. <ul id="tab-news-4" class="tab-news-content">
  96. <?php
  97. $counter_4 = null;
  98. $wp_query = null;
  99. $temp = $wp_query;
  100. $wp_query = new WP_Query();
  101. $wp_query->query('tag=Events&orderby=comment_count&posts_per_page=' . $number_of_posts . ''.'&paged=null');
  102. while ($wp_query->have_posts()) : $wp_query->the_post();
  103. ?>
  104.  
  105.     <li>
  106.         <div class="shortcode-popular-posts-counter"><?php echo(++$counter_4 . $row['foo']); ?>.</div>
  107.         <div class="shortcode-popular-post-title"><a href="<?php the_permalink(); ?>"><?php $thetitle = get_the_title(); $getlength = strlen($thetitle); $thelength = 57; echo mb_substr($thetitle, 0, $thelength, 'UTF-8'); if ($getlength > $thelength) echo "..."; ?></a></div>
  108.         <div class="shortcode-popular-posts-details"><?php the_category(', ') ?><span class="shortcode-popular-posts-time"><?php the_time('l, M j'); ?></span></div>
  109.     </li>
  110.  
  111. <?php
  112. endwhile;
  113. wp_reset_query();
  114. ?>
  115. </ul>
  116.  
  117. </div><!-- shortcode-popular-posts -->
  118. <?php
  119. $shortcode_content = ob_get_clean();
  120. return $shortcode_content;
  121.  
  122. }
  123. add_shortcode("mycustom-popular-blog-posts", "mycustom_popular_blog_posts");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement