I’ve tried several code examples, including the one provided by WPengine themselves but all the ones I’ve tried end up in a redirect loop as many others people have found. I settled on this one as it seemed to be the most comprehensive and the only one I could get working.
I managed to get a single language version working for our UK site:
/** GEOIP REDIRECT but allow bots **/
function country_geo_redirect() {
$country = getenv('HTTP_GEOIP_COUNTRY_CODE');
$agent = $_SERVER['HTTP_USER_AGENT'];
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if ( $host == 'example.com/en-gb/' || isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT']) || $country != "GB" ) {
return;
}
wp_redirect('https://example.com/en-gb/', 301);
exit;
}
add_action('init', 'country_geo_redirect');
However, when I finally got the syntax right for the elseif statements, the UK version doesn’t redirect anywhere anymore, and neither do any of the others:
function country_geo_redirect() {
$country = getenv('HTTP_GEOIP_COUNTRY_CODE');
$agent = $_SERVER['HTTP_USER_AGENT'];
$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if ( $host == 'example.com/en-gb/' || isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT']) || $country != "GB" ) {
wp_redirect('https://example.com/en-gb/', 301);
exit;
} elseif ( $host == 'example.com/zh-hans/' || isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT']) || $country != "CN" ) {
wp_redirect('https://example.com/zh-hans/', 301);
exit;
} elseif ( $host == 'example.com/ja/' || isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT']) || $country != "JP" ) {
wp_redirect('https://example.com/ja/', 301);
exit;
}
}
add_action('init', 'country_geo_redirect');
Any idea where I’m going on here? This has been driving me nuts!
]]><cae>212924</cae>
<price_sk2_rozn>4562</price_sk2_rozn>
<price_dmd_rozn>4562</price_dmd_rozn>
<name>225/65R17 106H XL SUV Summer TL</name>
<brand>Kormoran</brand>
<cae>0357175</cae>
<price_sk3_rozn>15480</price_sk3_rozn>
<price_sk2_rozn>15480</price_sk2_rozn>
<name>245/35ZR19 93(Y) XL SportContact 6 FR</name>
<brand>Continental</brand>
I need to import the available price into my Regular price field. If I choose {price_dmd_rozn} as a Regular price, I get prices only for those products, which are in stock in DMD, others are imported with empty prices. How do I get prices right? I tried some things. First, I tried to put this in my Regular price field:
[IF({price[.='']})]{price_dmd_rozn}[ELSE]{price}[ENDIF]
[IF({price_dmd_rozn[.='']})]{price_sk2_rozn}[ELSE]{price_dmd_rozn}[ENDIF]
[IF({price_sk2_rozn[.='']})]{price_sk3_rozn}[ELSE]{price_sk2_rozn}[ENDIF]
[IF({price_sk3_rozn[.='']})]{price_sk4_rozn}[ELSE]{price_sk3_rozn}[ENDIF]
As an example result, I got Regular price: 31003100, as the item is in stock in 2 cities with price 3100.
Next time I tried ELSEIF:
[IF({price[.='']})]{price_dmd_rozn}[ELSEIF({price_dmd_rozn[.='']})]{price_sk2_rozn}[ELSEIF({price_sk2_rozn[.='']})]{price_sk3_rozn}[ELSEIF({price_sk3_rozn[.='']})]{price_sk4_rozn}[ELSE]{price}[ENDIF]
As the result, I again got prices not for all products.
I am really upset and have no idea what I do wrong
Will be grateful for your help and support!
I’m not a very good coder and am trying to use an IF statement. The help/examples on https://www.wpallimport.com/documentation/advanced/if-statements/ and elsewhere on the web haven’t been helpful enough for me.
I’m trying to hide some content if a cell is empty. For instance below; if any of the below cells; tuotemerkki/ean/sap are empty then that whole line should be hidden.
Tuotemerkki: {tuotemerkki[1]}
EAN-numero: {ean[1]}
SAP-numero: {sap[1]}
Thanks in advance.
]]>I have a problem of Displaying custom posts – only if custom meta box date is not expired. I can’t figure out the where I should put the if statement in the code. My idea is;
if($daysleft >= 0)
then execute the while “custom post”;
The following code is displaying the all the custom posts both – expired and not expired.
?php
while(have_posts() ) : the_post();
$thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
$discount = get_post_meta($post->ID, '_single_discount', true);
$date = get_post_meta($post->ID, '_single_date', true);
$code = get_post_meta($post->ID, '_single_code', true);
$url = get_post_meta($post->ID, '_single_url', true);
$daysleft = round( ($date-time()) / 24 / 60 / 60);
?>
<div class="coupon-date">
<?php
if($date == '')_e('Х?чинтэй', 'Couponize');
else if($daysleft <= 0) _e('Дууссан', 'Couponize');
else echo sprintf( _n('%d day left.', '%d Хоног ?лдсэн.', $daysleft, 'Couponize'), $daysleft );
?>
</div>
<?php endwhile; ?>
Thanx in advance,
Anandmongol
For example, if a post is in a child category of Category A, display Menu X. If another post is in a child category of Category B, display Menu Y.
My code works fine… until a post is in multiple child categories.
My understanding of the elseif statements was once a criteria was matched in a statement, it would stop running. In this case, the statements seem to be cycling through to match every child category.
Here is a page where this is apparent: https://tjohnsonmediagroup.com/insiders-radio-network/promotions/library/heart/heart-promotions-from-a-phone-call-to-a-cause/
This post is in a two child categories of two different parent categories, so two custom menus are being displayed (the menus I’m referring to start with “Personalities Home” and “Promotions Home”).
Can someone help me change the code so only one custom menu shows up?
Here is my template code:
<?php
/**
* Template Name: Insiders Post
*/
get_header(); ?>
<div class="gradient gradient-insiders">
<div class="container">
<h4><i class="fa fa-rocket fa-fw"></i> Insiders Radio Network: <?php foreach((get_the_category()) as $childcat) { $parentcat = $childcat->category_parent; echo get_cat_name($parentcat); } ?>: <?php $category = get_the_category(); echo $category[0]->cat_name; ?></h2>
</div><!-- /.container -->
</div><!-- /.gradient -->
<div class="social-line">
<div class="container" style="padding: 15px;">
<?php wp_nav_menu(
array(
'theme_location' => 'insiders_nav',
'depth' => 2,
'container' => 'div',
'menu_class' => 'nav nav-pills nav-justified',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker()
));
?>
</div><!-- /.container -->
<div class="container" style="padding: 15px;">
<?php
foreach((get_the_category()) as $childcat) {
if (cat_is_ancestor_of(1286, $childcat)) {
wp_nav_menu(
array(
'theme_location' => 'insiders_personalities_nav',
'depth' => 2,
'container' => 'div',
'menu_class' => 'nav nav-tabs nav-justified',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker()
));
}
else if (cat_is_ancestor_of(308, $childcat)) {
wp_nav_menu(
array(
'theme_location' => 'insiders_promotions_nav',
'depth' => 2,
'container' => 'div',
'menu_class' => 'nav nav-tabs nav-justified',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker()
));
}
else if (cat_is_ancestor_of(303, $childcat)) {
wp_nav_menu(
array(
'theme_location' => 'insiders_programming_nav',
'depth' => 2,
'container' => 'div',
'menu_class' => 'nav nav-tabs nav-justified',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker()
));
}
else if (cat_is_ancestor_of(557, $childcat)) {
wp_nav_menu(
array(
'theme_location' => 'insiders_preparation_nav',
'depth' => 2,
'container' => 'div',
'menu_class' => 'nav nav-tabs nav-justified',
'fallback_cb' => 'wp_bootstrap_navwalker::fallback',
'walker' => new wp_bootstrap_navwalker()
));
}
else {
echo "null";
}
}
?>
</div><!-- /.container -->
</div><!-- /.social-line -->
<div class="section section-gray-light">
<div class="container">
<div class="row">
<div class="col-md-8">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php if( has_post_thumbnail() ) { ?><?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID, 'thumbnail') ); ?><img class="featuredImage" src="<?php echo $url ?>" alt="<?php the_title(); ?>" /><?php } else { ?><?php } ?>
<h1 class="title title-blog"><?php the_title(); ?></h1>
<p class="no-margin-top text-muted"><em>by <?php the_author(); ?></em></p>
<?php if( get_field('download_file') ): ?>
<?php
ob_start ();
?>
<a href="<?php the_field('download_file'); ?>" class="btn btn-primary" style="margin-bottom: 20px;">Free - Download Now <i class="fa fa-angle-right"></i></a>
<?php
$download_content = ob_get_contents ();
ob_end_clean ();
echo do_shortcode( '[member]'.$download_content.'[/member]' );
?>
<?php endif; ?>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, this page does not exist.'); ?></p>
<?php endif; ?>
</div><!-- /.col -->
<div class="col-md-4">
<?php get_sidebar();?>
</div><!-- /.col -->
<div class="col-md-12"?
<?php related_posts(); ?>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container -->
</div><!-- /.section -->
<?php get_footer(); ?>
]]><?php
if(is_page(49)){
echo '<div class="header-logo-image"><a rel="home" title="Wisechoice Financial Services" href="https://2cf.bbe.myftpupload.com/"><img alt="Wisechoice Financial Services src="https://2cf.bbe.myftpupload.com/wp-content/uploads/2016/03/OFFICIAL-Wise-Choice-Financial-Logo.jpg"></a></div>';
}
?>
]]>On this site: https://annemarieobrienauthor.com/
We have two blog categories that we style differently: “Dog Reads” and “World Reads.” The best way to tell is by the banner on the top of the page. “Dog Reads” has a banner with dogs in it, “World Reads” should have a banner with Worlds in it, and all other categories have no banner at all.
“Dog Reads” is working perfectly. All other categories are working perfectly. But the archive page for “World Reads” is styling just like “Dog Reads”.
https://annemarieobrienauthor.com/category/dog-reads/
https://annemarieobrienauthor.com/category/world-reads/
Here’s my conditional code, displaying a different banner depending on the category:
<?php if ( is_category('Dog Reads') || in_category( 'Dog Reads' ) || post_is_in_descendant_category( 4 ) ) {
echo '<div class="dogbanner"><img src="https://annemarieobrienauthor.com/wp-content/themes/BORZOI/images/dogbanner.jpg"/></div>';
}
elseif ( is_category('World Reads') || in_category( 'World Reads' ) || post_is_in_descendant_category( 3 ) ) {
echo '<div class="dogbanner world"><img src="https://annemarieobrienauthor.com/wp-content/themes/BORZOI/images/worldbanner.jpg"/></div>';
} else {
echo ('');
}
?>
Note that subcategories of World Reads look exactly like they should: https://annemarieobrienauthor.com/category/world-reads/countries/uganda/
As do single posts of World Reads: https://annemarieobrienauthor.com/2015/07/q-a-with-shenaaz-g-nanji-child-of-dandelions/
It’s just the main archive page for World Reads that is showing the wrong banner (among other things, but if I can figure out why the banner is wrong I can figure out everything else):
https://annemarieobrienauthor.com/category/world-reads
Regarding PHP if elseif else…
1. I want it to work In all pages where the code will be used.
2. if there is no “taxonomy download_artist”, then display the default “Author code” instead.
3. My download_artist (taxonomy) and Author code is working fine the only issue im facing is with PHP if elseif else!
My example which does not work:
<?php if { ?>
<?php $artist = get_the_term_list( $post->ID, 'download_artist', '', ', ', '' );
if (!is_wp_error( $artist ) && '' != $artist ) {echo '<div class="text-muted text-sm text-ellipsis">'. esc_html__('by ','musik') . $artist .'<i class="fa fa-check-circle text-wildstuff"></i></div>';
} ?>
<?php } else { ?>
<?php if( get_theme_mod( 'show-author' )){ $user_id = $post->post_author;echo get_user_link($user_id); } ?>
<?php } ?>
Please help thank you!
]]>I have a child theme where I have customized the default header, but I want to add the code for the 2 alternate pages into the header file using if/elseif/else statements and I’m new at writing this stuff so a little help would be greatly appreciate.
Can someone please see if what I’m trying to do will work? Thanks!
Jeri
<?php if (is_page ( 'upcoming-conferences' )) {
MY HTML CODE HERE;
} elseif ( is_page ( 'in-the-news' )) {
MY HTML CODE HERE;
} else {
THE DEFAULT HTML CODE HERE;
} ?>
I just tried it and got a blank white screen on all pages.
]]>Here is what I have now
‘<?php
if (is_front_page()) { include(“empty.php”); }
elseif (is_home()) { include(“empty.php”); }
elseif (is_page( array(‘691’, ‘850’, ‘2072’, ‘2064’, ‘2077’, ‘2052’))) { include(“empty.php”); }
elseif (is_single( array(‘480’, ‘36094’, ’26’))) { include(“empty.php”); }
elseif (in_category( array(’42’, ’26’, ‘marketplace’, ‘Obituaries’, ‘obituaries’))) { include(“empty.php”); }
else { include(“paywall.php”); }
?>’
I want to be able to add this, if URL contains (array(‘events’, ‘calendar’, ‘movies’) then include empty.php
I am having problems finding code to do this. Perhaps add a function to functions.php and call it ‘elseif(in_url(array….’
]]>