The Osclass is a really good tool, but I have some problems with it.
I have this code:
<div class="cell selector">
<?php osc_categories_select('sCategory', null, __('Select country/city', 'bender')) ; ?>
</div>
and this code renders this HTML:
<div class="cell selector">
<div class="select-box undefined"><select name="sCategory" id="sCategory" style="opacity: 0;"><option value="">Select a category</option><option value="98">Key West</option><option value="101"> Miami</option><option value="99">Italy</option><option value="102"> Rome</option><option value="97">Madives</option><option value="96">France</option><option value="4">United States</option><option value="43"> Houses - Apartments for Sale</option><option value="44"> Houses - Apartments for Rent</option><option value="45"> Rooms for Rent - Shared</option><option value="46"> Housing Swap</option><option value="47"> Vacation Rentals</option><option value="48"> Parking Spots</option><option value="49"> Land</option><option value="50"> Office - Commercial Space</option><option value="51"> Shops for Rent - Sale</option></select><span class="select-box-label">Select a category</span><span class="select-box-icon">0</span></div> </div>
SO as you can see I don't have control over: <?php osc_categories_select('sCategory', null, __('Select country/city', 'bender')) ; ?>
How and where I can change this? I need to put my classes because I want to create a new theme with a new style? Anybody knows?
This should be in oc-includes > osclass > fm > Category.form.class.php
under:
static public function category_select($categories, $category, $default_item = null, $name = "sCategory")
{
echo '<select name="' . $name . '" id="' . $name . '">';
if(isset($default_item)) {
echo '<option value="">' . $default_item . '</option>';
}
foreach($categories as $c) {
echo '<option value="' . $c['pk_i_id'] . '"' . ( ($category['pk_i_id'] == $c['pk_i_id']) ? 'selected="selected"' : '' ) . '>' . $c['s_name'] . '</option>';
if(isset($c['categories']) && is_array($c['categories'])) {
CategoryForm::subcategory_select($c['categories'], $category, $default_item, 1);
}
}
echo '</select>';
}
Related
I'm working on a custom built English website that has WPML integrated in it to get the French translations for the entire site which also includes various custom post types, the main one I'm trying to get to work with it properly is the cpt "Products". So I already have the site translated but where my issue resides is with the custom search form & page that should only pull the cpt "Products".
Whenever I search for a product whether by ID or name, all products relating to the search is pulled as it should BUT is pulled for both languages. I only want it to show English results if it's on the English site and vice-versa for the French site but to no avail I can't get it to work.
CODE Snippet from Search Page:
if (have_posts()) {
$col_count = 1;
echo '
<div class="product-archive">
';
while(have_posts()) {
the_post();
if ($post->post_type == 'product') {
if (has_post_thumbnail($post->ID)) {
$thumbnail = get_the_post_thumbnail_url($post->ID);
} else {
$thumbnail = plugins_url('../images/gcp-no-thumbnail.jpg', __FILE__);
}
if ($col_count == 1) {
/*
echo '
<div class="product-row">
';
*/
}
echo '
<div class="col-sm-' . $column_size . ' product-category">
<a class="borderOutside" href="' . get_permalink($post->ID) . '">
<div class="borderInside">
<img src="' . $thumbnail . '" alt="' . $post->post_title . '">
<h2>' . $post->post_title . '</h2>
</div>
</a>
</div>
';
$col_count++;
if ($col_count > $columns) {
/*
echo '
</div>
';
*/
$col_count = 1;
}
}
}
echo '
</div>
';
}
?>
</article>
I want to add CCS style which depends on php IF statement. I have found something: changing the style inside "if" statement, but somehow it doesn`t work, maybe because of WHILE statement in my code.
<?php
$possible_lang_list = mysqli_query($con,
'SELECT * FROM page WHERE title = "lang" ORDER BY name1 ASC');
while ($row = mysqli_fetch_array($possible_lang_list)) {
echo '
<div class="language" id="' . $row['name2'] . '">
<p>' . $row['name1'] . '</p>
</div>
';
}
?>
I want to display only div class="language" where $row['name2'] == $x, with possibility to display whole class "language" with JavaScript. Could anyone help?
I have tried:
while ($row = mysqli_fetch_array($possible_lang_list)) {
if ($row['name2'] == $x) {
?>
<div style="display:block;">
<?php } else {
?>
<div style="display:none;">
<?php
echo '
<div class="" id="' . $row['name2'] . '">
<p>' . $row['name1'] . '</p>
</div>
</div>';
}
}
now it is working:
while ($row = mysqli_fetch_array($possible_lang_list)) {
if ($row['name2'] == $x) {
?>
<div style="display:block;">
<?php } else {
?>
<div style="display:none;">
<?php }
echo '
<div class="" id="' . $row['name2'] . '">
<p>' . $row['name1'] . '</p>
</div>
</div>';
}
Try this code :
while ($row = mysqli_fetch_array($possible_lang_list))
{
if($row['name2'] == $x)
{
echo '<div class="language" id="' . $row['name2'] . '"><p>' . $row['name1'] . '</p>
</div>';
}
else
{
echo '<div class="" id="' . $row['name2'] . '"><p>' . $row['name1'] . '</p>
</div>';
}
}
Hope it will work
Assign a style element with a true/false ternary, like below. Then just output it!
<?php
while ($row = mysqli_fetch_array($possible_lang_list)) {
$class = ($row['name2'] == $x) ? 'language' : null;
echo '
<div class="'.$class.'" id="' . $row['name2'] . '">
<p>' . $row['name1'] . '</p>
</div>
';
}
And then:
I'm developing a News website in Wordpress, and I need to show in a bootstrap carousel the first three posts, my problem is that I need to add the "active" class only at the first of the three elements, but really don't know how to. Here's my code:
<?php
$args = array('numberposts' => '3');
$recent_posts = wp_get_recent_posts($args);
foreach ($recent_posts as $recent) {
echo '<div class="item active"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ': <strong>' .$recent["post_title"] . '</strong></a></div>';
}
?>
I've already tried a answer found on this site (this one):
$isFirst = true;
foreach ($recent_posts as $recent) {
echo '<div class="item' . $isFirst ? ' active' : '' . '"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ": <strong>" .$recent["post_title"] . '</strong></a></div>';
$isFirst = false;
?>
but it just printed me the "active" words.
Thanks for your help
You need to set $i so that you can count how many times you have gone through the loop and do some logic with it, like in my example below. Instead of having two lines of code that are nearly identical like I have done below though, you should be able to do the if conditional right around the class active. I didn't do that so you could clearly see the conditional and the count of the loops through the array.
<?php
$args = array('numberposts' => '3');
$recent_posts = wp_get_recent_posts($args);
$i = 0;
foreach ($recent_posts as $recent) {
if ($i == 0) {
echo '<div class="item active"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ': <strong>' .$recent["post_title"] . '</strong></a></div>';
} else {
echo '<div class="item"><a href="' . get_permalink($recent["ID"]) . '" title=" ' . esc_attr($recent["post_title"]) . '" >' .$recent["post_date"] . ': <strong>' .$recent["post_title"] . '</strong></a></div>';
}
$i++;
}
?>
I am currently setting up an update company details page for my app (company timezone), I have already built and outputted a list of timezone/locale's grabbing PHP's inbuilt values for this and its all outputting fine.
My issue is I cannot for the life of me, work out how to set the 'selected' value when using a foreach to display the array into the select...
Model
//Timezone listing generated from PHP locales
function tz_list()
{
$zones_array = array();
$timestamp = time();
foreach(timezone_identifiers_list() as $key => $zone) {
date_default_timezone_set($zone);
$zones_array[$key]['zone'] = $zone;
$zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P', $timestamp);
}
return $zones_array;
}
Controller
//set locale display
$data['userOrglocale'] = $this->session->userdata('locale');
//load locale list from model
$data['tz_list'] = $this->account_model->tz_list();
View
<div class="form-group">
<label class="col-lg-3 control-label">Time Zone:</label>
<div class="col-lg-8">
<div class="ui-select">
<select id="user_time_zone" class="form-control">
<?php
foreach($tz_list as $key => $value)
{
if ($userOrglocale == $tz_list['zone'])
{
$selected = 'selected';
}
echo '<option value=' . $key['zone'] . $selected . '>' . $value['zone'] . ' (' . $value['diff_from_GMT'] . ')</option>';
}
?>
</select>
</div>
</div>
</div>
The ability to do this without Javascript/AJAX would be nice (as I dont know it well/much/at all) but I understand there is only so much I can do with HTML/PHP too...
quotation issuse.
you should change this
echo '<option value=' . $key['zone'] . $selected . '>' . $value['zone'] . ' (' . $value['diff_from_GMT'] . ')</option>';
to
echo '<option value="' . $key['zone'] .'" selected="'. $selected . '"'>' . $value['zone'] . ' (' . $value['diff_from_GMT'] . ')</option>';
UPDATE 1
Model
//Timezone listing generated from PHP locales
function tz_list()
{
$zones_array = array();
$timestamp = time();
foreach(timezone_identifiers_list() as $key => $zone) {
date_default_timezone_set($zone);
$zones_array[$zone] = 'UTC/GMT ' . date('P', $timestamp);
}
return $zones_array;
}
Controller
//set locale display
$data['userOrglocale'] = $this->session->userdata('locale');
//load locale list from model
$data['tz_list'] = $this->account_model->tz_list();
View
<div class="form-group">
<label class="col-lg-3 control-label">Time Zone:</label>
<div class="col-lg-8">
<div class="ui-select">
<?php
echo form_dropdown(array('id' => 'user_time_zone'), $tz_list, $userOrglocale);
?>
</div>
</div>
</div>
Not the most elegant solution but worked and kept the data as I needed it presented:
Only change was within the view
<?php
foreach($tz_list as $key => $value)
{
if ($userOrglocale == $value['zone'])
{
$selected = 'selected';
}
else
{
$selected = '';
}
echo '<option value="' . $value['zone'] . '"' . $selected . '>' . $value['zone'] . ' (' . $value['diff_from_GMT'] . ')</option>';
}
?>
I have some php that creates two columns of website content categories with child articles from that category. I've tried messing with the code that inserts the after two posts are listed, but it's not working (because I don't know what I'm doing). The current php renders as follows:
<div class="row">
<div class="column col-half">...</div>
<div class="column col-half">...</div>
</div>
I'd like it to render as:
<div class="row">
<div class="column col-third">...</div>
<div class="column col-third">...</div>
<div class="column col-third">...</div>
</div>
Here is the theme's code that renders the HTML:
$st_categories = get_categories($st_hp_cat_args);
$st_categories = wp_list_filter($st_categories,array('parent'=>0));
if ($st_categories) {
foreach($st_categories as $st_category) {
$st_cat_counter++;
if ((!is_int($st_cat_counter / 2)) && $st_cat_counter != 1) {
echo '</div><div class="row">';
} elseif ($st_cat_counter == 1) {
echo '<div class="row">';
}
echo '<div class="column col-half '. $st_cat_counter.'">';
echo '<h3> <a href="' . get_category_link( $st_category->term_id ) . '" title="' . sprintf( __( 'View all posts in %s', 'framework' ), $st_category->name ) . '" ' . '>' . $st_category->name.'</a>';
if (of_get_option('st_hp_cat_counts') == '1') {
echo '<span class="cat-count">(' . $st_category->count.')</span>';
}
echo '</h3>';
Thanks in advance.
You need to change just a couple of things (I improved the code style in terms of lines and indentation as well):
$st_categories = get_categories($st_hp_cat_args);
$st_categories = wp_list_filter($st_categories,array('parent'=>0));
if ($st_categories) {
foreach($st_categories as $st_category) {
$st_cat_counter++;
if (1 === $st_cat_counter % 3 && $st_cat_counter !== 1) { // change 2 -> 3 and use mod operator %
echo '</div><div class="row">';
} elseif ($st_cat_counter == 1) {
echo '<div class="row">';
}
echo '<div class="column col-third '. $st_cat_counter.'">'; // half -> third
echo '<h3> <a href="' . get_category_link( $st_category->term_id ) . '" title="' . sprintf( __( 'View all posts in %s', 'framework' ), $st_category->name ) . '" ' . '>' . $st_category->name.'</a>';
if (of_get_option('st_hp_cat_counts') == '1') {
echo '<span class="cat-count">(' . $st_category->count.')</span>';
}
echo '</h3>';