• Resolved supertrooper2

    (@supertrooper2)


    The shortcode used on our website is as follows:

    <h3>Top-Viewed Posts Last 30 Days</h3>
    <?php echo do_shortcode('[google_top_content pageviews="5" titleremove= "Focusing on Wildlife" contentfilter="post" catfilter="3173" number="10" showhome="no" time="2628000"]'); ?>

    The list of top-viewed posts looks good but there are no page load numbers at the end of each line.

    Is there an error in the shortcode?

    Thanks for your help.

    https://www.ads-software.com/plugins/google-analytics-top-posts-widget/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter supertrooper2

    (@supertrooper2)

    Hi Justin

    A couple of years ago you helped me to get GATCW working in conjunction with GAD using the following two pieces of code:

    1) Installed in the single.php file

    <?php echo do_shortcode('[google_top_content pageviews="5" titleremove= "Focusing on Wildlife" contentfilter="post" catfilter="3173" number="10" showhome="no" time="2628000"]'); ?>

    2) Installed in the functions.php file:

    add_filter( 'gtc_pages_filter', 'gtc_add_viewcount_title' );
    function gtc_add_viewcount_title( $pages ) {
    
        if ( !$pages )
            return false;
        // loop through the pages
        foreach ( $pages as $key => $page ) {
            // and add the page count to the title value
            $pages[$key]['children']['value'] = $pages[$key]['children']['value'] . ' ['. $pages[$key]['children']['children']['ga:pageviews'] .' Views]';
        }
        return $pages;
    }

    Now after replacing GAD by “Google Analytics by Yoast”, the 10 top posts are still being listed correctly but the page count is not showing after each post title.

    Do I need to change something in either of the 2 pieces of code to get the page counts to show up?

    Please advise

    Plugin Author Justin Sternberg

    (@jtsternberg)

    Hey, yah, those parameters have changed a bit w/ the new plugin integration. We actually have a handy title filter now as well. To accomplish what you’re asking, you would use this (functions.php) snippet instead:

    function gtc_page_title_add_viewcount_total( $title, $analytics ) {
    
    	if ( isset( $analytics['value'] ) ) {
    		// Add the page view count to the title value
    		$title .= ' ['. absint( $analytics['value'] ) .' Views]';
    	}
    
    	return $title;
    }
    add_filter( 'gtc_page_title', 'gtc_page_title_add_viewcount_total', 10, 2 );

    Thread Starter supertrooper2

    (@supertrooper2)

    Hi Justin

    The top 10 posts with view count works perfectly now after updating the functions.php file and can be seen in action on the following typical post (scroll down to the bottom of the page to see the post rankings):

    https://focusingonwildlife.com/news/promoting-wildlife-conservation/

    I have added an addendum to the positive review. Thanks once again for responding so quickly with the coding solution to this issue.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    Awesome!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Problem using shortcodes’ is closed to new replies.