Thesis 2 – Filter Comments Intro

Thesis 2 comment intro displays the total number of comments as well as acting as a jump link between the start of the comments and the comment form – handy if you have a lot of comments on your pages.

The default comment intro box displays the following.

X Comment(s)… Add one

You can change the comment(s) text via the HTML editor.

comment intro

However some users may wish to change the jump link (Add one) – after looking at the code for this box it turns out you can do this via a filter.

There are two ways in which you can do this – the first with custom.php and the other with skin.php

Custom.php – for skins created by someone else

add_filter('thesis_comments_intro_add', 'replace_comments_intro_link');

// Replace comment intro jump link
function replace_comments_intro_link() {
        return '<a href="#commentform" rel="nofollow">Add yours now</a>';
}

Skin.php – for custom skins created by you

protected function construct() {
        add_filter('thesis_comments_intro_add', array( $this,'replace_comments_intro'));
}

// Replace comment intro jump link
function replace_comments_intro() {
        return '<a href="#commentform" rel="nofollow">Add yours now</a>';
}
Note: the difference between skin.php and custom.php – Skin.php is used by developers to include additional functionality which is part of the core of the skin whereas custom.php is for users of that skin to add further customizations which wont interfere with the skin if and when it’s updated.

Customize the Comments Intro

Customizing the comment link may not be enough for you, so why not customizing the who thing.

This is the complete filter to return the comment intro as it is.

Custom.php

add_filter('thesis_comments_intro', 'custom_thesis_comments_intro');

// Custom Comments Intro
function custom_thesis_comments_intro() {
        global $thesis, $wp_query;
        $number = (int) count($wp_query->comments_by_type['comment']);
        return  "<span class=\"num_comments\">". count($wp_query->comments_by_type['comment']). "</span> ".
                ($number == 1 ? (!empty($this->options['singular']) ?
                $thesis->api->esch($this->options['singular']) : $thesis->api->strings['comment_singular']) : (!empty($this->options['plural']) ?
                $thesis->api->esch($this->options['plural']) : $thesis->api->strings['comment_plural'])).
                "&#8230; <a href=\"#commentform\" rel=\"nofollow\">". trim(apply_filters("{$this->_class}_add", __('add one'), 'thesis')). "</a>";
}

Skin.php

protected function construct() {
        add_filter('thesis_comments_intro', array( $this,'custom_thesis_comments_intro'));
}

// Custom Comments Intro 
function custom_thesis_comments_intro() {
        global $thesis, $wp_query;
        $number = (int) count($wp_query->comments_by_type['comment']);
        return  "<span class=\"num_comments\">". count($wp_query->comments_by_type['comment']). "</span> ".
                ($number == 1 ? (!empty($this->options['singular']) ?
                $thesis->api->esch($this->options['singular']) : $thesis->api->strings['comment_singular']) : (!empty($this->options['plural']) ?
                $thesis->api->esch($this->options['plural']) : $thesis->api->strings['comment_plural'])).
                "&#8230; <a href=\"#commentform\" rel=\"nofollow\">". trim(apply_filters("{$this->_class}_add", __('add one'), 'thesis')). "</a>";
}

Lets look at removing the link and ellipsis so that our comment intro says X Comment(s).

Custom.php

add_filter('thesis_comments_intro', 'custom_thesis_comments_intro');

// Custom Comments Intro
function custom_thesis_comments_intro() {
        global $thesis, $wp_query;
        $number = (int) count($wp_query->comments_by_type['comment']);
        return  "<span class=\"num_comments\">". count($wp_query->comments_by_type['comment']). "</span> ".
                ($number == 1 ? (!empty($this->options['singular']) ?
                $thesis->api->esch($this->options['singular']) : $thesis->api->strings['comment_singular']) : (!empty($this->options['plural']) ?
                $thesis->api->esch($this->options['plural']) : $thesis->api->strings['comment_plural']));
}

Skin.php

protected function construct() {
        add_filter('thesis_comments_intro', array( $this,'custom_thesis_comments_intro'));
}

// Custom Comments Intro 
function custom_thesis_comments_intro() {
        global $thesis, $wp_query;
        $number = (int) count($wp_query->comments_by_type['comment']);
        return  "<span class=\"num_comments\">". count($wp_query->comments_by_type['comment']). "</span> ".
                ($number == 1 ? (!empty($this->options['singular']) ?
                $thesis->api->esch($this->options['singular']) : $thesis->api->strings['comment_singular']) : (!empty($this->options['plural']) ?
                $thesis->api->esch($this->options['plural']) : $thesis->api->strings['comment_plural']));
}

Now we will return the number of comments and our singular and plural terms while maintaining the ability to change them via the boxes options.

Thesis 2 Tutorials

About the Author

Matthew Horne

Matthew Horne is an Optimization Specialist whose passion lies in making the web a faster and more efficient place. He has been fighting an uphill battle to change the minds of the masses.

2 comments… add one

  • Richard B. January 16, 2014, 4:08 pm

    Thanks for the helpful tip.

    Is there a way to add comment pagination? When dozens of comments have been left users are left with flipping through the pages one-by-one. It would be better if they could select a specific page number or jump to the last page.

    • Matthew Horne January 17, 2014, 5:42 am

      There will be a way but it would need to be a custom box.

Leave a Comment

Current ye@r *