Skip to:
Content
Pages
Categories
Search
Top
Bottom

Modifying Activity Loop for Likebtn


  • jgilbert1990
    Participant

    @jgilbert1990

    Hope everybody is doing well.
    Im having trouble using a plugin. The plugin is by likebtn.com and allows me to sort activity by most liked content. However it requires modifying a bit of code and im having quite the difficult time. I have tried pasting this line of code into a few different files. Currently im trying to paste it into ‘public_html/wp-content/plugins/buddypress/bp-activity/bp-activity-template.php’. When i try to include it into the PHP file the activity page breaks and a syntax error appears saying there was an unexpected ‘<‘ at the top of the new code. Here is where i pasted the code and the instructions provided by likebtn.com

    function bp_has_activities( $args = '' ) {
    	global $activities_template;
    
    	// Get BuddyPress.
    	$bp = buddypress();
    
    	/*
    	 * Smart Defaults.
    	 */
             //Filtering by Likes.Custom Code.
             <?php query_posts($query_string . '&meta_key=Likes&orderby=meta_value&meta_type=numeric&order=DESC'); ?>
    <?php /* Start the Loop */ ?>
    <?php while ( have_posts() ) : the_post(); ?>
        <?php get_template_part( 'content', get_post_format() ); ?>
    <?php endwhile; ?>
    
    	// User filtering.
    	$user_id = bp_displayed_user_id()
    		? bp_displayed_user_id()
    		: false;

    https://likebtn.com/en/wordpress-like-button-plugin#sort_posts_by_likes

Viewing 2 replies - 1 through 2 (of 2 total)

  • danbp
    Moderator

    @danbp

    Perhaps the closing php tag after endwhile. Remove ?>

    <?php endwhile;
    	// User filtering.
    	$user_id = bp_displayed_user_id()
    		? bp_displayed_user_id()
    		: false;

    Note that you’re hacking a core file and that customization will be lost at next bp update.
    Never do that.
    That said i doubt that your like button will work on BP activities. That button is made for wordpress, not BP.
    Try better this plugin which is more appropriate imho.
    https://wordpress.org/plugins/buddypress-like/


    jgilbert1990
    Participant

    @jgilbert1990

    Thanks DANBP, i will give that a shot.

    What i am trying to achieve is to have my sitewide activity sorted by likes. Ill use a ‘recipe’ site as a simple example. I would like my users to be able to post recipes and have other users like there favorite recipes. I would like my ‘Sitewide Activity’ page to be organized with most liked recipes at the top.

    As far as i can tell this is the only plugin that will allow that. There is an option to allow voting on buddypress activities, which led me to believe this was possible.

    Any advice would be much appreciated. Do you think if i learn enough about PHP i will be able to edit the code to allow this plugin to do this?
    Is there anyway to modify the functions of sitewide activity in my own file? One that will still exist after a update?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar