This topic contains a post which is marked as Best Answer. Press here if you would like to see it.
*

Олег Котел

  • **
  • 27 posts
  • Західна ТеплоЕнергетична будівельна компанія. Твердопаливні котли, https://t.co/Zwml1cY34U будуємо котельні під ключ!
How (last ads on the main page) to display in categories?
« on: January 14, 2020, 12:24:54 PM »
How on the main page in main.php (recent announcements) to display in categories?
Example: 1) the latest ads Real Estate (block with the latest ads added to the category Real Estate), 2) the latest ads Automobiles (block with the latest ads added to the category Cars)

How to make an output block (last announcements on the main) for each category a separate block !?
Or what are the options?

*

MB Themes

Re: How (last ads on the main page) to display in categories?
« Reply #1 on: January 14, 2020, 08:21:02 PM »
Such feature is not present in theme
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Олег Котел

  • **
  • 27 posts
  • Західна ТеплоЕнергетична будівельна компанія. Твердопаливні котли, https://t.co/Zwml1cY34U будуємо котельні під ключ!
Re: How (last ads on the main page) to display in categories?
« Reply #2 on: January 15, 2020, 06:54:24 PM »
How to register osc_query_item function in main.php?

  <div class="home-container latest">
    <div class="inner">

<!-- LATEST LISTINGS BLOCK CATEGORY 6 -->

<?php
   osc_query_item(array(
    "category" => "4"   
));

  </div>
    <div class="inner">

<!-- LATEST LISTINGS BLOCK CATEGORY 6 -->

<?php
   osc_query_item(array(
    "category" => "6"   
));

      </div>
        </div>

*

MB Themes

Re: How (last ads on the main page) to display in categories?
« Reply #3 on: January 20, 2020, 04:10:45 PM »
@Олег Котел
This is basic syntax.

1) get listings into memory:
Code: [Select]
<?php
   osc_query_item
(array(
    
"category" => "4"   
  
));
?>

... check docs for more details:
https://docs.osclasspoint.com/display-only-certain-type-of-listings

2) show listings:
Code: [Select]
<?php
while(osc_has_custom_items()) {
  echo 
osc_item_id();
}
?>


To integrate it into theme is best to duplicate some section (with home page items) and just add query function and change osc_has_items to osc_has_custom_items...
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Олег Котел

  • **
  • 27 posts
  • Західна ТеплоЕнергетична будівельна компанія. Твердопаливні котли, https://t.co/Zwml1cY34U будуємо котельні під ключ!
Re: How (last ads on the main page) to display in categories?
« Reply #4 on: January 24, 2020, 10:42:48 AM »
Can you show it clearly?

Here is the whole main.php code

Code: [Select]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="<?php echo str_replace('_''-'osc_current_user_locale()) ; ?>">
<head>
  <?php osc_current_web_theme_path('head.php') ; ?>
</head>

<body id="body-home" class="layout-<?php echo bet_param('home_layout'); ?>">
  <?php osc_current_web_theme_path('header.php') ; ?>

  <?php if(bet_banner('home_top') !== false) { ?>
    <div class="home-container banner-box"><div class="inside"><?php echo bet_banner('home_top'); ?></div></div>
  <?php ?>

  <?php osc_get_premiums(bet_param('premium_home_count')); ?>

  <?php if(bet_param('premium_home') == && osc_count_premiums() > 0) { ?>
    <div class="home-container premium">
      <div class="inner">

        <!-- PREMIUMS BLOCK -->
        <div id="premium" class="products grid">
          <h2><?php _e('Featured listings''beta'); ?></h2>

          <div class="block">
            <div class="prod-wrap">
              <?php $c 1?>
              <?php while( osc_has_premiums() ) { ?>
                <?php bet_draw_item($ctrue); ?>
                 
                <?php $c++; ?>
              <?php ?>

              <?php if(osc_count_premiums() <= 0) { ?>
                <div class="home-empty">
                  <img src="<?php echo osc_current_web_theme_url('images/home-empty.png'); ?>" />
                  <strong><?php _e('No premium listing yet''beta'); ?></strong>
                </div>
              <?php ?>
            </div>
          </div>
        </div>
      </div>
    </div>
  <?php ?>


  <?php if(function_exists('osc_slider')) { ?>

    <!-- Slider Block -->
    <div class="home-container slider">
      <div class="inner">
        <div id="home-slider">
          <?php osc_slider(); ?>
        </div>
      </div>
    </div>
  <?php ?>




  <?php if (bet_param('promote_home') == 1) { ?>
    <div class="home-container promote">
      <div class="inner">
        <div class="promote">
          <h2><?php _e('Want to sell quickly?''beta'); ?></h2>
          <h3><?php _e('Publish a listing, promote ad to make it more attractive and get more hits and sell item much faster''beta'); ?></h3>

         <div class="box">
          <div class="bl b1">
            <div class="img"><div><span><img src="<?php echo osc_current_web_theme_url('images/publish.svg'); ?>" alt="<?php echo osc_esc_html(__('Publish an ad''beta')); ?>"/></span></div></div>
            <strong><?php _e('Add a listing''beta'); ?></strong>
            <span><?php _e('It takes just 1 minute!''beta'); ?></span>
          </div>

          <div class="bl b2">
            <div class="img"><div><span><img src="<?php echo osc_current_web_theme_url('images/promote.svg'); ?>" alt="<?php echo osc_esc_html(__('Promote listing''beta')); ?>"/></span></div></div>
            <strong><?php _e('Promote it''beta'); ?></strong>
            <span><?php _e('To make it more attractive''beta'); ?></span>
          </div>


          <div class="bl b3">
            <div class="img"><div><span><img src="<?php echo osc_current_web_theme_url('images/sold.svg'); ?>" alt="<?php echo osc_esc_html(__('Listing sold''beta')); ?>"/></span></div></div>
            <strong><?php _e('Sold''beta'); ?></strong>
            <span><?php _e('Premium item sells 5x faster''beta'); ?></span>
          </div>

          <i class="fa fa-caret-right ar ar1 mbCl"></i>
          <i class="fa fa-caret-right ar ar2 mbCl"></i>

          </div>
        </div>
      </div>
    </div>
  <?php ?>



  <div class="home-container latest">
    <div class="inner">

      <!-- LATEST LISTINGS BLOCK -->
      <div id="latest" class="products grid">
        <h2><?php _e('Lately added on our classifieds''beta'); ?></h2>

        <?php View::newInstance()->_exportVariableToView('latestItems'bet_random_items()); ?>

        <?php if( osc_count_latest_items() > 0) { ?>
          <div class="block">
            <div class="prod-wrap">
              <?php $c 1?>
              <?php while( osc_has_latest_items() ) { ?>
                <?php bet_draw_item($c); ?>
               
                <?php $c++; ?>
              <?php ?>
            </div>
          </div>
       
        <?php } else { ?>
          <div class="home-empty">
            <img src="<?php echo osc_current_web_theme_url('images/home-empty.png'); ?>" />
            <strong><?php _e('No latest listing yet''beta'); ?></strong>
          </div>
        <?php ?>

        <?php View::newInstance()->_erase('items') ; ?>
      </div>
    </div>
  </div>



  <?php if (bet_param('stats_home') == 1) { ?>
    <div class="home-container stats">
      <div class="inner">
        <div class="stats">
          <h2><?php _e('We are best thanks to you!''beta'); ?></h2>
          <h3><?php _e('Our classifieds are constantly spreading into world, stats says it all''beta'); ?></h3>

          <div class="box">
            <div class="bl bl1">
              <div class="img"><img src="<?php echo osc_current_web_theme_url('images/listing.svg'); ?>" alt="<?php echo osc_esc_html(__('Active listings''beta')); ?>"/></div>
              <strong><?php echo osc_total_active_items(); ?></strong>
              <span><?php _e('Active ads''beta'); ?></span>
            </div>

            <div class="bl bl2">
              <div class="img"><img src="<?php echo osc_current_web_theme_url('images/category.svg'); ?>" alt="<?php echo osc_esc_html(__('Categories''beta')); ?>"/></div>
              <strong><?php echo osc_count_categories(); ?></strong>
              <span><?php _e('Categories''beta'); ?></span>
            </div>

            <div class="bl bl3">
              <div class="img"><img src="<?php echo osc_current_web_theme_url('images/region.svg'); ?>" alt="<?php echo osc_esc_html(__('Regions''beta')); ?>"/></div>
              <strong><?php echo osc_count_regions(); ?></strong>
              <span><?php _e('Regions''beta'); ?></span>
            </div>

            <div class="bl bl4">
              <div class="img"><img src="<?php echo osc_current_web_theme_url('images/city.svg'); ?>" alt="<?php echo osc_esc_html(__('Cities''beta')); ?>"/></div>
              <strong><?php echo osc_count_cities(); ?></strong>
              <span><?php _e('Cities''beta'); ?></span>
            </div>

            <div class="bl bl5">
              <div class="img"><img src="<?php echo osc_current_web_theme_url('images/user.svg'); ?>" alt="<?php echo osc_esc_html(__('Users registred''beta')); ?>"/></div>
              <strong><?php echo osc_total_users(); ?></strong>
              <span><?php _e('Users registered''beta'); ?></span>
            </div>

          </div>
        </div>
      </div>
    </div>
  <?php ?>


  <?php if(function_exists('fi_most_favorited_items') && bet_param('favorite_home') == 1) { ?>
    <div class="home-container favorite">
      <div class="inner">

        <!-- MOST FAVORITED -->

        <?php
          $limit 
= (osc_get_preference('maxLatestItems@home''osclass') > osc_get_preference('maxLatestItems@home''osclass') : 24);


          
// SEARCH ITEMS IN LIST AND CREATE ITEM ARRAY
          
$aSearch = new Search();
          
$aSearch->addField(sprintf('count(%st_item.pk_i_id) as count_id'DB_TABLE_PREFIX) );
          
$aSearch->addConditions(sprintf("%st_favorite_list.list_id = %st_favorite_items.list_id"DB_TABLE_PREFIXDB_TABLE_PREFIX));
          
$aSearch->addConditions(sprintf("%st_favorite_items.item_id = %st_item.pk_i_id"DB_TABLE_PREFIXDB_TABLE_PREFIX));
          
$aSearch->addConditions(sprintf("%st_favorite_list.user_id <> coalesce(%st_item.fk_i_user_id, 0)"DB_TABLE_PREFIXDB_TABLE_PREFIX));
          
$aSearch->addTable(sprintf("%st_favorite_items"DB_TABLE_PREFIX));
          
$aSearch->addTable(sprintf("%st_favorite_list"DB_TABLE_PREFIX));
          
$aSearch->addGroupBy(DB_TABLE_PREFIX.'t_item.pk_i_id');

          
$aSearch->order('count(*)''DESC');

          
$aSearch->limit(0$limit);
          
$list_items $aSearch->doSearch();


          
// EXPORT FAVORITE ITEMS TO VARIABLE
          
GLOBAL $fi_global_items2;
          
$fi_global_items2 View::newInstance()->_get('items'); 
          
View::newInstance()->_exportVariableToView('items'$list_items);
        
?>


        <?php if(osc_count_items() <= 0) { ?><style>.home-container.favorite {display:none!important;}</style><?php ?>

        <div id="favorite" class="products grid">
          <h2><?php _e('Most favorited listings by users''beta'); ?></h2>

          <div class="block">
            <div class="prod-wrap">
              <?php $c 1?>
              <?php while( osc_has_items() ) { ?>
                <?php bet_draw_item($c); ?>
                 
                <?php $c++; ?>
              <?php ?>

              <?php if(osc_count_items() <= 0) { ?>
                <div class="home-empty">
                  <img src="<?php echo osc_current_web_theme_url('images/home-empty.png'); ?>" />
                  <strong><?php _e('No listing favorited yet''beta'); ?></strong>
                </div>
              <?php ?>
            </div>
          </div>
        </div>

        <?php
          
GLOBAL $fi_global_items2
          
View::newInstance()->_exportVariableToView('items'$fi_global_items2);  
        
?>

      </div>
    </div>
  <?php ?>



  <?php if(function_exists('blg_param') && bet_param('blog_home') == 1) { ?>
    <div class="home-container blog">
      <div class="inner">

        <!-- BLOG WIDGET -->
        <div id="blog" class="products grid">
          <a class="h2" href="<?php echo blg_home_link(); ?>"><?php _e('Latest articles on blog''beta'); ?></a>

          <?php osc_run_hook('blg_widget'); ?>
        </div>
      </div>
    </div>
  <?php ?>


  <?php if(function_exists('bpr_companies_block') && bet_param('company_home') == && count($sellers ModelBPR::newInstance()->getSellers(1, -1, -18'''''''NEW')) > 0) { ?>
    <div class="home-container business">
      <div class="inner">

        <!-- BUSINESS PROFILE WIDGET -->
        <div id="company" class="products grid">
          <a class="h2" href="<?php echo bpr_companies_url(); ?>"><?php _e('Our partners''beta'); ?></a>

          <?php echo bpr_companies_block(bet_param('company_home_count'), 'NEW'); ?>
        </div>
      </div>
    </div>
  <?php ?>


  <?php if(bet_banner('home_bottom') !== false) { ?>
    <div class="home-container banner-box"><div class="inside"><?php echo bet_banner('home_bottom'); ?></div></div>
  <?php ?>

  <?php osc_current_web_theme_path('footer.php') ; ?>
</body>
</html>


If I do like this:

Instead of code (original)

Code: [Select]
  <div class="home-container latest">
    <div class="inner">

      <!-- LATEST LISTINGS BLOCK -->
      <div id="latest" class="products grid">
        <h2><?php _e('Lately added on our classifieds''beta'); ?></h2>

        <?php View::newInstance()->_exportVariableToView('latestItems'bet_random_items()); ?>

        <?php if( osc_count_latest_items() > 0) { ?>
          <div class="block">
            <div class="prod-wrap">
              <?php $c 1?>
              <?php while( osc_has_latest_items() ) { ?>
                <?php bet_draw_item($c); ?>
               
                <?php $c++; ?>
              <?php ?>
            </div>
          </div>
       
        <?php } else { ?>
          <div class="home-empty">
            <img src="<?php echo osc_current_web_theme_url('images/home-empty.png'); ?>" />
            <strong><?php _e('No latest listing yet''beta'); ?></strong>
          </div>
        <?php ?>

        <?php View::newInstance()->_erase('items') ; ?>
      </div>
    </div>
  </div>
 

I paste my code 
Code: [Select]

  <div class="home-container latest">
    <div class="inner">
<!-- LATEST LISTINGS BLOCK category-4 -->
<?php
osc_query_item(array(
    
"category" => "4"    
));
if( 
osc_count_custom_items() == 0) { ?>

<?php _e('No Listings''beta') ; ?>
<?php } else { ?>
<?php $class "even"?>
<?php while ( osc_has_custom_items() ) { ?>

<?php if( osc_images_enabled_at_items() ) { ?>

<div class="img-wrap">
<?php if( osc_count_item_resources() ) { ?>
<a class="img" href="<?php echo osc_item_url() ; ?>">
<img class="lazy" src="<?php echo osc_resource_thumbnail_url() ; ?>" width="75" height="56" title="<?php echo osc_item_title(); ?>" alt="<?php echo osc_item_title(); ?>" /></a>
<?php } else { ?>
<img class="lazy" src="<?php echo osc_current_web_theme_url('images/no-image-240x200.png') ; ?>" alt="" title=""/>
<?php ?>
</div>
<div class="data">
<div class="price isGrid">
<span>
<?php if( osc_price_enabled_at_items() ) { echo osc_item_formated_price() ; ?>
<?php ?>
</span>
</div>

<a class="title" href="<?php echo osc_item_url() ; ?>"><?php echo osc_item_title() ; ?></a>

<div class="date isGrid">
<i class="fa fa-clock-o"></i>
<?php echo osc_format_date(osc_item_pub_date()); ?>
</div>
<!-- <div class="description isList">
<?php echo osc_highlightstrip_tagsosc_item_description() ) ) ; ?>
</div> -->
<div class="location isGrid">
<?php } echo osc_item_city(); ?> (<?php echo osc_item_region();?>)
</div>
 <?php $class = ($class == 'even') ? 'odd' 'even' ?>
            <?php ?>
<?php }; ?>
</div>
</div>

//////////////////////////////////////////////////////////////////////

  <div class="home-container latest">
    <div class="inner">
<!-- LATEST LISTINGS BLOCK category-6 -->
<?php
osc_query_item(array(
    
"category" => "6"    
));
if( 
osc_count_custom_items() == 0) { ?>

<?php _e('No Listings''beta') ; ?>
<?php } else { ?>
<?php $class "even"?>
<?php while ( osc_has_custom_items() ) { ?>

<?php if( osc_images_enabled_at_items() ) { ?>

<div class="img-wrap">
<?php if( osc_count_item_resources() ) { ?>
<a class="img" href="<?php echo osc_item_url() ; ?>">
<img class="lazy" src="<?php echo osc_resource_thumbnail_url() ; ?>" width="75" height="56" title="<?php echo osc_item_title(); ?>" alt="<?php echo osc_item_title(); ?>" /></a>
<?php } else { ?>
<img class="lazy" src="<?php echo osc_current_web_theme_url('images/no-image-240x200.png') ; ?>" alt="" title=""/>
<?php ?>
</div>
<div class="data">
<div class="price isGrid">
<span>
<?php if( osc_price_enabled_at_items() ) { echo osc_item_formated_price() ; ?>
<?php ?>
</span>
</div>

<a class="title" href="<?php echo osc_item_url() ; ?>"><?php echo osc_item_title() ; ?></a>

<div class="date isGrid">
<i class="fa fa-clock-o"></i>
<?php echo osc_format_date(osc_item_pub_date()); ?>
</div>
<!-- <div class="description isList">
<?php echo osc_highlightstrip_tagsosc_item_description() ) ) ; ?>
</div> -->
<div class="location isGrid">
<?php } echo osc_item_city(); ?> (<?php echo osc_item_region();?>)
</div>
 <?php $class = ($class == 'even') ? 'odd' 'even' ?>
            <?php ?>
<?php }; ?>
</div>
</div>



That display styles are lost, and custom-fields that I displayed in loop-single.php are not displayed

Although if the first code (original) then everything is displayed normally.

Correct me, please, what am I doing wrong ...

Thanks.




« Last Edit: January 24, 2020, 11:20:40 AM by Олег Котел »

*

MB Themes

Re: How (last ads on the main page) to display in categories?
« Reply #5 on: January 24, 2020, 01:44:32 PM »
@Олег Котел
Code looks ok, you might just removed some element. It should not be so hard to simply replace words with different one, just do one more try.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Олег Котел

  • **
  • 27 posts
  • Західна ТеплоЕнергетична будівельна компанія. Твердопаливні котли, https://t.co/Zwml1cY34U будуємо котельні під ключ!
Re: How (last ads on the main page) to display in categories?
« Reply #6 on: January 24, 2020, 04:18:34 PM »
I strongly apologize, but repeated attempts do not give a positive result. Be so kind as to help fix the code!

Thank you very much for the early ...

*

Олег Котел

  • **
  • 27 posts
  • Західна ТеплоЕнергетична будівельна компанія. Твердопаливні котли, https://t.co/Zwml1cY34U будуємо котельні під ключ!
Re: How (last ads on the main page) to display in categories?
« Reply #7 on: January 27, 2020, 11:00:42 PM »
Help me please!

Marked as best answer by frosticek on January 30, 2020, 08:32:18 AM
*

MB Themes

Re: How (last ads on the main page) to display in categories?
« Reply #8 on: January 28, 2020, 07:31:09 AM »
Code: [Select]
<div class="home-container latest">
    <div class="inner">

      <!-- LATEST LISTINGS BLOCK -->
      <div id="latest" class="products grid">
        <h2><?php _e('Lately added on our classifieds''beta'); ?></h2>

        <?php osc_query_item(array("category" => "4")); ?>

        <?php if( osc_count_custom_items() > 0) { ?>
          <div class="block">
            <div class="prod-wrap">
              <?php $c 1?>
              <?php while( osc_has_custom_items() ) { ?>
                <?php bet_draw_item($c); ?>
               
                <?php $c++; ?>
              <?php ?>
            </div>
          </div>
       
        <?php } else { ?>
          <div class="home-empty">
            <img src="<?php echo osc_current_web_theme_url('images/home-empty.png'); ?>" />
            <strong><?php _e('No listing in category yet''beta'); ?></strong>
          </div>
        <?php ?>

        <?php View::newInstance()->_erase('items') ; ?>
      </div>
    </div>
  </div>
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Олег Котел

  • **
  • 27 posts
  • Західна ТеплоЕнергетична будівельна компанія. Твердопаливні котли, https://t.co/Zwml1cY34U будуємо котельні під ключ!
Re: How (last ads on the main page) to display in categories?
« Reply #9 on: January 29, 2020, 06:52:58 PM »
Thanks so much for the help, everything works great!

*

MB Themes

Re: How (last ads on the main page) to display in categories?
« Reply #10 on: January 30, 2020, 08:32:24 AM »
Welcome.
  To get fast support, we need following details: Detail description, URL to reproduce problem, Screenshots

*

Олег Котел

  • **
  • 27 posts
  • Західна ТеплоЕнергетична будівельна компанія. Твердопаливні котли, https://t.co/Zwml1cY34U будуємо котельні під ключ!
Re: How (last ads on the main page) to display in categories?
« Reply #11 on: May 08, 2020, 01:38:17 PM »
How and where to change the number of ads in the "recent ads" block?

Displays 10 ads by default.

I change in the file:
\ oc-content \ themes \ beta \ functions.php

// RANDOM LATEST ITEMS ON HOME PAGE
function bet_random_items ($ numItems = 10,

10 by 8, no result.

Along the way:
MY DOMAIN.COM / oc-admin / index.php? Page = settings
The last ads for showing "set 8" in the frontend are further 10 ... I cleaned the cache ...

As I understand it, somewhere in the script you need to change, and which script, where is it located?

*

Decent Gull

  • *
  • 4 posts
Re: How (last ads on the main page) to display in categories?
« Reply #12 on: May 28, 2020, 02:35:15 AM »
Code: [Select]
<div class="home-container latest">
    <div class="inner">

      <!-- LATEST LISTINGS BLOCK -->
      <div id="latest" class="products grid">
        <h2><?php _e('Lately added on our classifieds''beta'); ?></h2>

        <?php osc_query_item(array("category" => "4")); ?>

        <?php if( osc_count_custom_items() > 0) { ?>
          <div class="block">
            <div class="prod-wrap">
              <?php $c 1?>
              <?php while( osc_has_custom_items() ) { ?>
                <?php bet_draw_item($c); ?>
               
                <?php $c++; ?>
              <?php ?>
            </div>
          </div>
       
        <?php } else { ?>
          <div class="home-empty">
            <img src="<?php echo osc_current_web_theme_url('images/home-empty.png'); ?>" />
            <strong><?php _e('No listing in category yet''beta'); ?></strong>
          </div>
        <?php ?>

        <?php View::newInstance()->_erase('items') ; ?>
      </div>
    </div>
  </div>

This is very good.. Thanks MB themes.. I need a little bit more in this code.

1. How i can show only 8 custom items of selected category?
 
(i.e i want show only 8 items of category 4.....

But this query show all items in category 4
<?php osc_query_item(array("category" => "4")); ?>

2. How to show the latest items on top from category 4 if the number of items will be select to 8?


*

Decent Gull

  • *
  • 4 posts
Re: How (last ads on the main page) to display in categories?
« Reply #13 on: May 30, 2020, 07:45:23 AM »
I found it myself.. Thanks

*

siken

  • ****
  • 136 posts
Re: How (last ads on the main page) to display in categories?
« Reply #14 on: August 20, 2020, 07:23:02 PM »
I found it myself.. Thanks


<?php osc_query_item(array("category" => "4", "results_per_page" => "8")); ?>