Changing Logo based on Page (Wordpress, PHP) - php

I'm trying to change the header logo on my site, depending on the page the person is on. I don't know PHP, but I've found where the Logo is defined in header.php, and am trying to rewrite it to be dynamic. When I use my code, the site breaks, so obviously I'm doing something wrong.
The original code is:
<!-- Logo -->
<?php
// Get the logo
if ($ti_option['site_logo'] != '') {
$site_logo = $ti_option['site_logo'];
}
else {
$site_logo = get_template_directory_uri() . '/images/logo.png';
}
?>
<a class="logo" href="<?php echo home_url('/'); ?>">
<img src="<?php echo $site_logo; ?>" alt="<?php bloginfo('name'); ?>
-
<?php bloginfo('description'); ?>" title="<?php bloginfo('name'); ?>
-
<?php bloginfo('description'); ?>" />
</a>
<!-- End Logo -->
What I'm trying to do is display a different logo based on which page the visitor is on. There are three:
- if the page is one of these: (1168, 1433, 1428), display /path/logo1.jpg
- if the page is one of these: (1369, 1361, 1365), display /path/logo2.jpg
- otherwise, just show /path/logo3.jpg
Here's what I've been able to manage so far:
<!-- Logo -->
<?php
// Get the logo
< ? php
if ($ti_option['site_logo'] != '') {
if (is_page(array(
1168,
1433,
1428
))) :
// '$site_logo' => 'FILELOCATION.jpg',
$site_logo = $ti_option['site_logo'];));
elseif (is_page(array(
1369,
1361,
1365
))):
$site_logo = $ti_option['site_logo'];));
else:
$site_logo = $ti_option['site_logo'];
endif;
?>
} else {
$site_logo = get_template_directory_uri() . '/images/logo.png';
}
?>
<a class="logo" href="<?php echo home_url('/'); ?>">
<img src="<?php echo $site_logo; ?>" alt="<?php bloginfo('name'); ?>
-
<?php bloginfo('description'); ?>" title="<?php bloginfo('name'); ?>
-
<?php bloginfo('description'); ?>" />
</a>
<!-- End Logo -->
I don't think I can nest PHP opening and closing tags, so there's that. But, I feel like I need to... my code doesn't work. Can anyone point me in direction of what to try?

I'm not 100% sure on wordpress standards, but here's a way to do it.
$logo1 = "logo1.jpg";
$logo2 = "logo2.jpg";
if ($ti_option['site_logo'] != '') {
if (is_page(array( 1168, 1433, 1428))){
$site_logo = $logo1;
}else if (is_page(array( 1369, 1361, 1365))){
$site_logo = $logo2;
}else{
$site_logo = $ti_option['site_logo'];
}
?>
} else {
I see 2 issues with your code :
1- No matter the outcome, you end up doing this : $site_logo = $ti_option['site_logo'];
In other words, you never actually change the logo.
2- Might be due to the fact you're using the dots if(cond): instead of if(cond){} which I'm not used to work with but imo it's much clearer when you have a good indentation.
error that is probably making your code crash :
$site_logo = $ti_option['site_logo'];));
should be
$site_logo = $ti_option['site_logo'];

Related

PHP foreach - Creating multple searchs in the same page

Firstly, I am a total php newby.
Secondly, below is the php header plus corresponding recursive commands for 2 photo lightboxes that are in the same html page.
Without the lines
getRecords() as $Title_row){ ?>
The page shows shows the first picture that is held in the external db table in the lightbox correctly.
Yet when I add the line below to add all the other entries in each table
getRecords() as $Title_row){ ?>
the page goes white and the browser html return is empty.
As I do not really understand what I am doing, I am stuck. Any suggestions would be very welcome.
<?php
$Title_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title_findCriterions = array('Order_web'=>'*',);
foreach($Title_findCriterions as $key=>$value) {
$Title_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title_find,'Title',50);
$Title_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title_result = $Title_find->execute();
if(FileMaker::isError($Title_result)) fmsTrapError($Title_result,"error.php");
fmsSetLastPage($Title_result,'Title',50);
$Title_row = current($Title_result->getRecords());
?>
<?php
$Title1_find = $Lowdenphotoweb->newFindCommand('MASTER_photo');
$Title1_findCriterions = array('Order_web'=>'*',);
foreach($Title1_findCriterions as $key=>$value) {
$Title1_find->AddFindCriterion($key,$value);
}
fmsSetPage($Title1_find,'Title',50);
$Title1_find->addSortRule('Order_web',1,FILEMAKER_SORT_ASCEND);
$Title1_result = $Title1_find->execute();
if(FileMaker::isError($Title1_result)) fmsTrapError($Title1_result,"error.php");
fmsSetLastPage($Title1_result,'Title',50);
$Title1_row = current($Title1_result->getRecords());
?>
<!DOCTYPE html>
<!-- Lightbox Gallery -->
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<!-- Lightbox Gallery End-->
You just missed out the closing brackets :
<?php foreach($Title_result->getRecords() as $Title_row){ ?>
<div class="hide">
<a data-group="gallery-1" data-caption="<?php echo $Title_row->getField('Title'); ?>" href="<?php echo $Title_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>
<?php foreach($Title2_result->getRecords() as $Title2_row){ ?>
<div class="hide">
<a data-group="gallery-2" data-caption="<?php echo $Title2_row->getField('Title'); ?>" href="<?php echo $Title2_row->getField('Pic_location'); ?>"></a>
</div>
<?php }?>

PHP WordPress if else not working unexpected syntax

I have a PHP if else statement however it does not seem to work and I'm not sure why.
Here is my code
<?php
if (has_post_thumbnail()) {
?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php
the_post_thumbnail('full', array('class' => 'img-responsive alignleft'));
?>
</a>
<?php
} else () {
?>
<img src="<?php echo get_template_directory_uri(); ?>/images/thumb.png" />';
<?php
}
?>
And here is the error that I get syntax error, unexpected ')'
I'm not sure where the unexpected ) is coming from.
I am basing my PHP on this structure, however editing it as I would like to be able to put mine into HTML without using echo
<?php if ( '' != get_the_post_thumbnail() ) {
// some code
}
else {
// some code
}
?>
Let's try with this:
<?php if (has_post_thumbnail()): ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" >
<?php the_post_thumbnail('full', array('class' => 'img-responsive alignleft')); ?>
</a>
<?php else: ?>
<img src="<?php echo get_template_directory_uri(); ?>/images/thumb.png" />';
<?php endif; ?>
I'm not sure why you wrote your code this way instead of concatenating it, but your if else statement has two parenthesis after else "()". You might want to get rid of these to fix your issue.
In PHP else is not a function, so you shouldn't call it like you did.
PHP's elseif () needs conditions,
try else instead:
<?php
if ( has_post_thumbnail() ) {
?>
<?php the_post_thumbnail( 'full', array( 'class' => 'img-responsive alignleft' ) ); ?>
<?php
} else { //instead of elseif () here, use else
?>
<img src="<?php echo get_template_directory_uri(); ?>/images/thumb.png" />
<?php
}
?>
Please also refer to the WordPress Coding Standards to make your code easier readable and maintainable. And try not to edit the original code in your question without marking the edits clearly, otherwise SO users won't be able to understand your problem/help you further.

Joomla 3.1 the full article image to be clickable (to self image url)

I find this com_content/views/article/tmpl/default.php I created a template override and here is the code:
<?php if ($params->get('access-view')):?>
<?php if (isset($images->image_fulltext) && !empty($images->image_fulltext)) : ?>
<?php $imgfloat = (empty($images->float_fulltext)) ? $params->get('float_fulltext') : $images->float_fulltext; ?>
<div class="pull-<?php echo htmlspecialchars($imgfloat); ?> item-image">
<img
<?php if ($images->image_fulltext_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_fulltext_caption) . '"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_fulltext); ?>" alt="<?php echo htmlspecialchars($images->image_fulltext_alt); ?>"/> </div>
<?php endif; ?>
Before img tag how to form, modify this php code to be clickable the image to self url:
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>"> <img
Here is the resolution:
<a href="<?php echo JURI::root().$images->image_fulltext; ?>">
Now the image is "clickalble" to self url
JURI::root() > your webpage url (like: something.com)
$images->image_fulltext > in joomla 3.1 you can choose an image what is displayed when you click to readmore, ie when you read the full article, that image have an url, like: /images/stories/freshsite/something.jpg
This php code combines these two code, to be: something.com/images/stories/freshsite/something.jpg > when you click on the image, only this image will shows in you browser :)

dynamic div sizing on one page only?

Live site.
My site is set up so that an image or gallery is displayed over a wooden background(#above), with the rest of the content below on a linen background(#below). This works well on every page but the portfolio page- the wooden space has no content until a specific gallery is selected.
Is there a way to have the linen background & content(#below) show instead of the plain wooden background(#above), until the gallery has been selected? (And if so, is it possible to have it appear to be sliding down from the top of the screen?)
header.php
<body>
<div class="above">
<div id="header">
<div class="logo">
<img src="<?php echo get_template_directory_uri(); ?>/img/logo.png" alt="Urban Palate logo" id="logo" />
</div><!-- end logo -->
<nav>
<ul>
<li><img src="<?php echo get_template_directory_uri(); ?>/img/about.png" alt="Urban Palate intro" /></li>
<li><img src="<?php echo get_template_directory_uri(); ?>/img/portfolio.png" alt="Urban Palate portfolio" /></li>
<li><img src="<?php echo get_template_directory_uri(); ?>/img/blog.png" alt="Urban Palate blog" /></li>
<li><img src="<?php echo get_template_directory_uri(); ?>/img/contact.png" alt="Urban Palate contact" /></li>
</ul>
</nav>
</div><!-- end header -->
portfolio.php
<?php
/*
Template Name: Portfolio
*/
?>
<?php get_header(); ?>
<div class="gallery">
<?php
if( is_page( 24 ) ) {
// make your stuff here
echo do_shortcode('[rev_slider slider1]');
} else {
// output standard content here
}
?>
<?php
if( is_page( 26 ) ) {
// make your stuff here
echo do_shortcode('[rev_slider slider2]');
} else {
// output standard content here
}
?>
<?php
if( is_page( 28 ) ) {
// make your stuff here
echo do_shortcode('[rev_slider slider3]');
} else {
// output standard content here
}
?>
<?php
if( is_page( 30 ) ) {
// make your stuff here
echo do_shortcode('[rev_slider slider4]');
} else {
// output standard content here
}
?>
<?php
if( is_page( 32 ) ) {
// make your stuff here
echo do_shortcode('[rev_slider slider5]');
} else {
// output standard content here
}
?>
<?php
if( is_page( 34 ) ) {
// make your stuff here
echo do_shortcode('[rev_slider slider6]');
} else {
// output standard content here
}
?>
<?php
if( is_page( 36 ) ) {
// make your stuff here
echo do_shortcode('[rev_slider slider7]');
} else {
// output standard content here
}
?>
<?php
if( is_page( 42 ) ) {
// make your stuff here
echo do_shortcode('[rev_slider slider8]');
} else {
// output standard content here
}
?>
</div><!-- end gallery -->
</div><!-- end above -->
<div class="below">
<div class="blurb">
<img src="<?php echo get_template_directory_uri(); ?>/img/portfolio_blurb.png" alt="see who has experienced our fabulous + creative and beautiful + cutting edge decor firsthand" />
</div><!-- end blurb -->
<div id="client-list">
<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'container_class' => 'menu-header' ) ); ?>
</div><!-- end client-list -->
<?php get_footer(); ?>
There are a lot of improvements that could be made to the code above. Investigate the switch statement, or at least ditch all the else blocks. Anyway,
In your header.php, try
<body>
<div class="above <?php if (is_page(1)) echo 'short'; ?>">
<div id="header">
<div class="logo">
// etc...
You will need to change the is_page(1) part to have the correct page number. I don't know how you figure this out with WordPress, but if you can do it for each gallery, you can do it for the empty portfolio page.
Then, in your site css:
.above.short {
height: 200px;
}
My solution is ugly, but it will fit in with the rest of the PHP you've got there. If you paid developers for that work, get new developers.
Somebody who knows WP may be able to tell you how to give div.above an additional class without resorting to inline code like I've done. This would be a better solution.
You can do this with jQuery.
For example:
// check if the gallery is empty and hide if it is.
if ($('.above .gallery').contents().length == 0){
$('.above').hide();
}
or use css instead of .hide and display:none or set the height to 0.
$('.above').css('height', '0');

Joomla intro image as read more link

I want to make the joomla articles intro image to behave like the read more, and the title link. So the user clicks the image, and the article loads.
I'm not an PHP expert but maybe this is the readmore links code:
<a href="<?php echo $this->item->readmore_link; ?>" class="button<?php echo $this->item->params->get('pageclass_sfx'); ?>">
<?php if ($this->item->readmore_register) :
echo JText::_('Register to read more...');
elseif ($readmore = $this->item->params->get('readmore')) :
echo $readmore;
else :
echo JText::_("Read Article");
endif; ?></a>
This is what i want to do with every intro image on my joomla site.
Thanks !
Just resolved it!
your way of thinking helped me. Thank you!
here's my code:
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>">
<?php
$images = json_decode($item->images);
if (isset($images->image_intro) and !empty($images->image_intro)) {
$imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro;
$class = (htmlspecialchars($imgfloat) != 'none') ? ' class="size-auto align-'.htmlspecialchars($imgfloat).'"' : ' class="size-auto"';
$title = ($images->image_intro_caption) ? ' title="'.htmlspecialchars($images->image_intro_caption).'"' : '';
echo '<img'.$class.$title.' src="'.htmlspecialchars($images->image_intro).'" alt="'.htmlspecialchars($images->image_intro_alt).'" />';
}
echo $this->item->introtext;
?>
</a>
for Joomla 2.5:
in your override for _item.php (Location: yourtemplate\html\mod_articles_news\item.php)
place the following line:
<?php if ($params->get('image')) : ?>
<?php $images = json_decode($item->images); ?>
<?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
<img src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
<?php endif; ?>
<?php endif; ?>
Place it there where you would like it to show up
For example after:
<?php echo $item->beforeDisplayContent; ?>
Your intro image has become a link now.
the isset part, makes sure that if a viewer uses Internet Explorer, it doesn't show up a small red cross box.
Just for the information:
in blog_item.php you can find an example code how it's shown up in an article. Here you can also find the code for imagefloat etc.
<?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
<?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?>
<div class="img-intro-<?php echo htmlspecialchars($imgfloat); ?>">
<img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</div>
<?php endif; ?>
So let me start by explaining what the code that you've posted above does. The entire block of code generates one link: there are a bunch of if statements that are determined based off some settings. For example, if you have set that people need to register in order to read more, the link will say "Register to read more..."
The part that we're interested in here, however, since we want to turn images into links, is the URL that we want the images to link to. This is right in the first line:
<a href="<?php echo $this->item->readmore_link; ?>"
so we know that the URL is provided dynamically thanks to $item->item->readmore_link and all this code is doing is echoing it into the HTML.
All that's left is to edit your Joomla template of the page on which you have your images (probably the same file you took this code from). It looks like this should be part of a greater PHP loop, which loops through all the posts. Somewhere above where you found this code, should be code for the intro image that goes along with that post.
I'm not sure what it'll look like, it could be a <img src="<? stuff here; ?> /> or it could be dynamically generated. Keep reading. If you're still not sure where to find it at the end, edit your post with the full code of the template where you got the above snipping from. Regardless of what it looks like, it is referred to as <WHATEVER IMAGE CODE YOU FOUND ABOVE> in the following step:
You have to wrap that image with "a" tags so that it looks like the following:
<WHATEVER IMAGE CODE YOU FOUND ABOVE>
That should do it. Let me know if you have any trouble, I'll be more than happy to make my post more specific if you can provide more detailed information, but I've tried to explain it well enough that you should be able to figure it out with a couple tries.
As you stated you are not a PHP expert, it sounds like your best bet will be to use a Joomla extension that has similar functionality to what you want.
I believe mod_minifrontpage will work for what you need. It allows you to display a list of articles, and it generates thumbnails for those articles based on the first image to be referenced.
There are article intro images in J, since 1.7.5 and now in latest 2.5.3
what you need is change the defaults for component_content,
you can do it 2 ways, editing views in yourinstall/components/com_content/views/
or use template overrides , you first need to know if your template IS using overrides otherwise if you edit component views in the component itself you will not see changes.
to verify this , go to
site_name/templates/template_name/html folder and check if there is folder name
com_content ,
if that is the case than your template is using overrides and any edits should be done trough there not through component
now to the actual code
this is in
components\com_content\views\featured\tmpl\default_item.php ( THIS I DEFAULT FRONTPAGE ARTICLE VIEW)
<?php if (isset($images->image_intro) and !empty($images->image_intro)) : ?>
<?php $imgfloat = (empty($images->float_intro)) ? $params->get('float_intro') : $images->float_intro; ?>
<div class="img-intro-<?php echo htmlspecialchars($imgfloat); ?>">
<img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</div>
<?php endif; ?>
all you would need to do is wrap a element around IMG tag with readmore link like this
<a href="<?php echo $this->item->readmore_link; ?>">
<img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</a>
DO NOT forget that if there is template override for com_content you wold need to edit the featured/default_item.php inside it
In Joomla 3.1, the intro_image layout has been moved to the layouts/joomla/content folder. In my situation, it is called from com_content/views/category/tmpl/blog_item.php like so:
<?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?>
I moved that file to my template/html/com_content/category/blog_item.php and then wrapped the call to JLayoutHelper like so:
<?php $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>
<a href="<?php echo $link; ?>">
<?php echo JLayoutHelper::render('joomla.content.intro_image', $this->item); ?>
</a>
If you have Gantry installed on Joomla 3.1, the overrides are in a different location. You will want to navigate to plugins/system/gantry/overrides/3.0/2.5/com_content/category/blog_item.php and wrap the intro image with the read more link code.
<?php $link = JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>
<a href="<?php echo $link; ?>"><img
<?php if ($images->image_intro_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_intro_caption) .'"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_intro); ?>" alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/></a>

Categories