ThemeShaper Forums » Thematic

[closed]

Post views in post footer

(7 posts)
  • Started 3 years ago by newb
  • Latest reply from helgatheviking
  • This topic is resolved
  1. newb
    Member

    Hello,

    //noob question starts here

    I need to insert number of post views to post footer. I'm trying to use wp postviews for it:

    function childtheme_override_postfooter() {
    
    ....
    if (is_single()) {
    $postfooter = '<div class="entry-utility">' . childtheme_override_postfooter_posttags() . the_views() . childtheme_override_postfooter_postcomments();
    ....
    
    }

    But it gives me post views just after post content and before post footer.
    What am I doing wrong?
    //noob question ends here

    Posted 3 years ago #
  2. lol... love the //noob question brackets. :)

    the problem is likely that the_views() echos out its value instead of returns it. unfamiliar w/ that plugin, but is there a function to 'return' the value? maybe a 'get_the_views()' ?

    Posted 3 years ago #
  3. newb
    Member

    ;)

    You are absolutely right about echo.

    ### Function: Display The Post Views
    function the_views($display = true, $prefix = '', $postfix = '', $always = false) {
    	$post_views = intval(post_custom('views'));
    	$views_options = get_option('views_options');
    	if ($always || should_views_be_displayed($views_options)) {
    		$output = $prefix.str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $views_options['template']).$postfix;
    		if($display) {
    			echo apply_filters('the_views', $output);
    		} else {
    			return apply_filters('the_views', $output);
    		}
    	}
    	elseif (!$display) {
    		return '';
    	}
    }
    ### Function: Display Total Views
    if(!function_exists('get_totalviews')) {
    	function get_totalviews($display = true) {
    		global $wpdb;
    		$total_views = intval($wpdb->get_var("SELECT SUM(meta_value+0) FROM $wpdb->postmeta WHERE meta_key = 'views'"));
    		if($display) {
    			echo $total_views;
    		} else {
    			return $total_views;
    		}
    	}
    }
    Posted 3 years ago #
  4. then you probably want

    $postfooter = '<div class="entry-utility">' . childtheme_override_postfooter_posttags() . the_views(FALSE) . childtheme_override_postfooter_postcomments();
    Posted 3 years ago #
  5. newb
    Member

    Helga,

    Thank you!

    Posted 3 years ago #
  6. Hey guys, if I wanted to add this function to my blog running on a Thematic child theme, what would be the complete code to add to my functions file?

    Thanks

    Posted 2 years ago #
  7. probably:

    function kia_postfooter($postfooter){
    	if(function_exists('the_views')){
    		$postfooter = '<div class="entry-utility">'. the_views(false) . thematic_postfooter_postcategory() . thematic_postfooter_posttags() . thematic_postfooter_postconnect() . "</div><!-- .entry-utility -->\n";
    	}
    	return $postfooter;
    }
    add_filter('thematic_postfooter','kia_postfooter');

    but don't have the plugin

    Posted 2 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.