Open jeremyomeara opened 11 years ago
You can still use get_the_post_thumbnail function.
Yes but I'm a little unsure as to exactly how to include it in your plugin, I'm more of a theme dev than a plugin dev and I don't want to break your nice pluggin. :) Any tips?
How are you displaying the favorite post actually? With shortcode?
php directly into the template. I've also very slightly modified your favorite-post.php code (sorry, but i have a very specific need) with the following (see the final printf statement):
/* * Display favorite posts * @param string $post_type * @param int $user_id * @param int $limit * @param bool $show_remove */ function display_favorites( $post_type = 'all', $user_id = false, $limit = 10, $show_remove = true ) {
$posts = $this->get_favorites( $post_type, $user_id, $limit );
echo '<ul class="userBookmarks">';
if ( $posts ) {
$remove_title = __( 'Remove from favorites', 'wfp' );
$remove_link = ' <a href="#" data-id="%s" title="%s" class="wpf-remove-favorite">x</a>';
foreach ($posts as $item) {
$extra = $show_remove ? sprintf( $remove_link, $item->post_id, $remove_title ) : '';
printf( '<li><span class="bookmarkIcon"></span><a href="%s" class="bookmarkLink">%s</a>%s</li>', get_permalink( $item->post_id ), get_the_title( $item->post_id ), $extra );
}
} else {
printf( '<li>%s</li>', __( 'Nothing found', 'wfp' ) );
}
echo '</ul>';
}
You're help is much appreciated.
Hi there Tareq, any suggestions? I'm not exactly a PHP expert.
You shouldn't be updating the plugin code. Here's how you can do it:
$favorite_post = WeDevs_Favorite_Posts::init()->get_favorites( 'all', $user_id );
echo '<ul>';
if ( $favorite_post ) {
$remove_title = __( 'Remove from favorite', 'wfp' );
$remove_link = ' <a href="#" data-id="%s" title="%s" class="wpf-remove-favorite">x</a>';
foreach ($favorite_post as $item) {
$extra = $show_remove ? sprintf( $remove_link, $item->post_id, $remove_title ) : '';
?>
<li>
<?php
if ( has_post_thumbnail( $item->ID ) ) {
echo get_the_post_thumbnail( $item->ID, 'thumbnail' );
} else {
//show some blank image
}
?>
<a href="<?php echo get_permalink( $item->ID ); ?>"><?php echo get_the_title( $item->post_id ) ?></a>
<?php echo $extra; ?>
</li>
<?php
}
} else {
printf( '<li>%s</li>', __( 'Nothing found', 'wfp' ) );
}
echo '</ul>';
Ok thanks for that. I'm not keen usually on changing plugin code directly but I'm really trying to achieve something very specific. Would you consider adding it to a future version?
Is there anyway of pulling in a page/post's feature image? Would be very handy for icons