Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

There is an option in the admin settings allowing you to define how many comments should be listed before creating a new page for the next ones. I would like to have the same number of comments for all my posts unless it belongs to one specific category (where I would like to set a different number of comments before pagination).

How can I do that?

share|improve this question
    
I asked this question many times and never got an answer. Is it impossible to achieve or am I not clear about the issue? –  Bachir Messaouri Nov 20 '12 at 6:59

1 Answer 1

This have several components to it - what option itself holds and how value from it is stashed away and reused by various pieces of core code.

I am not sure this is perfect, but my quick take would be:

new Adjust_Comments_Per_Page( 10, 'years', 'category' );

class Adjust_Comments_Per_Page {

    private $amount;
    private $term;
    private $taxonomy;

    /**
     * @param int    $amount
     * @param string $term
     * @param string $taxonomy
     */
    function __construct( $amount, $term, $taxonomy ) {

        $this->amount   = $amount;
        $this->term     = $term;
        $this->taxonomy = $taxonomy;

        add_action( 'template_redirect', array( $this, 'template_redirect' ) );
    }

    function template_redirect() {

        global $wp_query;

        if ( is_single() && has_term( $this->term, $this->taxonomy ) ) {

            $wp_query->set( 'comments_per_page', $this->amount );
            add_filter( 'pre_option_comments_per_page', array( $this, 'pre_option_comments_per_page' ) );
        }
    }

    /**
     * @return int
     */
    function pre_option_comments_per_page() {

        return $this->amount;
    }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.