Last active
March 4, 2017 15:02
-
-
Save omniacode/0850b118e3ce4814973b35c2670d03fa to your computer and use it in GitHub Desktop.
WP Favorites : Thumbnail Favorites
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
<div id="favorites-post-container"> | |
<?php | |
$favorites = get_user_favorites(); | |
if ( $favorites ) : // This is important: if an empty array is passed into the WP_Query parameters, all posts will be returned | |
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; // If you want to include pagination | |
$favorites_query = new WP_Query(array( | |
'post_type' => 'post', // If you have multiple post types, pass an array | |
'posts_per_page' => -1, | |
'ignore_sticky_posts' => true, | |
'post__in' => $favorites, | |
'paged' => $paged // If you want to include pagination, and have a specific posts_per_page set | |
)); | |
if ( $favorites_query->have_posts() ) : while ( $favorites_query->have_posts() ) : $favorites_query->the_post(); ?> | |
<div class="grid-post_outer masonry-item masonry-brick"> | |
<div class="favorites-wrapper"> | |
<a class="blog-thumb" href="<?php the_permalink(); ?>"> | |
<h3><?php the_title(); the_favorites_button(); ?></h3> | |
</a> | |
<a href="<?php the_permalink(); ?>"> | |
<?php the_post_thumbnail(); ?> | |
</a> | |
</div> | |
</div> | |
<?php endwhile; | |
next_posts_link( 'Older Favorites', $favorites_query->max_num_pages ); | |
previous_posts_link( 'Newer Favorites' ); | |
endif; wp_reset_postdata(); | |
else : ?> | |
<h3 id="no-favs-yet">No Favorites Yet</h3> | |
<p>Click on a heart to save a *post* as one of your favorites.<br>Reload the page to see your updated favorites.</p> | |
<?php endif; ?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment