I'm trying to make one-button language switch using qtranslate and different url mydomain.com/en/ etc. ), but with PHP I'm unable to do that, since it takes just a first (loading document) state.
<div class="language-box">
<?php if (get_locale() == 'en_EN') { ?>
<a href="/en/" class="lang en">
<img src="<?php echo get_template_directory_uri(); ?>-child/imgs/lang-czech.png"/>
<?php } else { ?>
<a href="/cs" class="lang cz">
<img src="<?php echo get_template_directory_uri(); ?>-child/imgs/lang-english.png"/>
<?php } ?>
</a>
</div>
<?php
$lang = get_locale();
$href = "cz";
$img = "english";
switch ($lang){
case "en_EN":
$href = "en";
$img = "czech";
break;
default:
$href = "cz";
$img = "english";
break;
}
?>
<div class="language-box">
<a href="/<?php echo $href; ?>/" class="lang <?php echo $href; ?>">
<img src="<?php echo get_template_directory_uri(); ?>-child/imgs/lang-<?php echo $img; ?>.png"/>
</a>
</div>
Related
I want to change the layout of a grid of videos on a site. It's Wordpress.
Currently the PHP displays the grid in a 3/2 layout over two rows and then duplicates it depending on how many videos you choose to display.
I understand the code enough to know that we are setting 5, and splitting into 3/2. And i can set it to 6 and split into 3/3 or 4/2.....and so on
But I need to change the layout so we have a row of 3, then 3 but with the first two of the second row stacked on top of each other 1/3rd width and the third 2/3rd width. like below.
new layout to be acheived
Current PHP that does the layout: ( I understand that CSS might have to be changed but I can do that)
<article class="col-1-<?php if(($i%5==0)||(($i+1)%5==0)){ echo "2"; } else { echo "3"; } ?>" id="post-<?php echo $page->ID; ?>">
Full block:
<article class="col-1-<?php if(($i%5==0)||(($i+1)%5==0)){ echo "2"; } else { echo "3"; } ?>" id="post-<?php echo $page->ID; ?>">
<a href="<?php echo get_page_link($page->ID); ?>">
<?php if ( $detect->isMobile() ) {
if (has_post_thumbnail( $page->ID ) ){ ?>
<img src="<?php echo $image[0]; ?>" alt="<?php echo $title; ?>" width="160" height="90">
<?php } ?>
<?php } else { ?>
<?php if(get_field('looping_thumb_preview', $page->ID)){ ?>
<video playinline preload="auto" loop="yes">
<source src="<?php echo get_field('looping_thumb_preview', $page->ID); ?>" type="video/mp4">
Your browser does not support the video tag.
</video>
<?php } else if(get_field('looping_thumb', $page->ID)){ ?>
<video playinline preload="auto" loop="yes">
<source src="<?php echo get_field('looping_thumb', $page->ID); ?>" type="video/mp4">Your browser does not support the video tag.</video>
<?php } else if (has_post_thumbnail( $page->ID ) ){ ?>
<img src="<?php echo $image[0]; ?>" alt="<?php echo $title; ?>">
<?php } else { ?>
<img src="<?php bloginfo( 'template_url' ); ?>/images/blank.png" alt="<?php echo $title; ?>">
<?php } ?>
<?php } ?>
<div class="center-content">
<h1<?php if(get_field('subtitle', $page->ID)){ echo ' class="hassubtitle"';} else { echo ' class="nosubtitle"'; }?>><?php echo $title;?></h1>
<div class="underline"></div>
<?php if(get_field('subtitle', $page->ID)) { echo "<h2>" . get_field('subtitle', $page->ID) . "</h2>"; }
?>
</div>
</a>
</article>
Thanks in advance for any help
I have this following code
<td>
<?php if($rec->telegram){ ?><img class="social" src="<?php echo base_url(); ?>social/telegram.jpg" /><?php } ?>
<?php if($rec->google_pluse){ ?><img class="social" src="<?php echo base_url(); ?>social/g.jpg" /><?php } ?>
<?php if($rec->instagram){ ?><img class="social" src="<?php echo base_url(); ?>social/insta.jpg" /><?php } ?>
<?php if($rec->facebook){ ?><img class="social" src="<?php echo base_url(); ?>social/f.jpg" /><?php } ?>
</td>
I would like to add "else" into this code that if ALL those icons facebook, instagram, google plus and facebook weren't available then it will show another image file like "nophoto.jpg"
Note: If all those icons (4 icons) weren't available then it will show nophoto.jpg
I highly appreciate if someone guide me how to add else into above code.
Regards
It'll be easier to just add an extra if:
if (!($rec->telegram || $rec->instagram || $rec->facebook || $rec->google_plus)) { //etc
But really you want to attach that kind of logic to the $rec object, so that it's neatly separated and it's easier to add new types of social media in the future. Hopefully your $rec object is indeed backed by a class and not just a stdClass from a database result or cast.
public function hasNoSocialIcon() {
return !($rec->telegram || $rec->instagram || $rec->facebook || $rec->google_plus);
}
And then use that in your template:
<?php if ($rec->hasNoSocialIcon()) { ?>
<img class="social" src="<?php echo base_url(); ?>social/nophoto.jpg" />
<?php } ?>
You should take the use of PHP's conditional operators like this:
<?php
$icons_available = (
!empty($rec->telegram) &&
!empty($rec->google_plus) &&
!empty($rec->instagram) &&
!empty($rec->facebook)
);
?>
<td>
<?php if(!$icons_available) { ?>
<a href="default-pic.jpg">
<img class="social" src="default-pic.jpg" />
</a>
<?php } else { ?>
<?php $url = echo base_url() . 'social/telegram.jpg'; ?>
<a href="<?php echo $url; ?>">
<img class="social" src="<?php echo $url ?>" />
</a>
<?php $url = echo base_url() . 'social/google_plus.jpg'; ?>
<a href="<?php echo $url ?>">
<img class="social" src="<?php echo $url ?>" />
</a>
<?php $url = echo base_url() . 'social/instagram.jpg'; ?>
<a href="<?php echo $url ?>">
<img class="social" src="<?php echo $url ?>" />
</a>
<?php $url = echo base_url() . 'social/facebook.jpg'; ?>
<a href="<?php echo $url ?>">
<img class="social" src="<?php echo $url ?>" />
</a>
<?php } ?>
</td>
Hope this helps!
I'm using wordpress "Newspaper theme" and I want to change the header logo on some pages without changing the default that's used for the rest.
What I've done is I changed the logo.php from the hostmonster filemanager to:
<?php
/**
* Created by PhpStorm.
* User: ra
* Date: 4/22/14
* Time: 10:08 AM
*/
//read the logo + retina logo
$td_customLogo = td_util::get_option('tds_logo_upload');
$td_customLogoR = td_util::get_option('tds_logo_upload_r');
$td_logo_alt = td_util::get_option('tds_logo_alt');
$td_logo_title = td_util::get_option('tds_logo_title');
if (!empty($td_logo_title)) {
$td_logo_title = ' title="' . $td_logo_title . '"';
}
if (!empty($td_customLogoR)) { //if retina
if ($_GET['page_id'] == 110){
$td_customLogoR = 'http://www.arabi-group.com/wp-content/uploads/2016/05/araib-radio.jpg';
}elseif ($_GET['page_id'] == 179){
$td_customLogoR = 'http://www.arabi-group.com/wp-content/uploads/2016/05/13840505_10209929205285223_1180352314_o-1-e1469358582277.jpg';
}elseif ($_GET['page_id'] == 577){
$td_customLogoR = 'http://www.arabi-group.com/wp-content/uploads/2016/05/arabi-App.jpg';
}
?>
<a class="td-main-logo" href="<?php echo esc_url(home_url( '/' )); ?>">
<img class="td-retina-data" data-retina="<?php echo esc_attr($td_customLogoR) ?>" src="<?php echo $td_customLogo?>" alt="<?php echo $td_logo_alt ?>"<?php echo $td_logo_title ?>/>
</a>
<?php
} else { //not retina
if (!empty($td_customLogo)) {
if ($_GET['page_id'] == 110){
$td_customLogo = 'http://www.arabi-group.com/wp-content/uploads/2016/05/araib-radio.jpg';
}elseif ($_GET['page_id'] == 179){
$td_customLogo = 'http://www.arabi-group.com/wp-content/uploads/2016/05/13840505_10209929205285223_1180352314_o-1-e1469358582277.jpg';
}elseif ($_GET['page_id'] == 577){
$td_customLogo = 'http://www.arabi-group.com/wp-content/uploads/2016/05/arabi-App.jpg';
}
?>
<a class="td-main-logo" href="<?php echo esc_url(home_url( '/' )); ?>">
<img src="<?php echo $td_customLogo?>" alt="<?php echo $td_logo_alt ?>"<?php echo $td_logo_title ?>/>
</a>
<?php
}
}
The pages that should have different logo in the header are:
http://www.arabi-group.com/?page_id=110
http://www.arabi-group.com/?page_id=179
http://www.arabi-group.com/?page_id=577
What's keeping the logos from changing?
You just edit following my source
if (is_page( 110 )){
$td_customLogoR = 'http://www.arabi-group.com/wp-content/uploads/2016/05/araib-radio.jpg';
}
Everything will be work.
Updated: And you wrong at show img at src attribute
It should be
<a class="td-main-logo" href="<?php echo esc_url(home_url( '/' )); ?>">
<img class="td-retina-data" data-retina="<?php echo esc_attr($td_customLogoR); ?>" src="<?php echo $td_customLogoR; ?>" alt="<?php echo $td_logo_alt ?>"<?php echo $td_logo_title ?>/>
</a>
I want to get each product related images which is not assign to product but want to show all related images in front-end.
<?php
foreach ($data['product'] as $product) {
$product_id = $product->getId();
$product_name = $product->getName();
$product_description = $product->getDescription();
$product_price = $product->getPrice();
$isporductImage = $product->getImage();
$product_image = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true) . "media/catalog/product" . $product->getImage();
$isproductthumbnail = $product->getThumbnail();
$product_thumbnail = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true) . "media/catalog/product" . $product->getThumbnail();
$collectionimage = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB, true) . "media/catalog/category/thumb/" . $data['collection']['image'];
$productplaceholderImage = $this->getSkinUrl() . "whi/assets/images/whi_placeholder.png";
?>
<?php if ($isproductthumbnail != "") { ?>
<div class="image-div" style="background: url('<?php echo $product_thumbnail;?>');">
<img src="<?php echo $product_thumbnail; ?>" alt="celeb" />
</div>
<?php }elseif ($isporductImage != "") { ?>
<div class="image-div" style="background: url('<?php echo $product_image;?>');">
<img src="<?php echo $product_image; ?>" alt="celeb" />
</div>
<?php } else { ?>
<div class="image-div" style="background: url('<?php echo $productplaceholderImage;?>');">
<img src="<?php echo $productplaceholderImage ?>" alt="celeb" />
</div>
<?php } ?>
i want to show all related product images in this list.
<ul class="outfit-images-cmt">
<li><img src="<?php echo $this->getSkinUrl() ?>whi/assets/images/doll.png"></li>
<li><img src="<?php echo $this->getSkinUrl() ?>whi/assets/images/doll.png"></li>
<li><img src="<?php echo $this->getSkinUrl() ?>whi/assets/images/doll.png"></li>
<li><img src="<?php echo $this->getSkinUrl() ?>whi/assets/images/doll.png"></li>
</ul>
Try the below code for fetch all the gallery images:
$product_image_url_gallery = $product->getMediaGalleryImages();
$galleryURL = '';
echo '<ul class="outfit-images-cmt">';
foreach ($product_image_url_gallery as $image) {
$galleryImage = Mage::helper('catalog/image')->init($product, 'image', $image->getFile());
echo '<li><img src="'.$galleryURL.'"></li>'
}
echo '</ul>';
Ignore the horrible code and formating, it's what I have to work with.
<div class="stories-pictures"><div class="inside">
<?php for ($j=0; $j<2; $j++) foreach ($stories as $post) { /* can be empty field as well*/
setup_postdata($post);
if ($post->ID==$mainID && $j==0) {
$link = get_permalink($productID);
$title = "Back to <br/>".get_the_title($productID);
$img = "<img class='backbg' width='316' height='234' src=".get_template_directory_uri()."/images/bg.png";
} else if ($post->ID!=$mainID && $j==1) {
$link = get_the_permalink()."?e=$productID";
$title = get_the_title();
$img = get_the_post_thumbnail(null,'story-thumb');
} else continue;
?>
<a href="<?php echo $link; ?>" class="storiespicture">
<span>
<span><em> <span class="title"><?php echo $title; ?></span></em></span>
</span>
<?php echo $img; ?>
<div class="storieoverlay">
</div> <!-- .storieoverlay -->
</a> <?php } ?>
</div></div>
Here's what's outputted:
<a href="http://hidden/" class="storiespicture">
<span>
<span> <em> <span class="title" style="background-color: rgba(144, 137, 213, 0.901961);">hidden</span></em> </span>
</span>
<img width="316" height="234" src="http://hidden/hidden.jpg" class="attachment-story-thumb wp-post-image" alt="hidden"> </a>
I'm trying to get the .storieoverlay class to be under the img.
I removed some possibly sensitive content, hence where hidden is shown.
It's because you don't close your image tag:
$img = "<img class='backbg' width='316' height='234' src=".get_template_directory_uri()."/images/bg.png";
Should be
$img = "<img class='backbg' width='316' height='234' src='".get_template_directory_uri()."/images/bg.png'>";
I've fixed the issue now.
It was a plugin outputting the mark up on this certain page, everything said here has been useful though, so thanks.