Tagged: 

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #11071

    1. The slider by default displays the most recent posts from a selected category. Is it possible to change this to posts with most comments in a given category? Ideally… posts with the most comments in the last 30 days?

    2. Can a category-specific slider be displayed on Category pages? This would show the latest posts from each individual category.

    #70418

    1) This should be possible. Select all categories for the slider and open up index.php. Search for following line:

    $additional_loop = new WP_Query("cat=".$k_option['mainpage']['feature_cats_final']."&posts_per_page=".$k_option['mainpage']['feature_count']);

    and replace it with:

    $additional_loop = new WP_Query("cat=".$k_option['mainpage']['feature_cats_final']."&orderby=comment_count&posts_per_page=".$k_option['mainpage']['feature_count']);

    2) Yes – this is be possible but it requires some major code adjustments which are beyond the scope of this support forum.

    #70419

    Hi dude,

    Thanks heaps. Regarding item 1, can the code be modified to only include posts published in the past 30 days?

    #70420

    Hi jebz,

    Try replacing what you’ve added so far with:

    // Create a new filtering function that will add our where clause to the query
    function filter_where( $where = '' ) {
    // posts in the last 30 days
    $where .= " AND post_date > '" . date('Y-m-d', strtotime('-30 days')) . "'";
    return $where;
    }

    add_filter( 'posts_where', 'filter_where' );
    $additional_loop = new WP_Query("cat=".$k_option['mainpage']['feature_cats_final']."&orderby=comment_count&posts_per_page=".$k_option['mainpage']['feature_count']);
    remove_filter( 'posts_where', 'filter_where' );

    I’ve not tested it live but it should work with the WP_Query from Peter.

    Regards,

    Devin

    #70421

    Hi Devin, just to be certain – do I *add* your code underneath Dude’s code, or *replace* it? Not quite sure. Thanks!

    #70422

    Hi!

    You need to replace it because it already contains the code line I posted above.

    Regards,

    Peter

    #70423

    Thanks! I did that and all seems to be working.

    #70424

    Could I just confirm that this displays the posts with the most comments from ALL categories? Thanks :-)

    #70425

    No, it will display posts of the selected categories (which you chose in the backend). You can adjust one line in the code Devin posted above – instead of:

    $additional_loop = new WP_Query("cat=".$k_option['mainpage']['feature_cats_final']."&orderby=comment_count&posts_per_page=".$k_option['mainpage']['feature_count']);

    use:

    $additional_loop = new WP_Query("orderby=comment_count&posts_per_page=".$k_option['mainpage']['feature_count']);

    All categories will be displayed in the slider after this code mod but it will also “break” the backend options regarding the frontpage slider categories.

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Some slider questions…’ is closed to new replies.