1 (edited by osman 2011-12-28 17:32:43)

Topic: How to display only the last 10 ads?

Hello,

latest_frontpage.tpl displays all ads from database sorting them by ad_date by default.
I think, sorting all ads causes slowing the front page. I want to display only last 10 ads in frontpage. When I do this, I will remove next - Prev buttons.

These are the line from latest_frontpage.tpl :
Could you please tell me how to control foreach loop for the last 10 ads?


...
{foreach item=ad from=$ads} 
<tr class="{cycle values=",alt"}">
    <td class="category">{$ad.CATEGORYNAME}</td>
    <td class="pointer"><a href="{$ad.LINK}" title="{$ad.TITLE|escape}">
    {if $ad.SPECIAL}<b>{/if}{$ad.TITLE|truncate:35:"...":true}{if $ad.SPECIAL}</b>{/if}</a></td>
    {foreach item=extraval from=$ad.EXTRA_VALUES}
        <td><nobr>{$extraval|truncate:20:"...":true}</nobr></td>
    {/foreach}
    <td>{$ad.EXPIREDATE}</td>
     <!-- <td>{if $ad.VENDOR_URL}<img src="{$ad.VENDOR_URL}" height="30" />{/if}</td> -->
    <td>{$ad.GRADE}</td>
    <td>{$ad.IMAGEYESNO}</td>
</tr>
{/foreach} 
...




Thank you for your help.

Osman

Thumbs up Thumbs down

Re: How to display only the last 10 ads?

Hello,

you have to set in opt_inc.php:

$set_frontpage_override = "10";

mysql is working very fast so your site doesn`t slowing down with 10 or 50 ads an frontpage.
Slowing down caused through facebookbutton or other buttons or adsense.

Re: How to display only the last 10 ads?

Dear tomzp,

Thank you. But I didn't mean the $set_frontpage_override = "10" option in opt_inc.php.

Script displays last ten ads on frontpage, if the $set_frontpage_override = 10.
But script sorts thousands of ads in the database.  And displays all records on pages one after the other. If there are 5000 ads, it displays 500 pages via Next button.

I need a control in latest_frontpage.tpl.
{foreach item=ad from=$ads} loops until the end of database, this is the slowness I meant on frontpage. I only want last ten records and exit the loop.

Thumbs up Thumbs down

Re: How to display only the last 10 ads?

The loop stops by MySQL so this doesn't make the script slow. Are you worried about speed?

Re: How to display only the last 10 ads?

AlexG wrote:

The loop stops by MySQL so this doesn't make the script slow. Are you worried about speed?

I mean the loop continues until the end of database, am I right? I wanted to display only 10 last ads on frontpage. Is there a control for this in the loop?

I use PRICE extrafield and it causes slowness in ad lists especially in latest ads on frontpage. Because when I uncheck "Include in lists?" option in extrafields, my frontpage is starting to fly. This proves that even one extrafield (LA_PRICE) causes slowness when there are more than 3000 ads.

By the way, Alex. Is the price field still an extrafield in v7.6? Why is the price field an extrafield instead of putting it in ad table directly? And was it too complicated to put locations in ad table directly instead of putting only region code? Thus, we could display locations in ad lists by default.

And another question... can we display locations in ad lists by default in v7.6? This is the mysterious question which nobody can answer me? smile

Thank you

Thumbs up Thumbs down