WordPress.org

Ready to get started?Download WordPress

Forums

WP Favorite Posts
Add CSS class for 'favourited' post? (7 posts)

  1. andy999
    Member
    Posted 1 year ago #

    I've been looking over the code and I can't seem to figure out to to change the class on a post fav link that's already been favourited.

    I'd imagine this is probably easy to do.

    Standard link looks like this on the page

    Add to favorites

    Favourited looks like this

    Remove from favorites

    I'd like to change the class to something like wpfp-faved when the post is actually 'favourited'.

    This would allow for really easy css styling.

    http://wordpress.org/extend/plugins/wp-favorite-posts/

  2. Alex185
    Member
    Posted 1 year ago #

    1. open file:
    wp-favorite-posts/wpfp-page-template.php

    2. find row 22:
    echo "<li><a href='".get_permalink()."' title='". get_the_title() ."'>" . get_the_title() . "</a> ";

    3. add class='my-class'

    4. look like this:
    echo "<li><a class='my-class' href='".get_permalink()."' title='". get_the_title() ."'>" . get_the_title() . "</a> ";

  3. andy999
    Member
    Posted 1 year ago #

    Hi Alex,

    That adds a class to posts on the favourite posts PAGE, to the list of them.

    I want to add a class to the link you see on the posts single page itself, the one that says 'Add to favourites' or 'remove from favourites'.

    This is because I'm not using the favourite posts page, I'm using the sidebar widget and I want it to be obvious which posts are favourited when you're on the page.

  4. Alex185
    Member
    Posted 1 year ago #

    Hi Andy,

    1. I think that
    - for link 'Add to favourites' you can use the class name .wpfp-link
    - for link 'remove from favourites' you can use the class name .remove-parent

    These styles already added in the code (right click - Inspect element).

    2. Also You can open wp-favorite-posts files (for example wp-favorite-posts.php) and try to find a bit of code including
    class="wpfp-link"
    and
    class="wpfp-link remove-parent"
    and add new class.

    For example:
    class="wpfp-link my-class"

    I hope this will help.

  5. andy999
    Member
    Posted 1 year ago #

    I think we're misunderstanding each other here, Alex.

    The link on the single page outputs this code.

    <span class='wpfp-span'><img src='http://192.168.1.141:8888/wp-content/plugins/wp-favorite-posts/img/loading.gif' alt='Loading' title='Loading' class='wpfp-hide wpfp-img' /><a class='wpfp-link' href='?wpfpaction=add&postid=647' title='Add to favorites' rel='nofollow'>Add to favorites</a></span>

    ie, it has the class wpfp-link, now I can add another class to the code quite easily, but that doesn't achieve what I'm trying to do, which is have a different class when it says 'Add to favourites' and when it says 'remove from favourites.

    This is the code it outputs when the story being viewed is already in favourites.

    <span class='wpfp-span'><img src='http://192.168.1.141:8888/wp-content/plugins/wp-favorite-posts/img/loading.gif' alt='Loading' title='Loading' class='wpfp-hide wpfp-img' /><a class='wpfp-link' href='?wpfpaction=remove&postid=647' title='Remove from favorites' rel='nofollow'>Remove from favorites</a></span>

    Same class...

    If I add a class to the wp-favourite-posts.php here

    function wpfp_link_html($post_id, $opt, $action) {
        $link = "<a class='wpfp-link' href='?wpfpaction=".$action."&postid=". $post_id . "' title='". $opt ."' rel='nofollow'>". $opt ."</a>";
        $link = apply_filters( 'wpfp_link_html', $link );
        return $link;
    }

    It adds it for both remove and add.

  6. Alex185
    Member
    Posted 1 year ago #

    Try find <a class='wpfp-link' (in some line)

    1. next rename wpfp-link, and check changes for 'Add to favourites' link.
    if its work - good

    else
    2. find next <a class='wpfp-link' in new line and go to 1.
    ...

  7. andy999
    Member
    Posted 1 year ago #

    Unfortunately it uses the same function to output both the 'Add to favourites' and 'Remove from favourites' link, therefor adding the new class to one adds to to the other also.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.