• Resolved jazak

    (@jazak)


    How can i display posts per daily view count but all time comments at the same time ?

    I am using the block element and when i set the time range to last 24 hours to show posts based on that it also shows only the comment number in this time range when i enable show comments .

    How can i show all time comments but only posts from this time range

    thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @jazak,

    Well, for that you’ll need to modify the HTML output of the popular post list so you can include total comments count instead of the comments count from the selected time range.

    Follow these steps:

    #1 Edit your Popular Posts block and make sure that the “Use Custom HTML Markup” option is enabled. You should be seeing something like this:

    #2 Change the “Post HTML Markup” field from this:

    <li>{thumb} {title} <span class="wpp-meta post-stats">{stats}</span></li>

    into this:

    <li>{thumb} {title} <span class="wpp-meta post-stats">{views_copy} | {total_comments_copy}</span></li>

    {total_comments_copy} is a custom Content Tag that we’re going to create on the next step to display the total amount of comments.

    #3 Add this code snippet to your theme’s functions.php file:

    <?php
    /**
     * Parses custom content tags in WordPress Popular Posts.
     *
     * @param  string  $html    The HTML markup from the plugin.
     * @param  integer $post_id The post/page ID.
     * @return string
     */
    function wpp_parse_tags_in_popular_posts($html, $post_id) {
    
        // Replace custom content tag {total_comments_copy} with
        // the actual comments count copy
        if ( false !== strpos($html, '{total_comments_copy}') ) {
            // Get comments count
            $comments_count = get_comment_count($post_id);
    
            // Comments copy
            $comments_copy = sprintf(
                _n('%s comment', '%s comments', $comments_count['all'], 'wordpress-popular-posts'),
                $comments_count['all']
            );
    
            // Replace {total_comments_copy} with the actual tags
            $html = str_replace('{total_comments_copy}', $comments_copy, $html);
        }
    
        return $html;
    
    }
    add_filter('wpp_parse_custom_content_tags', 'wpp_parse_tags_in_popular_posts', 10, 2);

    If everything went well you should see now the total comments count on your popular posts list.

    You may need to tweak this code a bit as this was just an example.

    If you have any comments and/or questions don’t hesitate to ask.

    Thread Starter jazak

    (@jazak)

    it works, thanks

    Can i also link directly to the comment section of a posts when someone clicks on the comment number?

    Plugin Author Hector Cabrera

    (@hcabrera)

    Yeah, but the actual link will vary depending on your theme. You could do something like this:

    <a href="{url}#comments">{total_comments_copy}</a>

    Replace #comments with the actual anchor tag that your theme uses to link directly to the comments section.

    Thread Starter jazak

    (@jazak)

    ok thanks it works

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Posts per daily view count all time comments’ is closed to new replies.