DIY Themes Forums  

Go Back   DIY Themes Forums > Thesis Theme > Thesis Customization Tips
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-01-2008, 12:05 PM
Senior Member
 
Join Date: Jul 2008
Location: Connersville, IN
Posts: 2,244
Send a message via ICQ to kingdomgeek Send a message via AIM to kingdomgeek Send a message via MSN to kingdomgeek Send a message via Yahoo to kingdomgeek
Talking Brian's Latest Comment - A Full-Featured Widget for Your Convenience

Brian's Latest Comments (BLC) is an excellent plugin for displaying recent comments in your sidebar, but if you want to use it with Thesis, you have to edit one of the sidebar files directly. Unfortunately, there isn't a widget for BLC.

Until now.

I don't claim this is perfect -- it's the product of a late-night-desire to produce something.

Place the following code (also available here) into your custom_functions.php file:

Code:
/*
    Widget for Brian's Latest Comments
*/

if (function_exists('blc_latest_comments')) {
    // Output the widget
    function brians_latest_comments_widget($args) {
        extract($args, EXTR_SKIP);
        $options = get_option('brians_latest_comments_widget');
        $posts = $options['brians-latest-comments-posts'] - 1;
        
        echo $before_widget . "\n";
        echo $before_title . $options['brians-latest-comments-title'] . $after_title . "\n";
        echo "<ul>\n";
        blc_latest_comments($posts, $options['brians-latest-comments-commenters'], $options['brians-latest-comments-hide-tbpb'], '                                <li>', '</li>', $options['brians-latest-comments-fade-old'], $options['brians-latest-comments-days'], $options['brians-latest-comments-fade-start'], $options['brians-latest-comments-fade-end']);
        echo "</ul>\n";
        echo $after_widget . "\n";
    }

    function wp_flush_widget_brians_latest_comments() {
        wp_cache_delete('brians_latest_comments_widget', 'widget');
    }
    add_action('comment_post', 'wp_flush_widget_brians_latest_comments');
    add_action('edit_comment', 'wp_flush_widget_brians_latest_comments');
    add_action('delete_comment', 'wp_flush_widget_brians_latest_comments');
    add_action('pingback_post', 'wp_flush_widget_brians_latest_comments');
    add_action('trackback_post', 'wp_flush_widget_brians_latest_comments');
    add_action('wp_set_comment_status', 'wp_flush_widget_brians_latest_comments');

    // Widget control
    function brians_latest_comments_control() {
        $options = $newoptions = get_option('brians_latest_comments_widget');
        
        if ($_POST['brians-latest-comments-submit']) {
            $newoptions['brians-latest-comments-title'] = strip_tags(stripslashes($_POST['brians-latest-comments-title']));
            $newoptions['brians-latest-comments-posts'] = (int) $_POST['brians-latest-comments-posts'];
            $newoptions['brians-latest-comments-commenters'] = (int) $_POST['brians-latest-comments-commenters'];
            $newoptions['brians-latest-comments-hide-tbpb'] = (int) $_POST['brians-latest-comments-hide-tbpb'];
            $newoptions['brians-latest-comments-fade-old'] = (int) $_POST['brians-latest-comments-fade-old'];
            $newoptions['brians-latest-comments-days'] = (int) $_POST['brians-latest-comments-days'];
            $newoptions['brians-latest-comments-fade-start'] = strip_tags(stripslashes($_POST['brians-latest-comments-fade-start']));
            $newoptions['brians-latest-comments-fade-end'] = strip_tags(stripslashes($_POST['brians-latest-comments-fade-end']));
        }
    
        if ($options != $newoptions) {
            $options = $newoptions;
            update_option('brians_latest_comments_widget', $options);
            wp_flush_widget_brians_latest_comments();
        }
        
        $title = attribute_escape($options['brians-latest-comments-title']);
        if (!$posts = (int) $options['brians-latest-comments-posts'])
            $posts = 5;
        if (!$commenters = (int) $options['brians-latest-comments-commenters'])
            $commenters = 5;
        $hide_tbpb = (int) $options['brians-latest-comments-hide-tbpb'];
        $fade_old = (int) $options['brians-latest-comments-fade-old'];
        if (!$days = (int) $options['brians-latest-comments-days'])
            $days = 10;
        $fade_start = attribute_escape($options['brians-latest-comments-fade-start']);
        $fade_end = attribute_escape($options['brians-latest-comments-fade-end']);
    ?>
            <p>
                <label for="brians-latest-comments-title"><?php _e('Title:', 'thesis'); ?>
                <input type="text" class="widefat" id="brians-latest-comments-title" name="brians-latest-comments-title" value="<?php echo $title; ?>" /></label>
            </p>
            <p>
                <label for="brians-latest-comments-posts"><?php _e('Number of posts for which to show comments:', 'thesis'); ?> <input style="width: 25px; text-align: center;" id="brians-latest-comments-posts" name="brians-latest-comments-posts" type="text" value="<?php echo $posts; ?>" /></label>
                <br />
                <small><?php _e('(default is 5)', 'thesis'); ?></small>
            </p>
            <p>
                <label for="brians-latest-comments-commenters"><?php _e('Number of commenters to show per post:', 'thesis'); ?> <input style="width: 25px; text-align: center;" id="brians-latest-comments-commenters" name="brians-latest-comments-commenters" type="text" value="<?php echo $commenters; ?>" /></label>
                <br />
                <small><?php _e('(default is 5)', 'thesis'); ?></small>
            </p>
            <p>
                <label for="brians-latest-comments-hide-tbpb"><input id="brians-latest-comments-hide-tbpb" name="brians-latest-comments-hide-tbpb" type="checkbox" value="1" <?php if ($hide_tbpb) echo 'checked="checked" '; ?>/> <?php _e('Hide TrackBacks &amp; PingBacks?', 'thesis'); ?></label>
            </p>
            <p>
                <label for="brians-latest-comments-fade-old"><input id="brians-latest-comments-fade-old" name="brians-latest-comments-fade-old" type="checkbox" value="1" <?php if ($fade_old) echo 'checked="checked" '; ?>/> <?php _e('Fade older comments?', 'thesis'); ?></label>
            </p>
            <p>
                <label for="brians-latest-comments-days"><?php _e('Number of days it takes for a comment to fade from newest to oldest:', 'thesis'); ?> <input style="width: 25px; text-align: center;" id="brians-latest-comments-days" name="brians-latest-comments-days" type="text" value="<?php echo $days; ?>" /></label>
                <br />
                <small><?php _e('(default is 10)', 'thesis'); ?></small>
            </p>
            <p>
                <label for="brians-latest-comments-fade-start"><?php _e('Start color for commenter fading:', 'thesis'); ?>
                <input class="widefat" type="text" id="brians-latest-comments-fade-start" name="brians-latest-comments-fade-start" value="<?php echo $fade_start; ?>" /></label>
                <br />
                <small><?php _e('(example: #000000)', 'thesis'); ?></small>
            </p>
            <p>
                <label for="brians-latest-comments-fade-end"><?php _e('End color for commenter fading:', 'thesis'); ?>
                <input class="widefat" type="text" id="brians-latest-comments-fade-end" name="brians-latest-comments-fade-end" value="<?php echo $fade_end; ?>" /></label>
                <br />
                <small><?php _e('(example: #DDDDDD)', 'thesis'); ?></small>
            </p> 
            <input type="hidden" id="brians-latest-comments-submit" name="brians-latest-comments-submit" value="1" />
    <?php
    }
    
    // Register this widget
    register_sidebar_widget(__('Brian\'s Latest Comments', 'thesis'), 'brians_latest_comments_widget');
    register_widget_control(__('Brian\'s Latest Comments', 'thesis'), 'brians_latest_comments_control');
}
Save/upload the file, and browse to the WordPress Widgets manager. You'll now be able to use the Brian's Latest Comments widget in either sidebar, wherever you want, with all the options you'll need to make it look nice.

I'm pretty sure that if you want to use the commenter-fading functionality, you'll need to put in both a start & end color as well. You shouldn't have to -- it should use some sort of default -- but that's something I'll work on later.

That minor annoyance aside, this should be a nice addition for any BLC user -- whether using Thesis or not.

(Users of any other theme can put the code into their theme's functions.php file, and they'll be able to use the widget as well!)
__________________
Rick Beckman, Kingdom Geek & Thesis Support Ninja (Forums Moderator)
[ Thesis Manual | Help, my posts don't show up! ]


Amazon Wishlist | My custom.css
Get Thesis! | Earn Cash as a DIY Affiliate!
Reply With Quote
  #2 (permalink)  
Old 08-01-2008, 03:58 PM
Member
 
Join Date: Jul 2008
Posts: 79
Default

THANK YOU! Love it!
Reply With Quote
  #3 (permalink)  
Old 08-01-2008, 08:48 PM
 
Join Date: Jun 2008
Posts: 9
Default

This is great. Thanks Rick!
Reply With Quote
  #4 (permalink)  
Old 09-06-2008, 03:45 PM
Junior Member
 
Join Date: Sep 2008
Posts: 15
Default

The Master of Puppets should be on his way home.

Thanks for this Rick, i hope you keep updating your hacks.

Ps: this is my first post here, bougth thesis a few hours ago, hi there for all of you
Reply With Quote
  #5 (permalink)  
Old 09-29-2008, 02:23 AM
 
Join Date: Sep 2008
Posts: 17
Thumbs up

Rick,

This works wonderfully. A very helpful Thesis modification.

Thank you.
Alec
__________________
Making Project Management Better
Effectiveness Blog with a People Skills Focus.
Please visit: http://blog.alecsatin.com
http://twitter.com/alecsatin
Reply With Quote
  #6 (permalink)  
Old 11-16-2008, 08:21 PM
Junior Member
 
Join Date: Sep 2008
Posts: 6
Thumbs up

Bows to kingdongeek. Now I have an example of how to create custom widgets. I used to hate editing my blog templates, looks like it will be totally modular and drag-n-drop customizable in a year or two, or so I can hope.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:19 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0