Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Favourite Thumnail #50

Closed
coderste opened this issue Apr 15, 2016 · 10 comments
Closed

Get Favourite Thumnail #50

coderste opened this issue Apr 15, 2016 · 10 comments

Comments

@coderste
Copy link

coderste commented Apr 15, 2016

I think personally it would be an awesome idea if you could get the post thumbnail - this is just a suggest and would be pretty awesome.

Say you favourite a blog you can recognize that blog much easier if the thumbnail was there with it :)

@ben-heath
Copy link

I did it like this. Use the get_user_favorites(); function to bring all the post ids for that user, and store it in a variable. Then do a normal WP_Query, and set that variable as the value for posts__in in the query args.

That way you can get anything from those posts that you need, and display it.

I agree, it would be nice if this was just built into the functions from the Favorites plugin so you could just do this with the shortcodes, but it is still possible.

<div id="rw-favorites-posts" style="display: none;">
  <?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' => 'real-wedding', // 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="postformat-standard">
			<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' );
else : ?>
	<h3 id="no-favs-yet">No Favorites Yet</h3>
	<p>Click on a heart to save a wedding as one of your favorites.<br>Reload the page to see your updated favorites.</p>
 <?php endif; wp_reset_postdata(); ?>
 <?php endif; ?>
</div>

@noonecaresman
Copy link

noonecaresman commented May 9, 2017

Hey can you please specify where to put this code?
Also instead of the thumbnail i would like to display all the content of the favorited post is that possible?
And do you know what happens if a plugin is removed by it's developer? Will it still be working on my website?

Thank you in advance!

@ben-heath
Copy link

The code I posted above would go in a template file. Just depends on where you're wanting it to show up.

As for displaying the content, yes, you can do that. The method I used is just a standard WP_Query, and once you have the loop setup, you would call the function "the_content()" where you want it to show up, in the same way I called "the_title()" or "the_permalink()".

https://codex.wordpress.org/Class_Reference/WP_Query
https://developer.wordpress.org/reference/functions/the_content/

@noonecaresman
Copy link

Hey thank you so much for the reply..this was my first question here!
Also im afraid im to inexperienced to completely understand your method.
To be specific:

1#. In what template file do i add the code? I want the content to show up here. www.trendflix.nl/opgeslagen it is a page not a post.

2#. Can you specify where to put the "the_content()" function. Is it at the "the_title()" or "the_permalink()" or both?

Hopefully you can help.

Bye!

@noonecaresman
Copy link

Can you please help me a little with my question above? it would mean the world to me and willing to pay you, no problem with paypal.. Thank you.

@ben-heath
Copy link

WordPress is made up of several php templates:
https://developer.wordpress.org/themes/basics/template-hierarchy/

Since you only want the code to show up on that one specific page, you'd need to create a template file for just it.
https://developer.wordpress.org/themes/basics/template-hierarchy/#single-page
There are several ways. You could create a page template, and assign it to that page in its editor. You could create a php file like "page-opgeslagen.php", and that would be automatically used when that page is viewed.

To do this, you'll want to use a Child theme, and copy the parent theme's page.php file, change the filename to page-opgeslagen.php, and then change the code within that file to have the "favorites" code added within, in the position where you need it to show up on the page.

the_content() doesn't have to replace the_title() or the_permalink(). It just depends on what you're wanting to show. If you don't want the title or the links to show up, don't use those functions.

It does take some basic knowledge of HTML and PHP to work with template files, which you can learn for free here: https://www.codecademy.com/

@noonecaresman
Copy link

noonecaresman commented May 18, 2017

Thank you so much for the reply! You are the man. Im going to try this out. And I will let you know when and if i manage to fix it! I do have two specific questions (again) just to be sure.

  1. Is this peace of the code also php or is it html? <div id="rw-favorites-posts" style="display: none;"></div>

  2. When i am in the page editor, do i still add the shortcode of the plugin to make the favorite items show up or does everything now go automatically when everything is done correctly.

Blessings from Amsterdam.

@noonecaresman
Copy link

noonecaresman commented May 20, 2017

Hey unfortunately it didn't work.

This is what i did:
I made a new page (not post) called http://trendflix.nl/opgeslagen2/ and on that page i added this shortcode to display the users favorite posts [user_favorites user_id="" include_links="true" site_id="" post_types="" include_buttons="false"]

I duplicated "page.php" and renamed one of the two versions to "page-opgeslagen2.php" the original page code looks like this:

`<?php
/**

  • The template for displaying all pages.

*/

get_header(); ?>

<div id="primary" class="content-area">

	<div class="large-8 columns">

		<main id="main" class="site-main" role="main">

			<?php while ( have_posts() ) : the_post(); ?>

				<?php get_template_part( 'template-parts/content', 'page' ); ?>

			<?php endwhile; // end of the loop. ?>

		</main><!-- #main -->

	</div><!-- .large-8 -->
	
</div><!-- #primary -->`

It also gets the footer and div class=row but those just don't show in the code above no matter what i try.....Anyway I started fiddling around by adding your code before and afer the loop closes in the original page code. I also posted it before <main id="main" class="site-main" role="main"> that all didn't work but when i delete
<div id="rw-favorites-posts" style="display: none;"></div>

It does show the

No Favorites Yet


Click on a heart to save a wedding as one of your favorites.
Reload the page to see your updated favorites.

piece of the code. But no thumbnail or content. For now i left the <div id="rw-favorites-posts" style="display: none;"></div> removed.

I'm not sure about what to do...And i feel a bit sweaty:P Can you pls help again?
when you need an item to save you can find it on this page. http://trendflix.nl/politiek/
I hope you can help i will absolutely pay you!

Im pretty sure the code affects the right page but it just doesnt show the content (i did put the_content() instead of the_post_thumbnail.
I also tried removing the shortcode on the page but that didnt help either.

Hopefully i hear from you.

Cheers!
bye.

@kylephillips
Copy link
Owner

The newest release of the plugin includes an additional parameter in the list shortcode to include the post thumbnail, and specify a size. To enable thumbnails, set the include_thumbnails parameter to true.

[user_favorites user_id="" include_links="true" site_id="" post_types="" include_buttons="false" include_thumbnails="false" thumbnail_size="thumbnail" include_excerpts="false"]

I'm going to go ahead and close this issue… getting into specifics about theming may be better served on another platform.

@ben-heath
Copy link

Thanks Kyle!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants