Advertisement:

Author Topic: Most Viewed Ads  (Read 55442 times)

przemo

  • Jr. Member
  • **
  • Posts: 81
  • Director ;)
Most Viewed Ads
« on: February 04, 2012, 02:23:42 pm »
Most Viewed Ads

Hello!
How to do it on your website to display most viewed active ads in my website?

My site: http://www.jasielskie.org.pl/

Please help, please code.

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: Most Viewed Ads
« Reply #1 on: February 06, 2012, 12:16:48 pm »
Hi przemo,


There's a table with stats and views of all ads. It's not very difficult to gather data from that table, unfortunately I don't have the time to do it right now, but maybe some other user could help you.


Thanks

Jesse

  • Hero Member
  • *****
  • Posts: 631
  • Out of my mind, back in 5 minutes
Re: Most Viewed Ads
« Reply #2 on: February 06, 2012, 12:24:15 pm »
I've been looking into doing this today. I'll continue to try and get a plugin together as time permits (new baby is keeping me quite busy!!).

przemo

  • Jr. Member
  • **
  • Posts: 81
  • Director ;)
Re: Most Viewed Ads
« Reply #3 on: February 06, 2012, 12:42:10 pm »
Jesse, congratulations!

Expected at the code from someone. Thank you.

Jesse

  • Hero Member
  • *****
  • Posts: 631
  • Out of my mind, back in 5 minutes
Re: Most Viewed Ads
« Reply #4 on: February 07, 2012, 05:59:13 am »
I've made some good progress on this. Although this may not be so helpful for "non-programmers", this code will determine the top 5 most viewed active items. This code will only show the Item ID and the total number of views. It's only the "core" function of the plugin I'm working on. This is far from being finished, but I figured I'd throw it out there for anyone wanting to work on a similar project. But no worries otherwise, I'll have a easy-to-use plugin done soon!!   :)

Code: [Select]
<?php
    $num_ads 
5// SETS HOW MANY POPULAR ADS TO DISPLAY

    
$conn getConnection();
    
$results=$conn->osc_dbFetchResults("SELECT fk_i_item_id, i_num_views FROM %st_item_stats ORDER BY fk_i_item_id ASC"DB_TABLE_PREFIX);

    if(
count($results)>0){

foreach($results as $result){
    $view_count[$result['fk_i_item_id']] += $result['i_num_views']; // Add-up all item views stored in database
}

arsort($view_count); // sorts array by highest number of item views first

foreach($view_count as $item_id=>$views)
{
    $result=$conn->osc_dbFetchResult("SELECT b_active FROM %st_item WHERE pk_i_id = %d"DB_TABLE_PREFIX$item_id); //Get active status of item

    if($result['b_active']==1){ //if active...
        echo 'Item ID: '.$item_id.' Views: '.$views.'<br>'// display only if item is active
$index++;
    
    }
    if($index>=$num_ads) break; // limit number of ads to display
}
    } else echo 
'No Results.';
?>

przemo

  • Jr. Member
  • **
  • Posts: 81
  • Director ;)
Re: Most Viewed Ads
« Reply #5 on: February 07, 2012, 01:01:33 pm »
Hello,
My computer science made ​​it so, but it displays all ads, and I want to display only those active.


                        
Code: [Select]
?>
                                <li class="pop">
                                <span style="width: 273px; display:block; position: relative; top: 15px; margin:0 auto;">
                                <?php echo osc_item_is_premium() ? 'Ogłoszenie wyróżnione' $class $class ?>
                                   
                                        <?php if( osc_item_is_premium() ) { ?>
                                        <?php ?>
                                        <?php $title $displayX[2];  $title substr($title020); ?>
                                        <h3 style="color:#666666"><a href="<?php echo osc_sanitizeString($CatDisplayX[0]).'/'.osc_sanitizeString($title).'_'.$display[0]; ?>
<?php //osc_item_url('index.php?page=item&id='.$display[0]); ?>"><?php echo $title.'...'?></a></h3>
                                        <p style="color:#F00">CENA: <?php if( osc_price_enabled_at_items() ) { if($display[5]!==NULL) echo $display[5].".00 PLN"; else echo "Sprawdź";  } ?></p>
                                        <?php $string $displayX[3];  $string substr($string0130); ?>
                                        <p style="color:#4f4f4f; text-align:justify"><?php echo osc_highlight(strip_tags($string))."..." ?></p>
                                        </span>
             </li>
                                <?php ?>
</ul></div>

freeeadz

  • Newbie
  • *
  • Posts: 42
  • E-Adz
Re: Most Viewed Ads
« Reply #6 on: February 07, 2012, 06:58:04 pm »
Dear Jesse,

Thanks for your code. Its good but it will be highly appreciated if it will display 'Title' (s_title) and Number of Views not the item id. Also it will look great if it has a link to that particular item details.

Regards

Jesse

  • Hero Member
  • *****
  • Posts: 631
  • Out of my mind, back in 5 minutes
Re: Most Viewed Ads
« Reply #7 on: February 07, 2012, 07:16:27 pm »
Hi Freeadz,

As explained above, it is being developed into a complete plugin, which is nearly complete. You'll be able to use existing OSClass Helpers to display any of the information you'd like, including title, description, URL's (links), pictures, price, etc.  :)

Hopefully I should have this done sometime today.

freeeadz

  • Newbie
  • *
  • Posts: 42
  • E-Adz
Re: Most Viewed Ads
« Reply #8 on: February 07, 2012, 07:27:12 pm »
Dear Jesse,

Thanks for your prompt response.

I am waiting for the subjected plugin.


Regards

Jesse

  • Hero Member
  • *****
  • Posts: 631
  • Out of my mind, back in 5 minutes
Re: Most Viewed Ads
« Reply #9 on: February 08, 2012, 05:21:12 am »
Updated: Works with Osclass 3.0.2


Hi all,

I've got a working plugin that's ready to be tested. It's called, Popular Ads.

To use the plugin, there are two functions that must be called before and after your "most popular ads" section. The format is like this:

Basic structure:

Code: [Select]
<?php popular_ads_start(); ?>

    .... write your code here ....

<?php popular_ads_end(); ?>

The above code will basically load all data for the "popular ads" into a OSClass array, which can be accessed by the standard OSClass Helper functions, here: http://wiki.osclass.org/HItems.php



Basic Example:
Here is a simple loop that will cycle through the entire array and display some information:
If you're wanting to try this plugin, this is a GREAT example to try!  :D
Code: [Select]
<?php popular_ads_start(); ?>
    <?php if( osc_count_items() > 0) {
        while ( 
osc_has_items() ) {
            echo 
'Item ID: '.osc_item_id().' Title: '.osc_item_title().' Views: '.osc_item_views().'<br>';
        }
    }
    
?>

<?php popular_ads_end(); ?>


Complete Working Example:

This is a complete, working example taken directly from the "Latest Items" section on the Main page (I used BCute theme):
Code: [Select]
<?php popular_ads_start(); ?>
    <div class="pop_ads">
<h1><strong><?php _e('Most Popular Ads''bcute') ; ?></strong></h1>
    <?php if( osc_count_items() == 0) { ?>
<p class="empty"><?php _e('No Popular Ads''bcute') ; ?></p>
    <?php } else { ?>
<table border="0" cellspacing="0">
    <tbody>
<?php $class "even"?>
<?php while ( osc_has_items() ) { ?>
<tr class="<?php echo $class. (osc_item_is_premium()?" premium":"") ; ?>">
<?php if( osc_images_enabled_at_items() ) { ?>
    <td class="photo">
<?php if( osc_item_is_premium() ){ ?>
<div id="premium_img"></div>
<?php }?>
<?php if( osc_count_item_resources() ) { ?>
    <a href="<?php echo osc_item_url() ; ?>">
<img src="<?php echo osc_resource_thumbnail_url() ; ?>" width="75" height="56" title="" alt="" />
    </a>
<?php } else { ?>
    <a href="<?php echo osc_item_url() ; ?>">
<img src="<?php echo osc_current_web_theme_url('images/no_photo.gif') ; ?>" alt="" title=""/>
    </a>
    <?php ?>
    </td>
<?php ?>
    <td class="text">
<div class="price-wrap"><span class="tag-head"></span><p class="price"><?php if( osc_price_enabled_at_items() ) echo osc_item_formated_price() ; ?></p></div>
<h3><a href="<?php echo osc_item_url() ; ?>"><?php echo osc_item_title() ; ?></a></h3>
<p><strong><?php if( osc_price_enabled_at_items() ) { echo osc_item_formated_price() ; ?> - <?php } echo osc_item_city(); ?> (<?php echo osc_item_region();?>) - <?php echo osc_format_date(osc_item_pub_date()); ?></strong></p>
<p><?php echo osc_highlightstrip_tagsosc_item_description() ) ) ; ?></p>
    </td>                                       
</tr>
<?php $class = ($class == 'even') ? 'odd' 'even' ?>
<?php ?>
    </tbody>
</table>
<?php if( osc_count_latest_items() == osc_max_latest_items() ) { ?>
    <p class="see_more_link"><a href="<?php echo osc_search_show_all_url();?>"><strong><?php _e("See all offers"'modern'); ?> &raquo;</strong></a></p>
<?php ?>
    <?php ?>
    </div>
<?php popular_ads_end(); ?>

Within the plugin folder is a CSS file that should have all the needed CSS for the above example. Feel free to modify the CSS file for your own styling and format.



Set the number of ads to display

In the admin panel, there is a Configuration page where you can set the desired number of popular ads to display.



Other notes:

This is a work in progress, which means there could be bugs, snakes, alligators, bears and sheep hiding inside this plugin. Please feel free to report anything you feel isn't working correctly. It's possible that some Helper functions will not work. That is because I've not included every bit of item data into the array (I did my best to include ALL important data). Should this be the case, it's an easy fix.  :)


Good luck my fellow OSClass'ers!  8)
« Last Edit: January 11, 2013, 11:19:21 pm by Jesse »

trains58554

  • Osclass contributor
  • Hero Member
  • *****
  • Posts: 3642
  • osCanyon, the class of Osclass
Re: Most Viewed Ads
« Reply #10 on: February 08, 2012, 05:34:31 am »
Hi Jesse,

I just tried this and I found some sheep they are very white and cute. :) In all seriousness I did not find any bugs it seems to work just fine. Very nice plugin.

Jay

PS I am glad I did not find any snakes or alligators. :)

Jesse

  • Hero Member
  • *****
  • Posts: 631
  • Out of my mind, back in 5 minutes
Re: Most Viewed Ads
« Reply #11 on: February 08, 2012, 05:53:55 am »
Haha... thanks for trying it Jay! And glad nothing bit you!  ;D

This plugin was a great learning experience for me (as is every project I work on!). And if anyone else can benefit from it, even better!

ingo

  • Full Member
  • ***
  • Posts: 216
Re: Most Viewed Ads
« Reply #12 on: February 08, 2012, 09:19:14 am »
Hi,

thank you for this plugin,

again one "WOW" work from you  :)

regards

Jesse

  • Hero Member
  • *****
  • Posts: 631
  • Out of my mind, back in 5 minutes
Re: Most Viewed Ads
« Reply #13 on: February 08, 2012, 09:35:20 am »
Thanks Ingo!


UPDATE: I've finished the plugin, at least the planned elements of it. I've added an admin panel, including a configuration page (for setting the number of popular ads to display), and also a Help page, which outlines pretty much what I've already covered above.

Download the latest version (1.0) from the link in my previous post.  :)

freeeadz

  • Newbie
  • *
  • Posts: 42
  • E-Adz
Re: Most Viewed Ads
« Reply #14 on: February 08, 2012, 10:18:49 am »
Thanks Jesse for your efforts for the plugin.

I have used it on my site on sidebar........with bCute theme. It was not looking nice so I made some changes to the code as below. now you can see the attached image for the changes affected.

Code: [Select]
<div class="box location">
<h3><strong><?php _e("Most Popular Ads"'bcute'); ?></strong></h3>
<?php popular_ads_start(); ?>
    <div class="pop_ads">
    <?php if( osc_count_items() == 0) { ?>
<p class="empty"><?php _e('No Popular Ads''bcute') ; ?></p>
    <?php } else { ?>
<table border="0" cellspacing="0">
    <tbody>
<?php $class "even"?>
<?php while ( osc_has_items() ) { ?>
<tr class="<?php echo $class. (osc_item_is_premium()?" premium":"") ; ?>">
<?php if( osc_images_enabled_at_items() ) { ?>
    <td class="photo">
<?php if( osc_item_is_premium() ){ ?>
<div id="premium_img"></div>
<?php }?>
<?php if( osc_count_item_resources() ) { ?>
    <a href="<?php echo osc_item_url() ; ?>">
</a>
<?php } else { ?>
    <a href="<?php echo osc_item_url() ; ?>">

    </a>
    <?php ?>
    </td>
<?php ?>
    <td class="text">
<a href="<?php echo osc_item_url() ; ?>"><?php echo osc_item_title() ; ?></a>
<?php echo "(".osc_item_views()." Views)"?>
    </td>                                       
</tr>

<?php ?>
    </tbody>
</table>
<?php if( osc_count_latest_items() == osc_max_latest_items() ) { ?>
    <p class="see_more_link"><a href="<?php echo osc_search_show_all_url();?>"><strong><?php _e("More Ads"'modern'); ?> &raquo;</strong></a></p>
<?php ?>
    <?php ?>
    </div>
<?php popular_ads_end(); ?>
</div>

Anyways it is a great plugin. Thanks once again Jesse.