Using the latest version of Wordpress & Buddypress, I am trying to display a certain custom profile field in the WP header.php. I'm terrible with PHP, but this is what I have:
<?php
global $bp;
$the_user_id = $bp->loggedin_user->userdata->ID;
if (function_exists('bp_get_profile_field_data')) {
$bp_gamertag = bp_get_profile_field_data('field=Gamertag&user_id='.bp_loggedin_user_id());
if ($bp_gamertag) {
echo '<img src="http://avatar.xboxlive.com/avatar/$bp_gamertag/avatar-body.png" alt=""/>';
}
else
echo '<img src="http://avatar.xboxlive.com/avatar/xbox/avatar-body.png" alt=""/>';
}
?>
I can't quite figure out why it isn't working. The source shows the variable still in the URL.
Also, I don't think I need the $user_user_id variable, as it isn't really being used, do I? I'm following the instructions in this topic: http://buddypress.org/support/topic/how-to-get-user-profile-data/
Try :
echo "<img src='http://avatar.xboxlive.com/avatar/$bp_gamertag/avatar-body.png' alt='' />";
Notice the use of single vs. double quotes.
Related
I'm a little lost here, hoping that someone can help. I'm using the Meta Box plugin for WordPress, and I'm trying to create a process for the user to select an option from a predefined list, and then assign a URL to that option as a link. Im trying to define the URL in a variable, and then call it in a function, but I'm still a little green on PHP syntax. this is my code now:
<?php
$article_url= rwmb_meta('orion_2016_article_url', 'type=URL');
if (rwmb_meta('orion_2016_article_source') != '') {
echo '<a href= ("$article_url") target=blank>';
echo rwmb_meta('orion_2016_article_source');
echo '</a>';} ?> on <?php the_date(); ?>
Since the options are already predefined, it seems like assigning a random URL to one of the options should be pretty simple. Hopefully this makes sense!
You need to to place variables you wish to echo inside double quotes or simply concatenate strings using . as in my example. Note that I didn't check the plugin's specific syntax, only general PHP syntax.
<?php
$article_url= rwmb_meta( 'orion_2016_article_url', 'type=URL' );
if (rwmb_meta('orion_2016_article_source') != '') {
echo '' . rwmb_meta( 'orion_2016_article_source' ); . '';
} ?> on <?php the_date(); ?>
I am making options in the 'customization api' for Wordpress. However for things such as the logo image, if no image has been uploaded (default value is blank) i want it to display the title of the Wordpress site. I have searched google a lot, but I just cant seem to get it to work.
I know the PHP code for the Wordpress site title, but I can't get the php 'if' and 'else' to work.
current code:
<img src="<?php echo get_theme_mod('logo_image'); ?>" alt="<?php bloginfo('name'); ?>"/>
..obviously this is just the option to upload the image, which WORKS, but I want it to display the site title if the default value is empty.
Thank you!
I don't know how you are setting the theme mod. I.e. are you using 'set_theme_mod' ?
But assuming you are complying to WordPress standards the code snippet below should be what you are seeking.
if (!empty(get_theme_mod('logo_image'))) {
echo "<img src='" . get_theme_mod('logo_image') . "' title='" . bloginfo('name') ."'>"
} else {
echo "<h2>" . bloginfo('name') . "</h2>";
}
Hope this helps you out,
Dave.
Can you try this?
<img src="<?php if (!isset(get_theme_mod['logo_image'])) {
echo ('Your custom image');
}
else{
echo get_theme_mod('logo_image');
}
?>" alt="<?php bloginfo('name'); ?
>"/>
The explanation for this line is that Anchor doesn't display the image from the custom field correctly. So I had to add the missing part of the path. It works just fine, but now the problem is that I get horrendous icons on Safari when there is no image fetched in the field image:
<?php echo "<img src='http://www.firstpartoftheurl/" . article_custom_field('image') . "' alt=' ' height='300' >"; ?>
May I show this line only when the custom field is populated?
And how can I hide custom fields when they are empty?
This is how I solved it:
<?php
$image = article_custom_field('image');
if (!empty($image)) {
echo "<img src= 'http://www.firstpartoftheurl".article_custom_field('image')."' alt='blabla ".article_title()."'>"; //if there is image show it
} else {
//if not do nothing
} ?>
I hope it helps. It works for me but if someone has a better solution, please let us know.
Shorter still:
<?php if (article_custom_field('featured-img')) :?>
<img src="<?php echo article_custom_field('featured-img')?>" alt="<?php echo article_title(); ?>" />
<?php endif; ?>
If article_custom_field() is not returning the full URL, there might be something up with your server configuration, because this has always worked for me. Otherwise, just prepend $_SERVER['SERVER_NAME']... this is better than hard-coding the URL.
There is documentation on the function here which also explains how to use its fallback: http://anchorcms.com/docs/function-reference/articles
my Conditional PHP is not working and i dont know why. Can you help me?
Here the Code:
<?php
if( is_page(array('5279','4945') ))
{
echo '<img src="http://www.example.de/logo_with_text.png">';
}
elseif( is_page(array('5656','5668','5672','5677','5682','5690','5735','5738','5741','5744','5749','5752')))
{
echo '<img src="http://www.example.de/logo_with_text_and_icon.png">';
}
else
{
echo '<img src="http://www.example.de/logo_without_text.png">';
}
?>
But i need it in this way... (letters are the Pages ids)
For pages a,b,c,d i need a own logo
For pages e,f,g,h i need a own logo
For pages j,k,l,m i need a own logo
and for Page n,o,p,q i need a own logo
Try this code, literally just tidied it slightly and removed the quotation marks round the page numbers.
<?php
if(is_page(array(5279,4945) ))
{
echo '<img src="http://www.example.de/logo_with_text.png">';
}
elseif(is_page(array(5656,5668,5672,5677,5682,5690,5735,5738,5741,5744,5749,5752)))
{
echo '<img src="http://www.example.de/logo_with_text_and_icon.png">';
}
else
{
echo '<img src="http://www.example.de/logo_without_text.png">';
}
?>
Just make sure you have the right pages. To do this go to pages in the dashboard and hover over the link to the page you want, you should see it shows the id number in the url, ie post=100. This is the id for that page and the one you will need to use. Using the id means that regardless of the page name, this code will always work for you.
An extreme test would also be using the below instead of the else
elseif(!is_page(array(5279,4945,5656,5668,5672,5677,5682,5690,5735,5738,5741,5744,5749,5752)))
{
echo '<img src="http://www.example.de/logo_without_text.png">';
}
Hi guys this is a pretty dumb question im really bad with php and this is basically not working and outputting the wrong thing can someone please help me.
if (get_field("gallery")){
while (has_sub_field("gallery")){
if (get_row_layout() == "video"){
echo '<ul class="bxslider">';
echo '<li>';
echo '<iframe src="'.the_sub_field("videos").'" frameborder="0"></iframe>';
echo '</li>';
}
heres a screenshot of whats happening as you can see the URL is not in the iframe src
Load the_sub_field("videos") into a variable first then include that in the string you want to echo out.
$myVar = the_sub_field("videos");
echo '<iframe src="' . $myVar . '"....
Of course this will not work if you are not correctly return a string from the_sub_field("videos") so make sure that function actually returns a string.