How To Display Item Views Counter For Each Ad Listing On OSCLASS Website?


osclass item as listing view counter

If you are using OSCLASS for a classified ad listing website and if you would like to display the number of times each ad listing has been viewed, there in this post we are going to discuss just that. Is it important to display item view count? Depends. But it may be a small feature but it may also help administrators as well as visitors know how popular the ad is with respect to others. In this post, we shall see how to add  views counter for each listing on OSCLASS website.


For the sake of this example, we shall display item view counter on the items page where a single ad listing is viewed.

  • The function we need to display item view count is: osc_item_views()
  • These functions are defined in ./oc-includes/osclass/helpers/hItems.php

Steps to add item views counter for each listing on OSCLASS website:

1) Login to your webhost and use your file manager to navigate to the osclass installation folder. If you have FTP access, you can also download a copy, edit it and upload.
2) Under YOURSITE\oc-content\themes find item.php
3) Open the item.php to edit
4) Find a suitable place where you would like to display the item view count and paste the code:
<?php echo osc_item_views();

But this will display only the numbers. So you may add some text and formating as given below:

<!--item views -->
        <div class="items_views_count">
            <p> Item viewed <b> <?php echo osc_item_views(); ?> </b> times.</p>
        </div> 


Explanation:
<!--item views --> : This is just a comment

<div class="items_views_count"> : included a div with a class so that we can add style it using CSS if required

<p> Item viewed <b> <?php echo osc_item_views(); ?> </b> times.</p> : 
Added text "Item viewed X times, where X is BOLD

5) Save the item.php edited

If you used FTP to download the file to edit, upload to the same directory from where you download, which should be: \public_html\oc-content\themes\YOURTHEME\item.php

Open an item page from your website and you should be able to see the number of items the ad listing has been viewed.

How To Display Item Views Counter For Each Ad Listing On OSCLASS Website







Comment with Facebook

Comments

  1. Please how can I add this to be display in mobile version in style.css

    ReplyDelete
    Replies
    1. This solution should appear on mobile too.
      The file to edit is: \public_html\oc-content\themes\YOURTHEME\item.php

      Or are you using a different theme for mobile?
      Even if so, still you may be able to achieve this by editing the item page file I suppose.

      Delete

Post a Comment