tareq1988 / wedevs-favorite-post

Yet another favorite post plugin for WordPress
https://wordpress.org/plugins/favorite-post/
15 stars 10 forks source link

Feature Request #1

Open jeremyomeara opened 11 years ago

jeremyomeara commented 11 years ago

Is there anyway of pulling in a page/post's feature image? Would be very handy for icons

tareq1988 commented 11 years ago

You can still use get_the_post_thumbnail function.

jeremyomeara commented 11 years ago

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?

tareq1988 commented 11 years ago

How are you displaying the favorite post actually? With shortcode?

jeremyomeara commented 11 years ago

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.

jeremyomeara commented 11 years ago

Hi there Tareq, any suggestions? I'm not exactly a PHP expert.

tareq1988 commented 11 years ago

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>';
jeremyomeara commented 11 years ago

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?