show custom fields data in next and previous link in wordpress - php

I am trying to show a advanced custom fields data in previous post link in wordpress. But The data is not showing also it breaks the html as well.
<div class="prev-posts pull-left">
<?php
$prev_post = get_previous_post();
if($prev_post) {
$prev_title = strip_tags(str_replace('"', '', $prev_post->post_title));
echo "\t" . '<a rel="prev" href="' . get_permalink($prev_post->ID) . '" title="' . $prev_title. '" class=" ">
<strong>
<<< "'. $prev_title . '"
</strong>
<img src="'.the_field("girl_image").'" alt="'.the_title().'/>
</a>' . "\n";
}
?>
</div>
In this code the "girl_img" field contains the URL of an image. I want to show the image based on the URL. But it is showing the URL itself instead of showing the image.

Use get_field() instead of the_field().
get_field() = Returns the value of the specified field.
the_field() = Displays the value of the specified field. This function is the same as echo get_field($field_name);
Replace the_field("girl_image") with get_field("girl_image")

Related

Insert Image in HTML / PHP

I would like to add a profile image for this follow and unfollow system. How would I do this in this line?
I am thinking before the <tr> I would have a <img src = ...>
$t_rows .= '<tr><td>'.htmlspecialchars($v['NameFirst'].' '.$v['NameLast']).'</td><td>';
If you would like to add a profile image based off of a PHP variable that has already been set, you could echo the HTML content.
<?php
$myVariable = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png";
echo '<img src="' . $myVariable . '" alt="Some Text..."/>';
?>

Display all users/authors in wordpress template

I'm trying to display all my authors/users in a custom page template using advanced custom fields. I'm using the following code to display their profile photos that grab from an acf image field called author_header. I put the users in an unordered lists by the following.
<div class="author">
<ul>
<li>
<?php
$publisher_photo = get_the_author_meta('author_header');
$image_src = wp_get_attachment_image_src($publisher_photo);
echo '<img src="'. $image_src[0] .'" />';
?>
</li>
</ul>
</div>
The problem I'm facing is that all the users get my profile photo. I want to be able to just grab the ones that they uploaded to the author_header field.
I have also tried this revised code but the img src doesn't show up.
<?php
$field_name = "author_header";
$post_id = "user_{$user_id}";
$publisher_photo = get_field($field_name, $post_id);
$image_src = wp_get_attachment_image_src($publisher_photo);
echo '<img src="'. $image_src[0] .'" />';
?>
I do have all of their names correctly displaying in the unordered list by the following.
<h2 class="authorName">[ <?php echo $user->display_name; ?> ]</h2>
You should add the user ID in get_the_author_meta like this:
$user_id = $user->ID;
$publisher_photo = get_the_author_meta('author_header', $user_id);
Please make sure that you will add this code in the loop, so user_id will be different for different user every time.
Regards,
Stanimir

How to make a userfeed scroll on a new mysql input?

I'm trying to make a userfeed for the homepage of my website that displays new information from users, for example: user x just did somthing.
This is what it looks like sofar: Image of page
this is the code used on the page:
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
echo '
<div class="media testimonial-inner">
<div class="pull-left">
<img class="img-responsive img-square" src="images/bierportaal.jpg" height="66" width="66">
</div>
<div class="media-body">
<span><a href="' . $row["naam"] . '"target=main>' . $row["naam"] . '</a></span>
<span>' . $row["tekst_before"] . '</span><a href="' . $row["item"] . '"target=main>' . $row["item"] . '</a>
<span>' . $row["tekst_after"] . '</span>
</div>
</div>
';
}
} else {
}
$db_conx->close();
?>
My question is, How do I rotate trough the activities?
So that when someone does somthing (it will be inserted into the database)the records jump and the top one will display a new record and the bottom one wil move out of the screen/disapear.
An example of what i have in mind is on this website the activetyfeed:
ratebeer website
Kind regards,
Aerosteon

Calling Php Strings from array

Hi I'm using this plugin called Meta Slider light and what I am trying to accomplish is getting the <li> to call the class of the image id.
Each Image has an ID and It calls the ID in the Img class but I want it to call it in the <li> class.
Below is the source code.
https://github.com/mihadaiko/ml-slider/blob/master/inc/slide/metaslide.image.class.php
on line 215 this code
'class' => "slider-{$this->slider->ID} slide-{$this->slide->ID}",
that code gives me this --> <img src="img url" class="slider-ID slide-ID">
The class calls for the Slider ID and The slide id.
and on line 347 it calls the <li> element.
$html = '<li style="display: none;"' . $thumb . '>' . $html . '</li>';
Each image is wrappen in an <li> element.
which gives me this
<li style="display:none;"><img src="img url"> class="slider-ID slide-ID"></li>
What I want to do is add the class line to the <li> element.
So far I have tried this
$html = '<li style="display: none;" class="slide-{$this->slide->ID}" ' . $thumb . '>' . $html . '</li>';
and it is still not working, it's calling the actual code instead of the image id. What am I doing wrong.
The value in there is most likely escaped before being printed. This means that your PHP is never given the chance to evaluate before being output on the page. I could be wrong, but it looks that way.
Try this instead
'class' => "slider-" . $this->slider->ID . " slide-" . $this->slide->ID,
edit, this
$html = '<li style="display: none;" class="slide-'. $this->slide->ID .'" ' . $thumb . '>' . $html . '</li>';

iFrame only works for first array?

I'm using FancyBox to contain my iframes, but it only works for the first array. Here's what the array looks like:
$gallery_items = array(
array("img_src" => "gallery/thumb_1.jpg", "link" => "gallery/profile1.txt"),
array("img_src" => "gallery/thumb_2.jpg", "link" => "gallery/profile2.txt"),
and so on, and then here is how it is produced:
echo '<li><a id="various3" href ="' . $current_gallery_item["link"] . '"><img src="' . $current_gallery_item["img_src"] . '" /></a></li>';
the id="various3" is how FancyBox tells its an iframe. But, it only works for the first array.
Revised answer:
It seems you don't want iFrames but just load the content via Ajax. Your problem is that every element has the same ID. If you attach Fancybox via
$('#various3').fancybox();
then it will only be applied to the first element, because IDs have to be unique.
Use classes instead:
<ul>
<?php foreach($gallery_items as $item): ?>
<li>
<a class="various3" href ="<?php echo $item['link']; ?>">
<img src="<?php echo $item["img_src"]; ?>" />
</a>
</li>
<?php endforeach;?>
</ul>
And jQuery:
$('a.various3').fancybox();
If you really want to have iFrames, you can just add the iframe class to the link elements:
<a class="various3 iframe" ...>
This will automatically tell Fancybox to use iFrames.
See also Fancybox - How to use.
foreach($gallery_items as $current_gallery_item){
echo '<li><a id="various3" href ="' . $current_gallery_item["link"] .
'"><img src="' . $current_gallery_item["img_src"] . '" /></a></li>';
}
Might work
You used the same id (namely, "various3") for several elements.
This will not work this way.
Every id should be unique.
assign some class to A-tags and use it:
$("#various3")
--->
$(".various3")

Categories