WordPress.org

Ready to get started?Download WordPress

Forums

rtSocial
[resolved] add individual buttons with different styles (6 posts)

  1. ethandt92
    Member
    Posted 1 year ago #

    I like the loading time of rtsocial, which is why I am trying to switch to that vs the manually written ones given by the original developers. However, my site has different types on different pages. For instance. I have the big box style on my blog list page, but the standard style w/ right counter on my each individual post. Is there anyway I can do that with rtsocial to keep my settings but still have rtsocial's speed?

    http://wordpress.org/extend/plugins/rtsocial/

  2. phirefly
    Member
    Posted 1 year ago #

    I second this - just heard about the great speed of this plugin, however I too would like the ability to use different buttons in different areas of my site.

    eg.

    in posts I have all buttons with counter, however in "archive" I only have the "like" button (no counter)

    thanks!

  3. ethandt92
    Member
    Posted 1 year ago #

    hey phirefly, I actually figured out how to do this but forgot to reply with my solution. What I did was create a duplicate and modified function within source.php, the file in the plugin's folder, of the function rtsocial().

    You can see in rtsocial() that the if statements contain all the options such as horizontal, vertical, and its getting your settings from the $options array. I just removed any of the use of $options with the value I needed and removed the if statements and any social media buttons that I did not need, in my case that would be pinterest and some styles, such as icon and icon-count. Then I called it within my archive.php and single.php files where it was needed.

    1) Copy function rtsocial() into a new function called whatever you want. I called mine rtsocial_edit().
    2) Remove all if statements that you don't need.
    3) Remove $options = get_option( 'rtsocial_plugin_options' ); and all uses of it in the function with the appropriate values.

    $options['display_options_set'] -> horizontal, vertical, etc
    $options['tw_handle'] -> your twitter account
    $options['tw_related_handle'] -> hashtags? I am not sure b/c I didnt use it and so I removed it entirely
    $options['fb_style'] -> like_light, like_dark, etc
    $options['active'] -> the order of the icon to be displayed as it is ksorted in the array $active_services, I used letters
    $options['alignment_options_set'] -> left, right, none, etc

    4) Call the function

    Below is an example:

    function rtsocial_edit() {
        //Working issue on attachment page
        if(is_attachment())
            return;
    
        global $post, $id;
    
        //Ordered buttons
        $active_services = array();
    
        //Twitter
            $tw = 'b';
            $tw_layout = '<div id="rtsocial-twitter-' . 'horizontal' . '">';
            $tw_layout .= '<div class="rtsocial-twitter-' . 'horizontal' . '-button"><a title= "' . esc_attr( get_the_title( $id ) ) . '" class="rtsocial-twitter-button" href= "http://twitter.com/share?via=' . 'twitteraccount' . '&related=' . '' . '&text=' . rt_url_encode( get_the_title( $id ) ) . '" target=\"_blank\" ></a></div><div class="rtsocial-' . 'horizontal' . '-count"><div class="rtsocial-' . 'horizontal' . '-notch"></div><span class="rtsocial-twitter-count"></span></div>';
            $tw_layout .= '</div>';
            $active_services[$tw] = $tw_layout;
        //Twitter End
    
        //Facebook
            $fb = 'a';
            $path = plugins_url( 'images/', __FILE__ );
            $class = 'rtsocial-fb-like-light';
            $rt_fb_style = 'fb-light';
    
            $fb_layout = '<div id="rtsocial-fb-' . 'horizontal' . '" class="' . $rt_fb_style . '">';
            $rt_social_text = 'Like';
            $fb_layout .= '<div class="rtsocial-fb-' . 'horizontal' . '-button"><a title="' . $rt_social_text . '" class="rtsocial-fb-button ' . $class . '" href="http://www.facebook.com/sharer.php?" target="_blank"></a></div><div class="rtsocial-' . 'horizontal' . '-count"><div class="rtsocial-' . 'horizontal' . '-notch"></div><span class="rtsocial-fb-count"></span></div>';
            $fb_layout .= '</div>';
            $active_services[$fb] = $fb_layout;
        //Facebook End
    
        //LinkedIn
            $lin = 'd';
            $summary = (strlen($post->post_content) > 100) ? wp_html_excerpt($post->post_content, 100) : $post->post_content;
            $lin_layout = '<div id="rtsocial-linkedin-' . 'horizontal' . '">';
            $lin_layout .= '<div class="rtsocial-linkedin-' . 'horizontal' . '-button"><a class="rtsocial-linkedin-button" href= "http://www.linkedin.com/shareArticle?mini=true&url='.urlencode(get_permalink($post->ID)).'&title='.urlencode(get_the_title( $post->ID )).'&summary='.$summary.'" target="_blank" ></a></div><div class="rtsocial-' . 'horizontal' . '-count"><div class="rtsocial-' . 'horizontal' . '-notch"></div><span class="rtsocial-linkedin-count"></span></div>';
            $lin_layout .= '</div>';
            $active_services[$lin] = $lin_layout;
        //Linked In End
    
        //G+ Share Button
            $gplus = 'c';
            $gplus_layout = '<div id="rtsocial-gplus-' . 'horizontal' . '">';
            $gplus_layout .= '<div class="rtsocial-gplus-' . 'horizontal' . '-button"><a class="rtsocial-gplus-button" href= "https://plus.google.com/share?url='.urlencode(get_permalink($post->ID)).'" target="_blank" ></a></div><div class="rtsocial-' . 'horizontal' . '-count"><div class="rtsocial-' . 'horizontal' . '-notch"></div><span class="rtsocial-gplus-count"></span></div>';
            $gplus_layout .= '</div>';
            $active_services[$gplus] = $gplus_layout;
        //G+ Share Button End
    
        //Sort by indexes
        ksort($active_services);
    
        //Form the ordered buttons markup
        $active_services = implode('', $active_services);
    
        //Rest of the stuff
        $layout = '<div class="rtsocial-container rtsocial-container-align-' . 'none' . ' rtsocial-' . 'horizontal' . '" >';
            //Append the ordered buttons
            $layout .= $active_services;
    
        //Hidden permalink
        $layout .= '<a title="' . esc_attr( get_the_title( $id ) ) . '" rel="nofollow" class="perma-link" href="' . get_permalink( $id ) . '" title="' . esc_attr( get_the_title( $id ) ) . '"></a></div>';
    
        return $layout;
    }
  4. phirefly
    Member
    Posted 1 year ago #

    Aw cheers ethandt92!

    Very much appreciated :)

  5. ethandt92
    Member
    Posted 1 year ago #

    your welcome! it looks like the plugin was just updated with manual features so my solution is no longer necessary

  6. Rutwick Gangurde
    Member
    Plugin Contributor

    Posted 1 year ago #

    @Phirefly and @Ethandt92

    Exactly, we have updated the plugin and now you can override the options in your manual call to rtSocial.

    @Ethandt92
    Thanks for your effort mate :)

    - Rutwick

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.