Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mycustom_popular_blog_posts($atts, $content = null) {
- extract(shortcode_atts(array(
- "number_of_posts" => '5'
- ), $atts));
- ob_start();
- ?><div class="shortcode-popular-posts">
- <div class="shortcode-popular-posts-title">
- <span id="tab-news-1-title" class="tab-news-content-title current"><?php _e('Most Liked', 'mycustom-shortcodes'); ?></span>
- <span id="tab-news-2-title" class="tab-news-content-title"><?php _e('Commented', 'mycustom-shortcodes'); ?></span>
- <span id="tab-news-3-title" class="tab-news-content-title"><?php _e('Featured', 'mycustom-shortcodes'); ?></span>
- <span id="tab-news-4-title" class="tab-news-content-title"><?php _e('Events', 'mycustom-shortcodes'); ?></span>
- <div class="shortcode-popular-posts-menu"><?php _e('Change', 'mycustom-shortcodes'); ?></div>
- <div class="shortcode-popular-posts-menu-drop-down">
- <span data-tab="tab-news-1" data-tab-title="tab-news-1-title" class="current"><?php _e('Most Liked', 'mycustom-shortcodes'); ?></span>
- <span data-tab="tab-news-2" data-tab-title="tab-news-2-title"><?php _e('Most commented', 'mycustom-shortcodes'); ?></span>
- <span data-tab="tab-news-3" data-tab-title="tab-news-3-title"><?php _e('Featured', 'mycustom-shortcodes'); ?></span>
- <span data-tab="tab-news-4" data-tab-title="tab-news-4-title"><?php _e('Events', 'mycustom-shortcodes'); ?></span>
- </div>
- </div>
- <ul id="tab-news-1" class="tab-news-content current">
- <?php
- $counter_1 = null;
- $row = null;
- $wp_query = null;
- $temp = $wp_query;
- $wp_query = new WP_Query();
- $wp_query->query('orderby=meta_value_num&meta_key=_liked&posts_per_page=' . $number_of_posts . ''.'&paged=null');
- while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
- <li>
- <div class="shortcode-popular-posts-counter"><?php echo(++$counter_1 . $row['foo']); ?>.</div>
- <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>
- <div class="shortcode-popular-posts-details"><?php the_category(', ') ?>
- <span class="shortcode-popular-posts-time"><?php the_time('l, M j'); ?> </span>
- <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>
- </div>
- </li>
- <?php
- endwhile;
- wp_reset_query();
- ?>
- </ul>
- <ul id="tab-news-2" class="tab-news-content">
- <?php
- $counter_2 = null;
- $wp_query = null;
- $temp = $wp_query;
- $wp_query = new WP_Query();
- $wp_query->query('orderby=comment_count&posts_per_page=' . $number_of_posts . ''.'&paged=null');
- while ($wp_query->have_posts()) : $wp_query->the_post();
- ?>
- <li>
- <div class="shortcode-popular-posts-counter"><?php echo(++$counter_2 . $row['foo']); ?>.</div>
- <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>
- <div class="shortcode-popular-posts-details"><?php the_category(', ') ?><span class="shortcode-popular-posts-time"><?php the_time('l, M j'); ?></span></div>
- </li>
- <?php
- endwhile;
- wp_reset_query();
- ?>
- </ul>
- <ul id="tab-news-3" class="tab-news-content">
- <?php
- $counter_3 = null;
- $wp_query = null;
- $temp = $wp_query;
- $wp_query = new WP_Query();
- $wp_query->query('tag=Featured&orderby=comment_count&posts_per_page=' . $number_of_posts . ''.'&paged=null');
- while ($wp_query->have_posts()) : $wp_query->the_post();
- ?>
- <li>
- <div class="shortcode-popular-posts-counter"><?php echo(++$counter_3 . $row['foo']); ?>.</div>
- <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>
- <div class="shortcode-popular-posts-details"><?php the_category(', ') ?><span class="shortcode-popular-posts-time"><?php the_time('l, M j'); ?></span></div>
- </li>
- <?php
- endwhile;
- wp_reset_query();
- ?>
- </ul>
- <ul id="tab-news-4" class="tab-news-content">
- <?php
- $counter_4 = null;
- $wp_query = null;
- $temp = $wp_query;
- $wp_query = new WP_Query();
- $wp_query->query('tag=Events&orderby=comment_count&posts_per_page=' . $number_of_posts . ''.'&paged=null');
- while ($wp_query->have_posts()) : $wp_query->the_post();
- ?>
- <li>
- <div class="shortcode-popular-posts-counter"><?php echo(++$counter_4 . $row['foo']); ?>.</div>
- <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>
- <div class="shortcode-popular-posts-details"><?php the_category(', ') ?><span class="shortcode-popular-posts-time"><?php the_time('l, M j'); ?></span></div>
- </li>
- <?php
- endwhile;
- wp_reset_query();
- ?>
- </ul>
- </div><!-- shortcode-popular-posts -->
- <?php
- $shortcode_content = ob_get_clean();
- return $shortcode_content;
- }
- add_shortcode("mycustom-popular-blog-posts", "mycustom_popular_blog_posts");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement