Git Product home page Git Product logo

Comments (7)

tareq1988 avatar tareq1988 commented on July 2, 2024

You can still use get_the_post_thumbnail function.

from wedevs-favorite-post.

jeremyomeara avatar jeremyomeara commented on July 2, 2024

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?

from wedevs-favorite-post.

tareq1988 avatar tareq1988 commented on July 2, 2024

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

from wedevs-favorite-post.

jeremyomeara avatar jeremyomeara commented on July 2, 2024

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.

from wedevs-favorite-post.

jeremyomeara avatar jeremyomeara commented on July 2, 2024

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

from wedevs-favorite-post.

tareq1988 avatar tareq1988 commented on July 2, 2024

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>';

from wedevs-favorite-post.

jeremyomeara avatar jeremyomeara commented on July 2, 2024

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?

from wedevs-favorite-post.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.