WordPress.org

Ready to get started?Download WordPress

Forums

single_cat_title() wont work when using comment_count (5 posts)

  1. destrones
    Member
    Posted 1 year ago #

    Hi,

    i edit archive.php so it sorts posts by comment count in certain categories. However, by doing this neither single_cat_title() or category_description() show the category name/description. Why is that? This is my code:

    <?php if(is_category( array(25))) { query_posts(array('orderby' => 'comment_count')); } elseif(is_category( array(96))) { query_posts(array('orderby' => 'comment_count', 'posts_per_page' => '20')); } ?>

    This goes to the very beginning of archive.php.

    Could you please give me a hand here?

    Thank you

  2. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    your custom query seems to 'destroy' the category archive information.

    try:

    <?php global $wp_query; if(is_category( array(25))) { $args = array_merge( $wp_query->query, array( 'orderby' => 'comment_count' ) ); query_posts( $args ); } elseif(is_category( array(96))) { $args = array_merge( $wp_query->query, array( 'orderby' => 'comment_count', 'posts_per_page' => '20') ); query_posts( $args ); } ?>

    http://codex.wordpress.org/Function_Reference/query_posts#Preserving_Existing_Query_Parameters

  3. destrones
    Member
    Posted 1 year ago #

    Hi,

    thank you but it didnt work. The name and the description do appear now but the posts are not arranged by comment count. I put the code right after <?php if (have_posts()) : ?> should i put it somewhere else?

    Thank you.

  4. alchymyth
    The Sweeper & Moderator
    Posted 1 year ago #

    the location seems ok;
    also, in my testsite, the code does what it is supposed to do

    - a possible reason that it is not working for you, might be some interference with other codes or plugins;

    have you tried to deactivate all plugins to see if that helps?

  5. destrones
    Member
    Posted 1 year ago #

    I think it may be the GD Star rating plugin but i cant try deactivating it because it will delete all my settings.

Topic Closed

This topic has been closed to new replies.

About this Topic