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);
Related
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'm trying to display a link only if it has a value.
How can i get the image if the_field imdb is not empty?
<a href="<?php the_field('imdb'); ?>" >
<img style="width:60px;"src="/img/link.png" /></a>
Use get_field(); instead of the_filed();.
if(!empty(get_field("fildname"))){
#your code hear
}
Try:-
if(!empty(the_field('imdb'))){
<a href="<?php the_field('imdb'); ?>" ><img style="width:60px;"src="/img/link.png" /></a>
}
Use isset
if(isset(the_field('imdb'))&&!empty(the_field('imdb'))){
<img src=""/>
}
Since i didnt want to show the img or link on older posts i solved it by:
<?php
// assign image
$imdbimg = "<img src='http://mydomain.com/IMDb.png' class='imdb' />";
// imdb link from custom field
$imdblink = get_field('imdb');
?>
// display img and link on post newer then id 16
<?php global $post;
if ( $post->ID >= 16 ){
echo ' ' . $imdbimg . '';
}
?>
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 :)
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 ?>.
I am trying to integrate the Google+ API on my website so that when a user submits approval via Oauth their Google+ activity feed will be displayed.
I have all of it working pretty much and am working on defining the variables that it will display for their feed.
Currently, this is what I have that IS working:
$activityMarkup = '';
foreach($activities['items'] as $activity) {
$url = filter_var($activity['url'], FILTER_VALIDATE_URL);
$title = filter_var($activity['title'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
$content = filter_var($activity['object']['content'], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH);
$published = $activity['published'];
$totalItems = $activity['object']['plusoners']['totalItems'];
$activityMarkup .= "<div class='activity'>
<a href='".$url."' target='_blank'>$title</a>
<div>$content</div>
<div><br/><span>Date Published: </span>$published</div>
<div><br/><span>Total Likes: </span>$totalItems</div>
</div><br/><br>";
What I am trying to get to work is adding in the image that is associated with the post, namely the thumbnail.
I have tried different variations based on using existing code that works, but I just can't figure it out.
According to the Google API, this is the information for that image:
object.attachments[].image object The preview image for photos or videos.
object.attachments[].image.url string URL of the link.
Here's a link to all of the activities available if the above information isn't enough:
https://developers.google.com/+/api/latest/activities#object.originalContent
If someone can help me figure out how to define the variable for the image, that'd be awesome.
I figured it out. If anyone needs it, here's the code.
$image='';
if(isset($activity['object']['attachments'])){
foreach($activity['object']['attachments'] as $att){
if(isset($att['image']['url'])) {
$src = $att['image']['url'];
To call it out:
<img src='$src'>
<?php
$image='';
if(isset($activity['object']['attachments']))
{
foreach($activity['object']['attachments'] as $att)
{
if(isset($att['image']['url']))
{
$src = $att['image']['url'] ;
}
}
}
?>
<img src='<?php echo $src ?>'>
Works a Treat - https://developers.google.com/+/api/latest/activities#object.originalContent
<?php foreach($activities['items'] as $activity): ?>
<div class="activity" >
<div class="title" ><a href="<?php echo($activity['object']['url']) ; ?>" ><?php echo($activity['object']['content']); ?></a></div>
<p>Published at <?php echo($activity['published']); ?></p>
<p>
<?php echo($activity['object']['replies']['totalItems']); ?> Replys .
<?php echo($activity['object']['plusoners']['totalItems']); ?> Plusoners .
<?php echo($activity['object']['resharers']['totalItems']); ?> Reshares
</p>
</div>
<?php endforeach ?>
Another Way to add to the Feed is with replies, plusoners and reshares