this is my first post for help on here, and man do I really need it. This is the first time I've developed a client's site using multisite, and I'm having trouble applying the appropriate header image to it's site. There are six sites in all, and I'm using the same template for all six sites' front pages. Also, the front page is static and doesn't have a specific page selected.
The conditional below is my attempt at specifying specific images depending on which sub-site I'm on. It keeps throwing a syntax error, (sublime calls it a parse error). I would be so grateful for any help!
<?php
if( get_bloginfo('All in with Laila Ali')) {
<img src="<?php bloginfo('template_directory');?>/images/Banner-LailaAli.jpg" />
} elseif{
if( get_bloginfo('Jaimies 15 Minute Meals')) {
<img src="<?php bloginfo('template_directory');?>/images/Banner-JamieOliver.jpg" />
}
} elseif{
if( get_bloginfo('Lucky Dog')) {
<img src="<?php bloginfo('template_directory');?>/images/Banner-LuckyDog.jpg" />
}
} elseif{
if( get_bloginfo('Game Changers with Kevin Frazier')) {
<img src="<?php bloginfo('template_directory');?>/images/Banner-GameChangers.jpg" />
}
} elseif{
if( get_bloginfo('Recipe Rehab')) {
<img src="<?php bloginfo('template_directory');?>/images/Banner-RecipeRehab.jpg" />
}
} else {
<img src="<?php bloginfo('template_directory');?>/images/Banner-PetVet.jpg" />
}
?>
You are getting this error because you have consecutive <?php tags with HTML in between them. Things like <img src=" aren't valid php, but you are inside <?php tags, so PHP gives you an error.
One of the ways you can fix this is by ending the tags when you need to switch back to HTML. Like this:
<?php
if( get_bloginfo('All in with Laila Ali')) {
?>
<img src="<?php bloginfo('template_directory');?>/images/Banner-LailaAli.jpg" />
<?php
} elseif{
if( get_bloginfo('Jaimies 15 Minute Meals')) {
?>
<img src="<?php bloginfo('template_directory');?>/images/Banner-JamieOliver.jpg" />
<?php
}
}
?>
Another way, is to have your PHP echo the HTML you want. Which would look something like this:
<?php
if( get_bloginfo('All in with Laila Ali')) {
echo '<img src="' . bloginfo('template_directory') . '/images/Banner-LailaAli.jpg" />';
} elseif{
if( get_bloginfo('Jaimies 15 Minute Meals')) {
echo '<img src="'. bloginfo('template_directory') . '/images/Banner-JamieOliver.jpg" />';
}
}
?>
Basically, you have to remember that once you open a <?php tag, you can only put valid PHP until you close it with ?>.
Related
I have the following code
<figure>
<?php if ($data[$i]->thumbnail) { ?>
<img src="<?php echo $img ?>" width="465" height="300" alt="news-report-juli19" title="" />
<?php } ?>
</figure>
I want to display images from mysql database dynamically,
the image_field_name=thumbnail.
I have 10 records in db and all have different images.
You should have to given the image path as well when you want to display.
<?php if ($data[$i]->thumbnail) { ?>
<img src="<?php echo base_url('path_of_img/$img'); ?>" width="465" height="300" alt="news-report-juli19" title="" />
<?php } ?>
If you use the Codeigniter framework, please try this.
In controller
$data['images'] = $this->model->get_images();
$this->load->view('view_name', $data);
In model you should make get_images() method that get image urls.
In view
<?php
foreach ($images as $value) {
echo '<img src="'.$value['thumbnail'].'" width="465"
height="300" alt="news-report-juli19" title="" />';
}
?>
Good luck.
use query variale with db colmn where images are present
use this in source img src
echo $query_variable['db_coln_name']
I'm attempting to add social follow icons to a BuddyPress site using a section of code that I found here:
https://buddypress.org/support/topic/display-users-social-follow-buttons-in-profile/
I followed the suggestion downthread and added the code to a bp-custom.php file in my plugins directory and the icons are showing up where they should but the link to the social profile is showing as text and when I click on the link it returns a 404 page.
I'm sure I have something wrong but I'm just too clueless new to spot it.
<?php
//Social Media Icons based on the profile user info
function member_social_extend(){
$dmember_id = $bp->displayed_user->id;
$fb_info = xprofile_get_field_data('facebook', $dmember_id);
$google_info = xprofile_get_field_data('googleplus', $dmember_id);
$linkedin_info = xprofile_get_field_data('linkedin', $dmember_id);
$twitter_info = xprofile_get_field_data('twitter', $dmember_id);
echo '<div class="member-social">';
if($fb_info||$google_info||$linkedin_info||$twitter_info){
echo 'My Social: ';
}
if ($fb_info) {
?>
<span class="fb-info"><img src="<?php bloginfo('wpurl'); ?>/wp-content/themes/family-openstrap-child/images/facebook.png" /></span>
<?php
}
?>
<?php
if ($google_info) {
?>
<span class="google-info"><img src="<?php bloginfo('wpurl'); ?>/wp-content/themes/family-openstrap-child/images/googleplus.png" /></span>
<?php
}
?>
<?php
if ($linkedin_info) {
?>
<span class="linkedin-info"><img src="<?php bloginfo('wpurl'); ?>/wp-content/themes/family-openstrap-child/images/linkedin.png" /></span>
<?php
}
?>
<?php
if ($twitter_info) {
?>
<span class="twitter-info"><img src="<?php bloginfo('wpurl'); ?>/wp-content/themes/family-openstrap-child/images/twitter.png" /></span>
<?php
}
echo '</div>';
}
add_filter( 'bp_before_member_header_meta', 'member_social_extend' );
?>
Thanks!
Looks like xprofile_get_field_data() creates its own <a> tag, so you don't have to write one out like you've done there. Try this instead:
$fb_info = xprofile_get_field_data(
'<img src="' . bloginfo('wpurl') . '/wp-content/themes/family-openstrap-child/images/facebook.png" />',
$dmember_id
);
...
<span class="fb-info"><?php echo $fb_info; ?></span>
Not sure if xprofile_get_field_data() will let you pass HTML in the first parameter there, so if that doesn't work quite right, you could fall back to something simpler (no image) like:
$fb_info = xprofile_get_field_data('Facebook', $dmember_id);
I'm working on a new WordPress theme (haven't touched WP themes since like 2.8...) and I'm attempting to make an if/else statement that changes the behavior of my top navigation bar based on whether the page is a front_page or not.
Essentially what I'm after is if the page is a front_page, then display the logo image. If the page is any other kind of page, then display a simple H1 element with the company name:
<li class="name">
<?php
if (is_front_page()) {
echo '<a href="<?php bloginfo("url"); ?>';
echo '<img src="' .bloginfo( "template_directory" ). '/images/logo-dsi.png" alt="DSI" />';
echo '</a>';
} else {
echo '<a href="' .home_url(). '">';
echo '<h1 class="logo">DSI</h1>';
echo '</a>';
}
?>
</li>
The else statement is working fine. But my if statement is not producing the img tag correctly. It echoes the literal bloginfo('template_directory') url and not inserting that into the img src, which is what I want it to do. It's trying to find an image at this url: localhost/images/logo-dsi.png
Obviously my syntax on line 5 is wrong somewhere, but I'm also not sure if I'm going about this the right way. Is there a better solution to what I'm trying to accomplish here?
Thanks!
The later is correct however
echo '<a href="<?php bloginfo("url"); ?>';
Should be
echo '<a href="' . bloginfo("url") . '">';
I tried this out and it worked:
<li class="name">
<a href="<?php bloginfo('url'); ?>">
<?php
if (is_front_page()) { ?>
<img src="<?php bloginfo('template_directory'); ?>/images/logo-dsi.png" alt="DSI" />
<?php
} else { ?>
<h1 class="logo">DSI</h1>
<?php } ?>
</a>
</li>
Apologies, I should have hacked away at it a little longer. But maybe this will become helpful to someone else.
I knew echos in WordPress looked bad for a reason... ;-)
Also I'm sure there's a prettier way to write this out, but for now, that code does the trick.
I am new in this so I'll try to be clear as I can.
I want to display\output, using php, page an image link html tag if user filed not empty like this on client side:
<a href="[dynamic from user filed]" title="My facebook">
<img src="images/facebook.png" alt="facebook" /></a>
so I wrote this but it always displays on html (client) the filed data as text without the all the html code (no html on client):
<div>
<?php
$Usr_Url = bp_member_profile_data('field=facebook' );
if ( !empty( $Usr_Url )) { ?>
<a href="<?php $Usr_Url; ?>" title="My facebook">
<img src="images/facebook.png" alt="facebook" /></a>
<?php } ?>
</div>
I suppose it is security issue so I need to make the code a server side code or something, can you give an advice please?
the current output seems to be always the user filed on html: www.facebook.com/try
*(need to add the I am retrieving buddypress field bp_member_profile_data(filed='filedname') and that sections works)
You are doing it the wrong way. Do it like this:
<?php
$Usr_Url = bp_member_profile_data('field=facebook' );
if ( !empty( $Usr_Url ))
{
echo "<a href=".$Usr_Url."title='My facebook' <img src='images/facebook.png' alt='facebook' /></a>";
}
?>
Comment if there are errors.
If wanting to output text from inside a PHP code block you need to use echo:
<?php
$Usr_Url = 'http://example.com';
echo 'Example URL';
...
?>
Or alternatively, you can mix in PHP code blocks into your HTML:
<?php $Usr_Url = 'http://example.com'; ?>
Example URL
...
You can't just stick HTML elements into your PHP code blocks though, as this breaks the syntax as in the original post.
To rework your code:
<div>
<?php
$Usr_Url = bp_member_profile_data('field=facebook' );
if ( !empty( $Usr_Url )) {
echo '<a href="'.$Usr_Url.'" title="My facebook">';
echo '<img src="images/facebook.png" alt="facebook" /></a>';
} ?>
</div>
You can try this out. It displays the image when Usr_Url is NOT empty:
<?php
$Usr_Url = bp_member_profile_data('field=facebook' );
if ( $Usr_Url != "" ) {
echo '<img src="images/facebook.png" alt="facebook" />'; } else { echo '$Usr_Url is empty...'; }
?>
I hope it helps :)
I want icon-backtotop.png to appear only on the home page and icon-backtotop-alt.png to appear on all other pages. However, with the code below, icon-backtotop-alt.png shows on all pages. How can I fix this code?
<?php if (is_home()) { ?>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/icon-backtotop.png" alt="Back To Top" />
<?php } else { ?>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/icon-backtotop-alt.png" alt="Back To Top" />
<?php } ?>
you probably want to use is_front_page not is_home
Note: WordPress 2.1 handles this function differently than prior
versions - See static Front Page. If you select a static Page as your
frontpage (see is_front_page()), this tag will be applied to your
"posts page".
try
<?php if (is_front_page()) { ?>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/icon-backtotop.png" alt="Back To Top" />
<?php } else { ?>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/img/icon-backtotop-alt.png" alt="Back To Top" />
<?php } ?>