I am using wordpress acf plugin to show some custom images with their description and some text. So first I just made the acf plugin fileds like this and assigned the page to the home page with the conditional tags Location-> Rules-> Page->is equal to-> Home
now when I made my content-page.php to show the image code like this
<?php
if( get_field('image') ):
?><img src="<?php the_field('image'); ?>" alt="" /><?php
endif;
?>
I am getting only a broken image. The firebug is showing image source like this
Kindly help me to solve this. I have already wasted one day behind it. So any help and suggestions will be really appreciable. Thanks
Here is the screen shot for my custom fields setup
Here is the firebug html code which is showing the image source
Had this problem too. This is what I came up with that works:
<?php if (get_field('staff_photo')) {
$imgarray = get_field( 'staff_photo' );
?>
<img src="<?php echo $imgarray['url'] ; ?>" alt="" class="staff-photo" />
<?php } ?>
So, what I did was put get_field('field_name') array into a variable, then took a WAG that the key was 'url', which it was. Seems like the ACF people need to update their documentation.
Hah! Discovered another way -- this way you can pick a size:
<?php
if ( get_field('staff_photo') ) {
$imgarray = get_field( 'staff_photo' );
$size = "thumbnail"; // (thumbnail, medium, large, full or custom size)
echo wp_get_attachment_image( $imgarray['id'], $size );
}
?>
For wp_get_attachemnt_image to work, you have to extract the image id, for which the key is, ta-da! 'id'.
Related
Orignal Code
<h5 class="entry-title">'.get_the_title().'</h5>
I want to add this code that ACF image field to show and it replaced on title
<?php $shortlinestory = get_field( 'shortlinestory' ); ?>
<?php if ( $shortlinestory ) { ?>
<img src="<?php echo $shortlinestory['url']; ?>" alt="<?php echo $shortlinestory['alt']; ?>" />
<?php } ?>
My Custom image field name is shortlinestory in a widget i want to show the recent image please help me thanks
To get the custom field of a widget you have to add an additional parameter in the get_field() function. Advanced Custom Fields has pretty decent documentation and it is explained here how to do that.
First you have to figure out the ID of the widget. This is passed to the function that creates the widget for example $widget_id = $args['widget_id']. Then you can use the_field('field_name', 'widget_' . $widget_id) to get the custom field value.
Hope that helps you out, good luck!
I am using the Plugin Auto Featured Image to set thumbnails automatically. And in the database it shows updated meta thumbnail key.
But for some reason it is not showing the featured image. It doesn't show a "placeholder" neither. It just shows nothing at all.
Also, when I try to view the attachment on a single page, it does not show it.
How can I proceed to find the problem? If you need more screenshots of different tables on my database, please ask. I really appreciate your time.
EDIT
$meta_values = get_post_meta( $POST_ID, '_thumbnail_id');
error_log(var_dump($meta_values)) //Prints nothing on error log
//Note: $POST_ID is fine, it contains the right id. Problem not there.
EDIT 2:
if ( has_post_thumbnail($post_parent_id) ){
error_log("THUMB EXISTS". get_post_thumbnail_id($post_parent_id));
}
Really weird result:
THUMB EXISTS: "Blank space, No id or string at all"....
1) get post thumbnail with post id full description
<?php echo get_the_post_thumbnail( $page->ID, 'thumbnail' ); ?>
2) In a loop full description
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
}
?>
3 want to get the thumb url ?? . Use this
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
<img src="<?php echo $url; ?>" longdesc="URL_2" alt="Text_2" />
I want to remove the featured image in post and page, but keep it as thumbnail so that the site look good! My site is a wordpress based site.
Here's an example post of the site: http://www.tradingspotsilver.com/build-mt4-custom-ea-indicator-forex-free/
You could see that the featured image is on top of the post and occupy a lot of space. I've tried to look at the theme source but no luck.
The link given in your question is a single post page, you look in to your theme's root folder and can find a file named single.php, in that file you may find something like this
// "custom_size" could be anything like "single_page_image"
if ( has_post_thumbnail() ) : the_post_thumbnail('custom_size');
This line of code is responsible for showing the big image. Just remove this line and your image will not show up. Also, you may check this answer for custom image sizing.
For page template, you may look for a file named page.php and look for the similar code.
you can use timthumb for resizing:
with the code here: { https://code.google.com/p/timthumb/source/browse/trunk/timthumb.php }
create a file named timthumb.php in your theme folder, and at the place of the featured image php script, type:
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
//the_post_thumbnail();
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<div class="img-hold"> <img src="<?php bloginfo('template_directory') ?>/timthumb.php?src=<?php echo $url; ?>&w=219&h=125" width="219" height="125" /></div>
<p><? }
echo $content;
?></p>
change the value of height and width as per your wish at &w=, &h= and also width= , height=
hope this helps
just remove the the_post_thumbnail code in the single.php and page.php or content.php.
this function use in wordpress for show featured so just remove or comment it.
check your single.php and content.php page to solve this problem its right there
if you dont require that code comment it / or modify it as you want.
dont mess things go easy with it or otherwise you will end up getting error
I had the same issue and i could not find any solution in single.php
Its simple although:
just comment:
from content.php page
This is for the Dazzle Theme
I found mine in "content-single.php and removed :
<?php the_post_thumbnail( 'dazzling-featured', array( 'class' => 'thumbnail' )); ?>
Picture was gone from post.
It is obviously varies depending on theme.
For theme Freemium you need to remove the following lines in wp-content/themes/freemium/single.php:
<?php $freemium_feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); if($freemium_feat_image!="") { ?>
<img src="<?php echo $freemium_feat_image; ?>" alt="Banner" class="img-responsive img-responsive-freemium" />
<?php } ?>
Hi Guys Need help with this very badly.
Need to add shortcode to output in the area circled in white in the picture below.
And the input area is under video description. And from my understanding ive have confirmed that the name for that text area is description_value.
I have looked through every documentation and tried all filters and do_shortcode variations to no avail. Please help i have spent 3 days non stop doing this. Puting the codes in my function.php and so many others. It still does not parse [shortcodes] it just displays text "[shortcodes]". please refer to picture below
Thank you.
This is outputing on the page. I have
<div class="describe-feat">[postexpirator]</div>
This is in a file called grid-gallery.js
<h2><%= item.title %></h2></div><div class="view-gallery">\
<div class="describe-feat"><%=item.desc%></div>\
<% if(item.imgnum){ %><span class="item-num"><%= item.imgnum %></span><% } %>\
This is in custom post editor in wordpress admin area
<textarea name="description_value" class="option-textarea">[postexpirator]</textarea>
https://www.dropbox.com/s/almn09e1dwmeywb/shortcodxe.jpg
It's because, you are missing do_shortcode function for parsing shortcode.
Assuming you just want to target a single value, you could just do this inside the loop.
<?php echo ( do_shortcode( get_post_meta( $post->ID , 'Your textarea Key Name' , true ) ) ); ?>
If your post has multiple values for that custom field, then you can set the above to false.. and loop over the array...
<?php $values = do_shortcode( get_post_meta( $post->ID , 'Your textarea Key Name' , false ) ); ?>
<?php if($values && is_array($values)) : ?>
<?php foreach( $values as $meta) : ?>
<p><?php echo $meta ?></p>
<?php endforeach; ?>
<?php endif; ?>
Just want to add that if you won't use the_post() no shortcode will work,
I had this issue when trying to enable shortcode on CutomFields on a new page type, and nothing worked until activating WP loop with the_post() .
I know this may be a simple question but I am a total beginner at Wordpress coding and PHP. I am looking to embed five attachments to each post on my site, so I know it has got to do with inserting something into single.php or loop.php. So let's say I have 8 or 10 photos attached to a post, I want the single post page to show 5 of those photos and have a link to the 'gallery'/attachment.php page. Something like what this website does on this page, the 6 photos at the end of the post entry (http://www.celebuzz.com/2011-05-27/kim-kardashian-kris-humphries-makes-first-post-engagement-public-appearance-photos/)
I have tried using the wordpress [gallery] insert but all it does is show all the pictures and I don't want to use a plugin because I feel that it is overkill and all it needs is some code to call up 5 attached photos. Hope someone can help. Thanks in advance
Try using custom field template plugin
http://wordpress.org/extend/plugins/custom-field-template/
I know you don't want to use plugin. But, for the sake of the questions and I know someone will eventually landed here from search engine.
You can use attachment plugin. This plugin is quite simple and very straightforward.
Once installed, it will add new meta box on post creation page.
You can add as much as images you like and the loop part of your template page, you add this snippet:
<?php
if( function_exists( 'attachments_get_attachments' ) )
{
$attachments = attachments_get_attachments();
$total_attachments = count( $attachments ) > 5 : 5 : count( $attachments );
if( $total_attachments ) : ?>
<ul>
<?php for( $i=0; $i<$total_attachments; $i++ ) : ?>
<li><img src="<?php echo $attachments[$i]['location']; ?>" alt="<?php echo $attachments[$i]['title']; ?>" /></li>
<?php endfor; ?>
</ul>
<?php endif; ?>
<?php } ?>