How to change header logo in specific page? - php

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>

Related

Wordpress PHP grid layout presentation

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

How to add if else into PHP code?

I have 4 social icons and if all of them weren't available then I want to show default.jpg , currently in the column, it's showing 5 icons including default.jpg too.
I added $icons_available, but not working, here is my complete code:
<?php
$icons_available = (
!empty($rec->telegram) &&
!empty($rec->google_plus) &&
!empty($rec->instagram) &&
!empty($rec->facebook)
);
?>
<td>
<?php if(!$icons_available) {?><img class="social" src="<?php echo base_url(); ?>social/default.jpg" /><?php }?>
<?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>
Here is my question:
**
If all of 4 icons weren't available together, then it will show
default.jpg otherwise it won't show default.jpg, How to make it?
**
try below code: (replace you above mention code and try with this)
<td>
<?php
if((!empty($rec->telegram) && !empty($rec->google_plus) && !empty($rec->instagram) && !empty($rec->facebook))) { ?>
<img class="social" src="<?php echo base_url()."social/telegram.jpg"; ?>" />
<img class="social" src="<?php echo base_url()."social/g.jpg"; ?>" />
<img class="social" src="<?php echo base_url()."social/insta.jpg"; ?>" />
<img class="social" src="<?php echo base_url()."social/f.jpg"; ?>" /><?php
}else{
$defaultSrc = base_url()."social/default.jpg";
for($i=0; $i < 4;$i++){
echo '<img class="social" src="'.$defaultSrc.'"/>';
}
}
?>
</td>
try this
<? php
$icons_available = (!empty($rec - > telegram) &&
!empty($rec - > google_plus) &&
!empty($rec - > instagram) &&
!empty($rec - > facebook)
); ?>
< td >
<? php
if (!$icons_available) { ?> < img class = "social"
src = "<?php echo base_url(); ?>social/default.jpg" / >
<? php
} else if ($rec - > telegram) { ?> < a href = "<?php echo $rec->telegram; ?>" > < img class = "social"
src = "<?php echo base_url(); ?>social/telegram.jpg" / > < /a>
<?php }else if($rec->google_pluse){ ?><img class="social" src="<?php echo base_url(); ?>social/g.jpg " />
<?php }else if($rec->instagram){ ?><a href=" <? php echo $rec - > instagram; ?> "><img class="
social " src=" <? php echo base_url(); ?> social / insta.jpg " /></a>
<?php }else if($rec->facebook){ ?><a href=" <? php echo $rec - > facebook; ?> "><img class="
social " src=" <? php echo base_url(); ?> social / f.jpg " /><?php } ?></a>
</td>
Rather use a PHP switch http://php.net/manual/en/control-structures.switch.php You will then put default.jpg in the default section of the switch.

How to loop a php code?

I wanted to do the DRY approach in my code but I'm having a hard time figuring it out. And also, I want to hide the entire code if there's no image_1. Hope you could help me do the trick.
Here's the code
<div class="col-md-4">
<?php
$image = get_field('image_1');
if(get_field('image_1'))
{
echo '<a href="' . get_field('image_link_1') . '">';?>
<img src="<?php echo $image['url']; ?>" title="<?php echo $image['title']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php echo '</a>';
} else {
echo '<img src="http://localhost/image.png">';
} ?>
</div>
<div class="col-md-4">
<?php
$image = get_field('image_2');
if(get_field('image_2'))
{
echo '<a href="' . get_field('image_link_2') . '">';?>
<img src="<?php echo $image['url']; ?>" title="<?php echo $image['title']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php echo '</a>';
} else {
echo '<img src="http://localhost/image.png">';
} ?>
</div>
<div class="col-md-4">
<?php
$image = get_field('image_3');
if(get_field('image_3'))
{
echo '<a href="' . get_field('image_link_3') . '">';?>
<img src="<?php echo $image['url']; ?>" title="<?php echo $image['title']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php echo '</a>';
} else {
echo '<img src="http://localhost/image.png">';
} ?>
</div>
You should put differences to arrays and then wrap everything into for loop:
<?php
$images = array('image_1', 'image_2', 'image_3');
$links = array('image_link_1', 'image_link_2', 'image_link_3');
for($i=0; $i<3; $i++){
?>
<div class="col-md-4">
<?php
$image = get_field($images[$i]);
if(get_field($images[$i])){
echo '<a href="' . get_field($links[$i]) . '">';
?>
<img src="<?php echo $image['url']; ?>" title="<?php echo $image['title']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php echo '</a>';
} else {
echo '<img src="http://localhost/image.png">';
}
?>
</div>
<?php
}
?>
Just a hint...:
<?php
for ($i = 0; $i < 3; $i++) {
echo "<div class='col-md-4'>" . "\n";
$image = get_field("image_" . ($i + 1));
...
echo "</div>" . "\n";
}
?>
Something along these lines should get you started if I'm understanding you correctly:
<?php for ($q = 1; $q <= 3; $q++) {
$image_loop = 'image_' . $q;
echo '<div class="col-md-4">';
if ($image = get_field($image_loop)) {
echo '<a href="' . get_field('image_link_' . $q) . '">';
?>
<img src="<?php echo $image['url']; ?>" title="<?php echo $image['title']; ?>" alt="<?php echo $image['alt']; ?>" />
<?php echo '</a>';
} else {
echo '<img src="http://localhost/image.png">';
} ?>
</div>
<?php } // end loop ?>
The other suggestions here will work as well but here's what I would do:
First arrange the images in an associative array with keys being the image name and values being the image link and then iterate via a foreach loop.
I generally try to not echo HTML unless strictly necessary.
<?php
$array = [
"image_1" => "image_link_1",
"image_2" => "image_link_2",
"image_3" => "image_link_3",
"image_4" => "image_link_4"
];
foreach ($array as $name => $link):
$image = get_field($name);
if ($image): ?>
<div class="col-md-4">
<a href="<?=get_field($link)?>">
<img src="<?= $image['url']; ?>" title="<?= $image['title']; ?>" alt="<?= $image['alt']; ?>" />
</a>
<?php else: ?>
<img src="http://localhost/image.png">
<?php endif; ?>
</div>
<?php endforeach; ?>

How to get individual product related images in magento

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>';

Toggle language using one button

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>

Categories