Support » Plugin: Google Analytics Top Content Widget » Top Viewed Content – Couple of Tweeks Needed

Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Author Justin Sternberg

    (@jtsternberg)

    The styling of the output is all handled by your theme. Some themes neglect to add styling for the html ol (ordered list vs ul, unordered list) element, and that appears to be the case with your theme. The numerical display can all be handled through your theme stylesheet.

    Including page hits is a nice idea and something I’ll look into adding in a future version of this plugin.

    Thread Starter supertrooper2

    (@supertrooper2)

    Justin, I also tried to add the “Top Viewed Content” into my posts using the following code:

    [google_top_content pageviews=5 number=10 showhome=no time=2628000 timeval=2]

    The problem is that several pages showed up in the list including my top page: http://focusingonwildlife.com/news/ – My questions are

    1) how to limit the top-viewed content to posts only?
    2) how to exclude specific posts?
    3) how to include a title “Top-Viewed Posts” above the list with <h5>?

    Thanks in advance for your advice.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    1) limit content to posts:
    contentfilter=post (or pages: contentfilter=page)

    2) exclude specific post/page/content:
    postfilter=25 (use post ID, multiple exclusions doesn’t work in the shortcode)

    3) Just add the h5 heading via the WordPress post edit screen above the shortcode

    Plugin Author Justin Sternberg

    (@jtsternberg)

    All of the documentation for the optional filters are on the plugin page: http://wordpress.org/extend/plugins/google-analytics-top-posts-widget/

    Thread Starter supertrooper2

    (@supertrooper2)

    Justin, I have adapted my shortcode based on your suggestions to:

    [google_top_content pageviews=5 contentfilter=post postfilter=23238, 26897,20233 number=10 showhome=no time=31536000 timeval=2]

    The “contentfilter” works fine but the “postfilter” doesn’t seem to work with multiple posts. Is there a way to filter out more than one post?

    The “time=31536000” is equivalent to 1 month, so I’m a little confused what the purpose of the “timeval” is?

    Is there any way to filter out specific authors. e.g. posts published by myself under the “admin” name?

    Hoping you can help me on the above questions.

    Thanks in advance.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    You’re right, as I mentioned, filtering multiple posts is not supported by the shortcode at this time. If you need to do something like that, I would suggest you filter by a category or exclude a category. The same goes for filtering by author.

    Your right, the timeval is superfluous in the shortcode.

    Thread Starter supertrooper2

    (@supertrooper2)

    Justin, brilliant suggestion – the “catfilter” works perfectly when added into the html editor of a post. My shortcode is now as follows:

    <h3>Explore These Popular Posts</h3>
    [google_top_content pageviews=5 contentfilter=post postfilter=30681 catfilter=3173 number=20 showhome=no time=31536000]

    Please bear with me and advise on the following questions:

    1) where should the shortcode be added into a theme into have the list show up at the bottom of each post below the comments?

    2) is there a way to get the number of page views to show up in brackets after each item in the list?

    Hoping you have an answer on these issues.

    Thanks again for your advice.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    1) I’d use the WordPress function do_shortcode( '[YOURSHORTCODE]' );
    2) There are many filters in the plugin for ultimate flexibility. To do what you’re requesting, you can put this code in your functions 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;
    }

    Thread Starter supertrooper2

    (@supertrooper2)

    Justin

    1) # page views – the second piece of code works great when added to the theme’s “functions.php” file.

    2) shortcodes for all posts – I also tried adding the following code to the bottom of the theme’s “functions.php” file:

    <?php do_shortcode('<h3>Explore These Popular Posts</h3>[google_top_content pageviews=5 contentfilter=post number=10 showhome=no time=2628000]'); ?>
    }

    Please advise what I’ve done wrong.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    <h3>Explore These Popular Posts</h3> is not part of the shortcode and should not be included. The code won’t do anything if added to the functions file. You’ll need to place it in the template file where you want it to appear.

    <?php echo do_shortcode( '[google_top_content pageviews=5 contentfilter=post number=10 showhome=no time=2628000]' ); ?>

    Thread Starter supertrooper2

    (@supertrooper2)

    Justin, after trial and error I succeeded by adding the following code to my theme’s “single.php” file:

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

    Note the quotation marks (“”) around all of the filter values. Without the quotation marks it doesn’t work.

    Thread Starter supertrooper2

    (@supertrooper2)

    Justin, many thanks for your outstanding support in getting this excellent plugin to function.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    Ok, glad to help.

    Thread Starter supertrooper2

    (@supertrooper2)

    Justin, one more question on this topic if I may.

    I realized that the modification to the single.php file in my theme’s folder is lost when the theme is updated. Therefore I tried to add the modified single.php file to the child folder of my theme.

    Unfortunately this doesn’t seem to work. Please advise how to set-up the shortcode via the child folder.

    Thanks in advance for your advice.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    Did you create the child theme specifically for this purpose, or were you already using a child theme?

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘Top Viewed Content – Couple of Tweeks Needed’ is closed to new replies.