Created
March 14, 2018 13:41
-
-
Save finalwebsites/3884dbb26f61793059a1f76b684b8196 to your computer and use it in GitHub Desktop.
General functions from the Jupiter theme (snippet)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add a widget to the dashboard. | |
* | |
* This function is hooked into the 'wp_dashboard_setup' action below. | |
*/ | |
function mk_posts_like_stats_widget() { | |
wp_add_dashboard_widget('mk_posts_like_stats', 'Popular Post Stats', 'mk_posts_like_stats_func'); | |
wp_enqueue_style('mk-posts-likes-widget', THEME_ADMIN_ASSETS_URI . '/stylesheet/css/wp-dashboard-styles.css'); | |
} | |
add_action('wp_dashboard_setup', 'mk_posts_like_stats_widget'); | |
/** | |
* Create the function to output the contents of our Dashboard Widget. | |
*/ | |
function mk_posts_like_stats_func() { | |
$args = array( | |
'post_type' => 'post', | |
'posts_per_page' => 5, | |
'order' => 'DESC', | |
'orderby' => 'meta_value_num', | |
'meta_key' => '_mk_post_love', | |
); | |
$query = new WP_Query($args); | |
echo '<p>' . __('Popular Blog & Portfolio posts based on the number of post likes.', 'mk_framework') . '</p>'; | |
echo '<span class="mk-like-post-posttype-title">' . __('Popular Blog Posts', 'mk_framework') . '</span>'; | |
echo '<ol class="mk_posts_like_stats_ol">'; | |
// The Loop | |
while ($query->have_posts()): | |
$query->the_post(); | |
$love_count = get_post_meta(get_the_id() , '_mk_post_love', true); | |
echo '<li>'; | |
echo '<a target="_blank" href="' . esc_url( get_permalink() ) . '" class="mk-like-post-title">' . get_the_title() . '</a>'; | |
echo '<span class="mk-like-post-count"><i class="dashicons dashicons-heart"></i>' . $love_count . '</span>'; | |
echo '<span class="mk-like-post-category">' . get_the_category_list(', ') . '</span>'; | |
echo '</li>'; | |
endwhile; | |
echo '</ol>'; | |
wp_reset_postdata(); | |
$args = array( | |
'post_type' => 'portfolio', | |
'posts_per_page' => 5, | |
'order' => 'DESC', | |
'orderby' => 'meta_value_num', | |
'meta_key' => '_mk_post_love', | |
); | |
$query = new WP_Query($args); | |
echo '<span class="mk-like-post-posttype-title">' . __('Popular Portfolio Posts', 'mk_framework') . '</span>'; | |
echo '<ol class="mk_posts_like_stats_ol">'; | |
// The Loop | |
while ($query->have_posts()): | |
$query->the_post(); | |
$love_count = get_post_meta(get_the_id() , '_mk_post_love', true); | |
echo '<li>'; | |
echo '<a target="_blank" href="' . esc_url( get_permalink() ) . '" class="mk-like-post-title">' . get_the_title() . '</a>'; | |
echo '<span class="mk-like-post-count"><i class="dashicons dashicons-heart"></i>' . $love_count . '</span>'; | |
echo '<span class="mk-like-post-category">' . implode(', ', mk_get_custom_tax(get_the_id() , 'portfolio', false)) . '</span>'; | |
echo '</li>'; | |
endwhile; | |
echo '</ol>'; | |
wp_reset_postdata(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment