In osclass, how display cities only with ads? - php

How can I display regions and their cities only with ads? And why I can't see numbers of ads? I would like use jQuery but I don't know how.
<?php
$aRegions = Region::newInstance()->getByCountry('AT');
if(count($aRegions) > 0 ) { ?>
<ul>
<?php
foreach($aRegions as $region) {
//print_r ($region);
echo "<li>";
//$region['pk_i_id'].
?>
<div class="accordionButton">
<a href="javascript:void()">
<?php echo $region['s_name']."\n"; ?>
</a>
<?php // echo "</em>(". $region['items'].")</em>";?>
</div>
<?php
$aCities = City::newInstance()-> getByRegion($region['pk_i_id']);
if(count($aCities) > 0 ) {
echo "<div class=\"accordionContent\">";
echo "<ul>";
foreach($aCities as $city) {
// print_r ($city);
//$city["pk_i_id"].'
echo "<li>";
echo "<a href='". osc_search_url( array( 'sRegion'=>$region["s_name"], 'sCity' => $city['s_name'] ) ) ."'> ";
echo $city["s_name"]."\n";
echo "</em>(". $city['items'].")</em>";
echo "</a>";
echo "</li>";
}
}
echo "</ul>";
echo "</li>";
} ?>
</ul>
<?php
}
?>

The solution for cities is:
<?php if(osc_count_list_cities() > 0 ) { ?>
<ul>
<?php while(osc_has_list_cities() ) { ?>
<li><?php echo osc_list_city_name() ; ?> <em>(<?php echo osc_list_city_items() ; ?>)</em></li>
<?php } ?>
</ul>
<?php } ?>
Now it's tested and workes for cities
This will list all cities and their number of items.

The solution for regions > cities is:
$locations = array();
if(osc_count_list_cities() > 0 ) {
while(osc_has_list_cities() ) {
$city_id = osc_list_city_id();
$city = City::newInstance()->findByPrimaryKey($city_id);
$region_id = $city['fk_i_region_id'];
$locations[$region_id][$city_id] = array("cityurl"=>osc_list_city_url(), "cityname"=>osc_list_city_name(), "cityitems"=>osc_list_city_items());
}
echo '<ul>';
while(osc_has_list_regions() ) {
$region_id = osc_list_region_id();
echo '<li>' . osc_list_region_name() . '<em>(' . osc_list_region_items() . ')</em>' ;
echo '<ul>';
foreach($locations[$region_id] as $acity) {
echo '<li>' . $acity['cityname'] . '<em>(' . $acity['cityitems'] . ')</em></li>' ;
}
echo '</ul></li><br/>';
}
echo '</ul>';
}

Thanks! Your code is good! I need to rewrite it now for country display. This is my code but does not work properly, instead of showing German regions this code display austrian regions again:
<?php
$locations = array();
if(osc_count_list_cities() > 0 ) {
while(osc_has_list_cities() ) {
$city_id = osc_list_city_id();
$city = City::newInstance()->findByPrimaryKey($city_id);
$region_id = $city['fk_i_region_id'];
$locations[$region_id][$city_id] = array("cityurl"=>osc_list_city_url(), "cityname"=>osc_list_city_name(), "cityitems"=>osc_list_city_items());
}
?>
<ul>
<?php while(osc_has_countries() ) { ?>
<li><?php echo osc_country_name() ; ?> <em>(<?php echo osc_country_items() ; ?>)</em>
<?php if (osc_country_name() =='Austria') { ?>
<?php
echo '<ul>';
while(osc_has_list_regions('AT') ) {
$region_id = osc_list_region_id();
echo '<li>' . osc_list_region_name() . '<em>(' . osc_list_region_items() . ')</em>' ;
echo '<ul>';
foreach($locations[$region_id] as $acity) {
echo '<li>' . $acity['cityname'] . '<em>(' . $acity['cityitems'] . ')</em></li>' ;
}
echo '</ul></li><br/>';
}
echo '</ul>';
}
if (osc_country_name() =='Germany') { ?>
<?php
echo '<ul>';
while(osc_has_list_regions('DE') ) {
$region_id = osc_list_region_id();
echo '<li>' . osc_list_region_name() . '<em>(' . osc_list_region_items() . ')</em>' ;
echo '<ul>';
foreach($locations[$region_id] as $acity) {
echo '<li>' . $acity['cityname'] . '<em>(' . $acity['cityitems'] . ')</em></li>' ;
}
echo '</ul></li><br/>';
}
echo '</ul>';
}
}
} ?>

The solution for COUNTRIES > REGIONS > CITIES in Osclass 3.7.x is
$locations = array();
if(osc_count_list_cities() > 0 ) {
while(osc_has_list_cities() ) {
$city_id = osc_list_city_id();
$city = City::newInstance()->findByPrimaryKey($city_id);
$region_id = $city['fk_i_region_id'];
$country_code = strtolower($city['fk_c_country_code']);
$locations[$country_code][$region_id][$city_id] = array("cityurl"=>osc_list_city_url(), "cityname"=>osc_list_city_name(), "cityitems"=>osc_list_city_items());
}
$locationsRegions = array();
while(osc_has_list_regions() ) {
$region_id = osc_list_region_id();
$region = Region::newInstance()->findByPrimaryKey($region_id);
$country_code = strtolower($region['fk_c_country_code']);
$locationsRegions[$country_code][$region_id] = array("regionurl"=>osc_list_region_url(), "regionname"=>osc_list_region_name(), "regionitems"=>osc_list_region_items());
}
echo "<ul>";
while(osc_has_list_countries() ) {
$country_code = strtolower(osc_list_country_code());
echo '<li>' . osc_list_country_name() . '<em>(' . osc_list_country_items() . ')</em>' ;
echo '<ul>';
foreach($locationsRegions[$country_code] as $regionId => $aregion) {
echo '<li>';
echo '' . $aregion['regionname'] . '<em>(' . $aregion['regionitems'] . ')</em></br>' ;
echo '<ul>';
foreach($locations[$country_code][$regionId] as $acity) {
echo '<li>' . $acity['cityname'] . '<em>(' . $acity['cityitems'] . ')</em></li>' ;
}
echo '</ul></li><br/>';
}
echo '</ul></li><br/>';
}
echo '</ul>';
}

Related

PHP output multiple variable values if they exist

I have to output a list of multiple values. These values are not part of an array. I am doing it like this:
$value_1 = get_field('value_1');
$value_2 = get_field('value_2');
$value_3 = some_other_function('value_3');
$value_4 = another_function('value_4', 'one_more_param');
echo '<ul>';
if ($value_1) :
echo '<li>' . $value_1 . '</li>';
endif;
if ($value_2) :
echo '<li>' . $value_3 . '</li>';
endif;
if ($value_3) :
echo '<li>' . $value_3 . '</li>';
endif;
if ($value_4) :
echo '<li>' . $value_4 . '</li>';
endif;
echo '</ul>';
I have about 30 values. Is there a quicker, cleaner way to output this?
Collect your values to array and iterate over this array:
$values = [
get_field('value_1'),
get_field('value_2'),
some_other_function('value_3'),
another_function('value_4', 'one_more_param'),
];
echo '<ul>';
foreach ($values as $value) {
if ($value) {
echo '<li>' . $value . '</li>';
}
}
echo '</ul>';
Create a function to check if it needs display the item, then pass the value each time...
function displayListItem( $value ) {
if ( $value ) {
echo '<li>'.$value.'</li>';
}
}
echo '<ul>';
displayListItem(get_field('value_1'));
displayListItem(get_field('value_2'));
displayListItem(some_other_function('value_3'));
displayListItem(another_function('value_4', 'one_more_param'));
echo '</ul>';

Order Custom Taxonomy by Slug in Wordpress Plugin

CONTEXT
We have created a custom taxonomy that is to be displayed as a search filter parameter in third party plugin (in the form of a checkbox). However, we want the list of taxonomies to be displayed ordered by slug.
This is the function that generates the checkbox and outputs the taxonomy - the part that we customized starts at " //create the attributes" .
public function checkbox($args)
{
//init defaults & vars
$input_args = $this->prepare_input_args($args, "checkbox");
$input_name = $input_args['attributes']['name'];
unset($input_args['attributes']['name']);
//filter the input arguments before the html is generated - allowing almost all options to be modified
if(has_filter('sf_input_object_pre')) {
$input_args = apply_filters('sf_input_object_pre', $input_args, $this->sfid);
}
//prepare html
$attibutes_html = $this->convert_attributes_to_html($input_args['attributes']);
$open_child_count = 0;
ob_start();
?>
<ul<?php echo $attibutes_html; ?>>
<?php
$last_option_depth = 0;
$option_count = count($input_args['options']);
$current_depth = 0;
$is_li_open = array();
//echo "<ul>";
for($i=0; $i<$option_count; $i++)
{
$option = &$input_args['options'][$i];
if(!isset($option->attributes))
{
$option->attributes = array(
'class' => '',
'id' => ''
);
}
//check a default has been set and set it
$option->attributes['type'] = "checkbox";
$option->attributes['value'] = $option->value;
$option->attributes['name'] = $input_name;
$option->attributes['html'] = '';
$container_attributes = array();
if($this->is_option_selected($option, $input_args['defaults']))
{
$option->attributes['checked'] = 'checked';
$option->attributes['class'] = trim($option->attributes['class']).' sf-option-active';
}
else
{
if(isset($option->attributes['checked']))
{
unset($option->attributes['checked']);
}
}
//now we want to put the class attribute on the LI, and remove from input
$option_class = $option->attributes['class'];
$option->attributes['class'] = $input_args['input_class'];
$input_id = $this->generate_input_id($input_name."_".$option->value);
$option->attributes['id'] = $input_id;
$container_attibutes_html = "";
if(isset($option->count))
{
$container_attributes['data-sf-count'] = $option->count;
$container_attibutes_html = $this->convert_attributes_to_html($container_attributes);
}
//create the attributes
$input_attibutes_html = $this->convert_attributes_to_html($option->attributes);
$option_label = $option->label;
$option_html = $option->attributes['value'];
if($input_name == "_sft_module_authors[]"){
$tax_name = "module_authors";
} else if ($input_name == "_sft_module_mindset[]") {
$tax_name = "module_mindset";
} else if ($input_name == "_sft_module_language[]") {
$tax_name = "module_language";
} else if ($input_name == "_sft_management_levels[]") {
$tax_name = "management_levels";
} else{
$tax_name = "wpdmcategory";
}
// Get the ID of a given category
$my_term = get_term_by('slug',$option->value,$tax_name);
$category_id = $my_term->term_id;
$category_desc = $my_term->description;
$category_name = $my_term->name;
$meta_image = get_wp_term_image($category_id);
// Get the URL of this category
$category_link = get_category_link( $category_id );
if ($input_name == "_sft_module_authors[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="eModal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>';
echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-8'>" . $category_desc . "</div>" . "<div class='col-md-4'>" . "<div class='img-wrap'><img src='".$meta_image."'></div></div>" . "[/modal]");
} else if ($input_name == "_sft_module_mindset[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="eModal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>';
echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-12'>" . $category_desc . "</div>" . "[/modal]");
} else if ($input_name == "_sft_module_language[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name;
} else if ($input_name == "_sft_management_level[]") {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name;
} else {
echo '<li class="accordion-content '.$option_class.'"'.$container_attibutes_html.'><input '.$input_attibutes_html.'><label class="sf-label-checkbox" for="'.$input_id.'">' . $category_name . '</label><a class="eModal-post-'.$category_id.'" href="'.$category_link.'"><i class="fa fa-info-circle"></i></a>';
echo do_shortcode("[modal id='post-". $category_id ."' size='small' title='". $category_name ."']". "<div class='col-md-12'>" . $category_desc . "</div>" . "[/modal]");
}
if(isset($option->depth))
{//then we do depth calculations
$current_depth = $option->depth;
$close_li = true;
$open_child_list = false;
$close_ul = false;
$next_depth = -1;
if(isset($input_args['options'][$i+1]))
{
$next_option = $input_args['options'][$i+1];
$next_depth = $next_option->depth;
}
if($next_depth!=-1)
{
if($next_depth!=$current_depth)
{//there is a change in depth
if($next_depth>$current_depth)
{//then we need to open a child list
//and, not close the current li
$open_child_list = true;
$close_li = false;
}
else
{
$close_ul = true;
}
}
}
if($open_child_list)
{
$open_child_count++;
echo '<ul class="children">';
}
if($close_li)
{
echo "</li>";
}
if($close_ul)
{
$diff = $current_depth - $next_depth;
$open_child_count = $open_child_count - $diff;
$str_repeat = str_repeat("</ul></li>", $diff);
echo $str_repeat;
}
}
}
$str_repeat = str_repeat("</ul></li>", (int)$open_child_count);
echo $str_repeat;
?>
</ul>
<?php
$output = ob_get_clean();
return $output;
}

How to add multiple ID in category

How to add in this code multiple ID category.
I have in kategorija_id 5 arrays:
1 - News
2 - Magazine
3 - Kokursi
4 - Grantovi ect..
I whant to display just key 1 and 2
when i add array i just print the first key
$kategorija = Kategorija::model()->findByPk($item->kategorija_**id=1,2**);
Thnx :)
Code update:
<div class="carousel-inner">
<div class="item active">
<ul class="thumbnails">
<?php
$i = 0;
$lastDefault = 0;
foreach ($ids as $itemId) {
$item = InfoPaket::model()->findByPk($itemId);
$kategorija = Kategorija::model()->findByPk($item->kategorija_id);
if ( $i % 3 == 0 && $i > 0 ) {
echo "</ul></div><div class='item'><ul class='thumbnails'>";
}
$imageUrl = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->baseUrl . "/images/infopaket/" . $item->slika;
if ( !file_exists($imageUrl) || empty($item->slika)) {
if ( $lastDefault == 0 ) {
$imagePath = Yii::app()->baseUrl . "/images/infopaket/info_paket.png";
$lastDefault = 1;
} else {
$imagePath = Yii::app()->baseUrl . "/images/infopaket/info_paket_redv2.png";
$lastDefault = 0;
}
} else {
$imagePath = Yii::app()->baseUrl . "/images/infopaket/" . $item->slika;
}
echo "<li class='span3 thmb-elem'>";
echo "<div class='thumbnail right-caption image'>";
echo "<a class='img-link' href='" . Yii::app()->getHomeUrl() . "?r=infoPaket/clanak&id=" . $item->id . "'><img class='img-class' src='$imagePath'></a>";
echo "</div>";
echo "<div class='caption caption-link'>";
echo "<div class='naziv'><img class='arrow-img' src='". Yii::app()->getBaseUrl() . "/themes/shadow_dancer/images/arrow.png'> " . strtoupper($kategorija->naziv) . "</div>";
echo "<p><a class='naslov' href='" . Yii::app()->getHomeUrl() . "?r=infoPaket/clanak&id=" . $item->id . "'><strong>" . $item->naslov . "</strong></a></p>";
echo "</div>";
echo "</li>";
$i++;
}
?>
</ul>
</div>
</div>
I solve this problem adding this line of code
if ($item->kategorija_id==3 || $item->kategorija_id==4 ) {
now code look like this and it works perfect.
<?php
$lastDefault = 0;
foreach ($ids as $itemId) {
$item = InfoPaket::model()->findByPk($itemId);
$kategorija = Kategorija::model()->findByPk($item->kategorija_id);
if ($item->kategorija_id==3 || $item->kategorija_id==4 ) {
echo '<li>';
echo '<img src="<?php echo Yii::app()->theme->baseUrl; ?>/images/infopaket/info_paket.png" />';
echo '<h2>';
echo strtoupper($kategorija->naziv);
echo '</h2>';
echo '<h1>';
echo "<a class='naslov' href='" . Yii::app()->getHomeUrl() . "?r=infoPaket/clanak&id=" . $item->id . "'>";
echo $item->naslov;
echo '</h1>';
echo '</a>';
echo '</li>';
}
}
?>
findByPk() accepts first argument as array too. So you can do
category::model()->findByPk(array('1', '2'));
Also, $item->category_id will return only single entry. If your item has multiple categories, than set up relations to categories and then get categories ID's with
CHtml::listData($item->categoriesRelationName, 'id', 'id');
can use function ($data){return $data->attribtues} too ---------^--- to get all attributes of model

Magento Get Products By Manufacturer

I have the following code which gets me a list of manufacturers:
$attribute = Mage::getModel('eav/entity_attribute')
->loadByCode('catalog_product', 'manufacturer');
$valuesCollection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setAttributeFilter($attribute->getData('attribute_id'))
->setStoreFilter(0, false);
$preparedManufacturers = array();
foreach($valuesCollection as $value) {
$preparedManufacturers[$value->getOptionId()] = $value->getValue();
}
if (count($preparedManufacturers)) {
echo "<h2>Manufacturers</h2><ul>";
foreach($preparedManufacturers as $optionId => $value) {
echo "<li>" . $value . " - (ID:" . $optionId . ")</li>";
}
echo "</ul>";
}
How do I get the first product of each manufacturer?
Thanks
try this
if (count($preparedManufacturers)) {
echo "<h2>Manufacturers</h2><ul>";
foreach($preparedManufacturers as $optionId => $value) {
<!-- add the this code for get first item id -->
$firstProductId=Mage::getModel('catalog/product')->getCollection()
->addStoreFilter(0)
->addAttributeToFilter('manufacturer',$optionId)->getFirstItem()->getId();
echo "<li>" . $value . " - (ID:" . $optionId . ")</li>";
}
echo "</ul>";
}

Links displaying array numbers and not mySQL values

As you can see on http://www.mattmaclennan.co.uk/a2 ... when you hover over "New Motorcycles", it has the array numbers, and not the labels as required. Also, the categories need to be grouped into their IDs. Below is what I have tried.
<?
$output = mysqli_query("SELECT * FROM bikes, bikeTypes WHERE bikes.model_id = bikeTypes.model_id");
$result = array();
while($row = mysqli_fetch_array($output))
{
$result[] = $row;
}
//var_dump($result);
foreach ($result as $key => $val) {
echo "<li><a href='test.php?id=" . $val['model_id'] . "'>".$key.'</a><ul>';
echo "<li><a href='details.php?id=" . $val['bike_id'] . "'>" . $val['bikeName'] . "</a></li>";
echo '</ul>';
echo '</li>';
}
?>
The category field is called 'model'. Thanks for any help!
Thats because you're display the $key, instead of the $value.
<?
$output = mysqli_query("SELECT * FROM bikes, bikeTypes WHERE bikes.model_id = bikeTypes.model_id");
while($row = mysqli_fetch_array($output))
{
echo "<li><a href='test.php?id=" . $row['model_id'] . "'>".$row['???'].'</a><ul>';
echo "<li><a href='details.php?id=" . $row['bike_id'] . "'>" . $row['bikeName'] . "</a></li>";
echo '</ul>';
echo '</li>';
}
?>

Categories