Loading


Advertisement:

Author Topic: [SOLVED] How to show latest ads with photos only on my home page.  (Read 326 times)

Syed

  • Full Member
  • ***
  • Posts: 171
I want help to show latest ads with photos only on my home page.

Here is the code that also include ads with no photos

Code: [Select]
<?php if( osc_count_latest_items() == 0) { ?>
    <div class="clear"></div>
    <p class="empty"><?php _e("There are no ads available at this moment."'bender'); ?></p>
<?php } else { ?>
    <?php
    View
::newInstance()->_exportVariableToView("listType"'latestItems');
    
View::newInstance()->_exportVariableToView("listClass"$listClass);
    
osc_current_web_theme_path('loop.php');
    
?>

    <div class="clear"></div>
    <?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 ads''bender') ; ?></strong></a>
        </p>
    <?php ?>
<?php ?>

I do not want changes in core files.

Regards
« Last Edit: October 14, 2017, 08:18:17 pm by Syed »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 994
Re: How to show latest ads with photos only on my home page.
« Reply #1 on: October 10, 2017, 07:43:26 pm »
Hi. Where else are they shown?

Syed

  • Full Member
  • ***
  • Posts: 171
Re: How to show latest ads with photos only on my home page.
« Reply #2 on: October 11, 2017, 08:48:13 am »
Only on home page.

Regards
« Last Edit: October 13, 2017, 09:27:28 am by Syed »

Syed

  • Full Member
  • ***
  • Posts: 171
Re: How to show latest ads with photos only on my home page.
« Reply #3 on: October 13, 2017, 09:26:48 am »
I found this piece of code in hItems.php in core but don't know how to use it.

Code: [Select]
View::newInstance()->_exportVariableToView('latestItems', $search->getLatestItems($total_latest_items, $options, $withPicture));
Regards,

teseo

  • Hero Member
  • *****
  • Posts: 5974
Re: How to show latest ads with photos only on my home page.
« Reply #4 on: October 13, 2017, 01:01:44 pm »
Hi,

This way:

Replace.

Code: [Select]
<?php if( osc_count_latest_items() == 0) { ?>

With:

Code: [Select]
<?php View::newInstance()->_exportVariableToView('latestItems'Search::newInstance()->getLatestItems(osc_max_latest_items(), array(), true));
 if( 
osc_count_latest_items() == 0) { ?>


Regards
« Last Edit: October 14, 2017, 06:26:24 pm by teseo »

Syed

  • Full Member
  • ***
  • Posts: 171
Re: How to show latest ads with photos only on my home page.
« Reply #5 on: October 13, 2017, 09:36:11 pm »
Thank you teseo,

Can you tell me what is array() here?

Regards,

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 994
Re: How to show latest ads with photos only on my home page.
« Reply #6 on: October 13, 2017, 09:43:56 pm »
He uses the option from search ads only with images to deliver the latest ads on front page.
Clever. Nice thinking.

Look bellow and you'll understand.

Code: [Select]
  /**
         * Return latest posted items, you can filter by category and specify the
         * number of items returned.
         *
         * @param int $numItems
         * @param mixed $options
         * @param bool $withPicture
         * @return array
         */
        public function getLatestItems($numItems = 10, $options = array(), $withPicture = false)
        {
            $key = md5(osc_base_url().(string)$numItems.json_encode($options).(string)$withPicture);
            $found  = null;
            $latestItems = osc_cache_get($key, $found);
            if($latestItems===false) {
                $this->set_rpp($numItems);
                if($withPicture) {
                    $this->withPicture(true);
                }
                if(isset($options['sCategory'])) {
                    $this->addCategory($options['sCategory']);
                }
                if(isset($options['sCountry'])) {
                    $this->addCountry($options['sCountry']);
                }
                if(isset($options['sRegion'])) {
                    $this->addRegion($options['sRegion']);
                }
                if(isset($options['sCity'])) {
                    $this->addCity($options['sCity']);
                }
                if(isset($options['sUser'])) {
                    $this->fromUser($options['sUser']);
                }
                $return = $this->doSearch();
                osc_cache_set($key, $return, OSC_CACHE_TTL);
                return $return;
            } else {
                return $latestItems;
            }
        }
« Last Edit: October 13, 2017, 09:47:40 pm by marius-ciclistu »

Syed

  • Full Member
  • ***
  • Posts: 171
Re: How to show latest ads with photos only on my home page.
« Reply #7 on: October 14, 2017, 01:34:28 pm »
Thank you teseo and marius-ciclistu for helping me,
Here is code that works fine for me, is it correct in terms of performance?

Code: [Select]
<?php
View
::newInstance()->_exportVariableToView("listType"'latestItems');
View::newInstance()->_exportVariableToView('latestItems'Search::newInstance()->getLatestItems(osc_max_latest_items(), array(), true)); // include ads with photos only
View::newInstance()->_exportVariableToView("listClass"$listClass);
osc_current_web_theme_path('loop.php');
?>


Regards,
« Last Edit: October 14, 2017, 01:36:01 pm by Syed »

teseo

  • Hero Member
  • *****
  • Posts: 5974
Re: How to show latest ads with photos only on my home page.
« Reply #8 on: October 14, 2017, 01:51:15 pm »
Not optimal in terms of performance, that would retrieve Latest Items from database twice, first the normal way, second with pictures only.

I'll try to explain:

osc_count_latest_items() function first checks if there is already a list of ads in View 'latestItems'. If not so, they are retrieved from database in the normal way.

So the trick here is to fill up 'latestItems' with your own options before invoking osc_count_latest_items(), thus:

Code: [Select]
<?php View::newInstance()->_exportVariableToView('latestItems'Search::newInstance()->getLatestItems(osc_max_latest_items(), array(), true));
 if( 
osc_count_latest_items() == 0) { ?>



Syed

  • Full Member
  • ***
  • Posts: 171
Re: How to show latest ads with photos only on my home page.
« Reply #9 on: October 14, 2017, 04:55:51 pm »
My complete code is

Code: [Select]
<?php if( osc_count_latest_items() == 0) { ?>
    <div class="clear"></div>
    <p class="empty"><?php _e("There are no ads available at this moment."'bender'); ?></p>
<?php } else {
    
View::newInstance()->_exportVariableToView("listType"'latestItems');
    
View::newInstance()->_exportVariableToView('latestItems'Search::newInstance()->getLatestItems(osc_max_latest_items(), array(), true)); // include ads with photos only
    
View::newInstance()->_exportVariableToView("listClass"$listClass);
    
osc_current_web_theme_path('loop.php');
    
?>

    <div class="clear"></div>
    <?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 ads''bender') ; ?></strong></a>
        </p>
    <?php }
     } 
?>


Do I need to change something in it to make its performance batter?

Regards

teseo

  • Hero Member
  • *****
  • Posts: 5974
Re: How to show latest ads with photos only on my home page.
« Reply #10 on: October 14, 2017, 05:21:58 pm »
Yes, as I tried to explain earlier, that's not the best way, try this:

Code: [Select]
<?php View::newInstance()->_exportVariableToView('latestItems'Search::newInstance()->getLatestItems(osc_max_latest_items(), array(), true)); // include ads with photos only
if( osc_count_latest_items() == 0) { ?>

    <div class="clear"></div>
    <p class="empty"><?php _e("There are no ads available at this moment."'bender'); ?></p>
<?php } else {
    
View::newInstance()->_exportVariableToView("listType"'latestItems');
    
View::newInstance()->_exportVariableToView("listClass"$listClass);
    
osc_current_web_theme_path('loop.php');
    
?>

    <div class="clear"></div>
    <?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 ads''bender') ; ?></strong></a>
        </p>
    <?php }
     } 
?>

 

Syed

  • Full Member
  • ***
  • Posts: 171
Re: How to show latest ads with photos only on my home page.
« Reply #11 on: October 14, 2017, 06:16:16 pm »
Thank you teseo,

Regards

teseo

  • Hero Member
  • *****
  • Posts: 5974
Re: How to show latest ads with photos only on my home page.
« Reply #12 on: October 14, 2017, 06:25:05 pm »
You're welcome. :) Please add [SOLVED] to the title of this thread.

Regards

ayman83

  • Jr. Member
  • **
  • Posts: 82
Re: [SOLVED] How to show latest ads with photos only on my home page.
« Reply #13 on: October 17, 2017, 06:32:10 am »

In which file this code exist?


Hi,

This way:

Replace.

Code: [Select]
<?php if( osc_count_latest_items() == 0) { ?>

With:

Code: [Select]
<?php View::newInstance()->_exportVariableToView('latestItems'Search::newInstance()->getLatestItems(osc_max_latest_items(), array(), true));
 if( 
osc_count_latest_items() == 0) { ?>


Regards

Syed

  • Full Member
  • ***
  • Posts: 171
Re: [SOLVED] How to show latest ads with photos only on my home page.
« Reply #14 on: October 17, 2017, 10:54:35 am »

In which file this code exist?


Hi,

This way:

Replace.

Code: [Select]
<?php if( osc_count_latest_items() == 0) { ?>

With:

Code: [Select]
<?php View::newInstance()->_exportVariableToView('latestItems'Search::newInstance()->getLatestItems(osc_max_latest_items(), array(), true));
 if( 
osc_count_latest_items() == 0) { ?>


Regards

in main.php