WordPress.org

Ready to get started?Download WordPress

Forums

WP Favorite Posts
[resolved] Suggestions on Widget: Refresh, remove, empty,share,manage buttons (24 posts)

  1. 3x7
    Member
    Posted 2 years ago #

    Widget should work like "shopping cart" on e-commerce sites (add to basket style), so when visitor add post to favorites, the list on widget should refresh.

    If that is not possible at least "refresh" button would be enough to refresh the favorites widget.

    Few other options that would be welcome by many of us I believe.

    1. "Remove from favorites" or "X" icon, after each post
    2. "Empty" or "trash" icon, to delete whole favorites list
    3. "Share/email favorites" Social networks icons and mail
    4. "Save favorites list" or "Manage favorites" link to the favorites page

    Also some suggestions on design like thumbnails etc.... but those are essential I believe.

    Thanks.
    Cheers!

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

  2. 3x7
    Member
    Posted 1 year ago #

    nr.1 is solved, in case somebody is interested:

    add this

    echo "-";
    wpfp_remove_favorite_link($post_id);

    right after this:
    echo "<a href='".get_permalink($post_id)."' title='". $p->post_title ."'>" . $p->post_title . "</a> ";

    Cheers!

  3. 3x7
    Member
    Posted 1 year ago #

    nr.2

    add

    echo "<a class='wpfp-link' href='?wpfpaction=clear' rel='nofollow'>". wpfp_get_option('clear') . "</a>";

    right after
    echo "";
    }

    wpfp-your-favs-widget.php

  4. 3x7
    Member
    Posted 1 year ago #

    nr.3 Should be able to do with "social streamer" plugin.

    nr4. could also be done with sharing plugin 'send to email'

  5. chrisgagner
    Member
    Posted 1 year ago #

    Were you ever able to get the sidebar widget to refresh when a user clicks "Add to Favorites" or at least refresh the page upon click so that the widget will refresh?

  6. 3x7
    Member
    Posted 1 year ago #

    yes I did, somehow this woked for me

    add this

    function refresh(){
    
       doAjaxCall(); // ajax call to get new data and update the widget
    
       setTimeout(refresh), delay ); // schedule next refresh
    
    }

    to wpfp.js file

    somwhere before endscript.

    Only problem is that when it refreshes the page th page loads from the begining and not where the user way when clicked on "add to fav"... hopefully somebody will find a way to refresh "ONLY" sidebar.

    Hope it helps.

    Cheers!

  7. chrisgagner
    Member
    Posted 1 year ago #

    That's a good start... thanks!

  8. 3x7
    Member
    Posted 1 year ago #

    Found a better solution so far:

    1. remove the old code for refreshing from wpfp.js file

    2. find the #id of the widget or sidebar in the css of the theme...

    3. put this in your header between <head> </head>

    <script type="text/javascript">
    
    			function WidgetRefresh() {
    			$("#YOURDIVID").load(location.href+" #YOURDIVID>*","");
    			}
    			setInterval(function() {
    			WidgetRefresh();
    			}, 3000);
    			</script>

    4. rename YOURDIVID to desired DIV ID which has to be refreshed.
    done.

    This will refresh the widget in the selected DIV every 3 seconds.

    Cheers!

  9. chrisgagner
    Member
    Posted 1 year ago #

    I know very little about javascript.. but is there a way to setup this script to only run when the user clicks "Add to favorites" or "Remove from favorites"... so the timeline would kinda look like this:

    1) User clicks link to add to favorites.
    2) Script runs and counts down 3 seconds
    3) Widget refreshes
    4) Script stops running.

    If this is possible, it might be better than having it refreshing constantly in the background.

  10. 3x7
    Member
    Posted 1 year ago #

    I totally agree with you, and tried to achieve this in several ways but no luck... hopefully I'll make it work someday, or if anybody else with more knowledge helps us.

    Cheers!

  11. sigmus
    Member
    Posted 1 year ago #

    Hi, this worked fine for me, just putting the code you sent at wpfp.js, but in the end of the function jQuery.get, like this:

    jQuery.get(url, params, function(data) {
                    dhis.parent().html(data);
                    if(typeof wpfp_after_ajax == 'function') {
                        wpfp_after_ajax( dhis ); // use this like a wp action.
    				}
    				loadingImg.hide();
    				dhis.show();
    				$("#top5").load(location.href+" #top5>*","");
                }
            );

    And in my sidebar I've used the widget internally, not throught the widgets admin stuff, like this:

    <div class="widget" id="top5">
            <h1><?=__('Top 5'); ?></h1>
            <?php if (function_exists('wpfp_list_most_favorited')) { wpfp_list_most_favorited(); } ?>
        </div>
  12. 3x7
    Member
    Posted 1 year ago #

    unfortunately it still refreshes whole page for me, not just the sidebar... maybe on some other themes and configuration it would work normally...

  13. 3x7
    Member
    Posted 1 year ago #

    a bit of copy/paste did the trick:

    add this at the top of the wpfp.js

    function WidgetRefresh() {
    			$("#YOUR-DIV-IDorClass").load(location.href+" #YOUR-DIV-IDorClass>*","");
    			};

    then right after the last
    loadingImg.hide(); at the bottom of the file but before }

    add
    WidgetRefresh();

    Cheers!

  14. 3x7
    Member
    Posted 1 year ago #

    Next, I would need to refresh the button so it does not stay on "removed from favorites" but to refresh back to "add to favorites" and also from "added to favorites" it should go back to "remove from favorites"

    I tried the same way like sidebar but it adds another div after a refresh (it might be that it works on some themes).

    I believe ithis should be done in the plugin core somewhere :)

    any idea?

  15. 3x7
    Member
    Posted 1 year ago #

    done.

    Dynamic sidebar can be refreshed, so I created a widget as a "button" then set to refresh the dynamic sidebar inside the post.

  16. sparespace
    Member
    Posted 1 year ago #

    3x7, can you show your full code for refreshing a widget and a button? Thx!

  17. 3x7
    Member
    Posted 1 year ago #

    Complete wpfp.js file:

    function WidgetRefresh() {
    			$("#sidebar-right").load(location.href+" #sidebar-right>*","");
    			$(".buttonbar-widget").load(location.href+".buttonbar-widget>*","");
    			};
    
    jQuery(document).ready( function($) {
    
        $('.wpfp-link').live('click', function() {
            dhis = $(this);
            wpfp_do_js( dhis, 1 );
            // for favorite post listing page
            if (dhis.hasClass('remove-parent')) {
               dhis.parent("li").fadeOut();
            }
            return false;
        });
    });
    
    function wpfp_do_js( dhis, doAjax ) {
    
        loadingImg = dhis.prev();
        loadingImg.show();
        beforeImg = dhis.prev().prev();
        beforeImg.hide();
        url = document.location.href.split('#')[0];
        params = dhis.attr('href').replace('?', '') + '&ajax=1';
        if ( doAjax ) {
            jQuery.get(url, params, function(data) {
                    dhis.parent().html(data);
                    if(typeof wpfp_after_ajax == 'function') {
                        wpfp_after_ajax( dhis ); // use this like a wp action.
                    }
                    loadingImg.hide();
    				WidgetRefresh();
                }
           );
        }
    }

    Change the "#sidebar-right" to your id or class of the sidebar where the favorites are (also works for most favourited).
    Change ".buttonbar-widget" to your id or class where the button is placed.
    You can also add some more classes or ids to refresh, just copy paste the "function WidgetRefresh" line and change to your id or class.

  18. andy999
    Member
    Posted 1 year ago #

    great job, 3x7.

    I'm getting the widget to refresh but I can't seem to get the wpfp-link to refresh when it's clicked?

    Can you explain how you got it to work?

  19. 3x7
    Member
    Posted 1 year ago #

    I managed it to refresh it as a widget area, so I created a widget area "inside" the post where I want it to be, then create "something.php" file with this code and place it in "plugins", activate it and place the widget in the widget area where you want it to be. Then set the script above to "refresh" that area too.

    Here is a code for a button widget:

    <?php
    /*
    Plugin Name: FavButton
    Plugin URI: http://xy.xy/
    Description: FavButton
    Author: 3x7
    Version: 1
    Author URI: http://
    */
    
    class FavButton extends WP_Widget
    {
      function FavButton()
      {
        $widget_ops = array('classname' => 'FavButton', 'description' => 'Displays a FavButton' );
        $this->WP_Widget('FavButton', 'FavButton', $widget_ops);
      }
    
      function form($instance)
      {
        $instance = wp_parse_args( (array) $instance, array( 'title' => '' ) );
        $title = $instance['title'];
    ?>
      <p><label for="<?php echo $this->get_field_id('title'); ?>">Title: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p>
    <?php
      }
    
      function update($new_instance, $old_instance)
      {
        $instance = $old_instance;
        $instance['title'] = $new_instance['title'];
        return $instance;
      }
    
      function widget($args, $instance)
      {
        extract($args, EXTR_SKIP);
    
        echo $before_widget;
        $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
    
        if (!empty($title))
          echo $before_title . $title . $after_title;;
    ?>
    
    						<div class="btn btn-mini">
    						<?php
    						if (function_exists('wpfp_link')) {	wpfp_link();}
    						?>
    						</div>
    
    <?php   echo $after_widget;
      }
    
    }
    add_action( 'widgets_init', create_function('', 'return register_widget("FavButton");') );?>
  20. andy999
    Member
    Posted 1 year ago #

    Haha instead of just refreshing the button in the widget area, it loads the entire page into the container I set to refresh.

    Oh god, what have I done wrong?

    Was a problem with my syntax, got it working now.

    Except although the button refreshes, the second time it's clicked on, it reloads the page?

  21. 3x7
    Member
    Posted 1 year ago #

    hum...
    I had similar problem on my old hosting...
    I'll test it again on my machine..

  22. andy999
    Member
    Posted 1 year ago #

    I thought it might be something to do with deprecated jquery functions, because the plugin uses code from jquery circa 1.6, whereas the newer wordpress distros use 1.9.1? I think.

    To get to working in the first place I had to change this

    jQuery(document).ready( function($) {
    
        $('.wpfp-link').live('click', function() {
            dhis = $(this);
            wpfp_do_js( dhis, 1 );
            // for favorite post listing page
            if (dhis.hasClass('remove-parent')) {
               dhis.parent("li").fadeOut();
            }
            return false;
        });
    });

    To this

    jQuery(document).ready( function($) {
    
        $('.wpfp-link').on('click', function() {
            dhis = $(this);
            wpfp_do_js( dhis, 1 );
            // for favorite post listing page
            if (dhis.hasClass('remove-parent')) {
               dhis.parent("li").fadeOut();
            }
            return false;
        });
    });

    Since 'live' doesn't work anymore, at least for this.

    I can't see anything else wrong with it though.

  23. 3x7
    Member
    Posted 1 year ago #

    worked fine for me, except on the second fav removal of the same post, it reloads the page...
    will have a look into it...

    thanks!

  24. jherrero7
    Member
    Posted 1 year ago #

    Anyone know if there is a widget that show real-time visits to the blog with google analytics? I would like to implement it in the web: Recetas de Postres Fáciles

    Thanks

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic