• Resolved owenoneill

    (@owenoneill)


    Hi I’m looking at making the post count appear via my posts page in my query/loop but it doesn’t show and I can’t seem to work out why:

    <?php query_posts('posts_per_page=1&orderby=date&order=DESC&cat=-1458'); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <div class="switch">
            <div class="avg_words">
                <a href="<?php the_permalink() ?>">
    	        <?php echo the_post_thumbnail('si-images'); ?>
                </a>
            </div>
         <div class="avg_num">
             <span><?php if(function_exists('the_views')) { the_views(); } ?></span>
              <a href="<?php the_permalink() ?>">
    	        <?php echo the_post_thumbnail('si-images'); ?>
               </a>
         </div>
      </div>
    <?php endwhile; endif; ?>

    Any ideas on why this isn’t loading?

    https://wordpress.org/plugins/wp-postviews/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Lester Chan

    (@gamerz)

    That looks correct, I can only think of the plugin is not being activated and hence the_views() function is not being called.

    Thread Starter owenoneill

    (@owenoneill)

    I thought it should be correct as well, but it is not working, as you can see the value should be inside the span, but it is not working, please check the link below.

    http://universitycompare.com/student-news-2/

    Also, this is not marked as resolved as the issue isn’t fixed.

    Plugin Author Lester Chan

    (@gamerz)

    Try just <?php the_views(); ?> to see if it works

    If it still doesn’t try <?php var_dump( intval( get_post_meta( get_the_ID(), 'views', true ) ) ); ?> to see if anything is printed out.

    Thread Starter owenoneill

    (@owenoneill)

    Hey Lester, the Intval works and prints the correct number views, as recorded but any of ‘the views’ doesn’t work. But yet it works on the same query copy and pasted. Why would this be?

    Plugin Author Lester Chan

    (@gamerz)

    To be hoest I have no idea. Have not come across this issue before. Because basically the_views function is just a wrapper for that

    Thread Starter owenoneill

    (@owenoneill)

    Do you know a way of removing the printed letters in PHP so i can then just have the number left and then use this as a way of displaying the views, that way I get the results I want, I swear there is a character remove thing in PHP? – I’m just a newbie so I’m not too it.

    I appreciate your help so far by the way buddy.

    Plugin Author Lester Chan

    (@gamerz)

    Sorry I don’t get what you mean.

    <?php $test = intval( get_post_meta( get_the_ID(), 'views', true ) ); echo $test; ?> will give you just the raw numbers

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Show View Count in Query/Loop’ is closed to new replies.