Wordpress: How to get a thumbnail post plugin to work - wordpress

I need a second opinion on something. I am trying to use the WP Post plugin as described in the following link:
http://www.seoadsensethemes.com/wordpress-wp-post-thumbnail-plugin/
You will see a section toward the bottom stating that you can call the feature using the following code:
$Wppt->get_post_thumbnail( $post->ID, 'post-thumbnail-square' );
It shows the following example inserted into the post loop:
<!-- wp post thumbnail -->
<?php if ( function_exists( "$Wppt->get_post_thumbnail" ) ) {
$thumb = $Wppt->get_post_thumbnail( $post->ID, 'thumbnail-custom-key-name' );
if ( !empty( $thumb ) ) { ?>
<img class="thumbnail" src="<?php echo $thumb['url']; ?>" title="<?php echo $thumb['title']; ?>" alt="<?php echo $thumb['alt']; ?>" width="<?php echo $thumb['width']; ?>" height="<?php echo $thumb['height']; ?>" />
<?php }
} ?>
<!-- wp post thumbnail -->
I cannot get this to work. Can someone tell me how this should specifically be used? I am simply pasting the code above my loop on the default theme, replacing the 'thumbnail-custom-key-name' with the one assigned to my thumbnail. Is this the right way to do it?

In your sample code it looks like you're using a default value 'thumbnail-custom-key-name' is that the name of an actual preset you've made?

Related

Wordpress - Need to pull ALT text from images

Can Somebody Help how to pull alt text from wordpress images in the following code??
<?php $logos = get_field('upload_logos');
$size = 'full';
if( $logos ): ?>
<div>
<div>
<?php foreach( $logos as $logo ): ?>
<div>
<div class="ccrc-logo-box-inner"><img src="<?php echo wp_get_attachment_url( $logo['ID'], $size ); ?>" alt=""></div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php endif; ?>
You are using get_field() function, so I guess you have 'Advanced Custom Fields' plugin. You want to get the data of a field with type of image. So looking at the documentation:
https://www.advancedcustomfields.com/resources/image/
You can access the alt text from the field object, the same way you already did it with $logo['ID'] before.
<img src="<?php echo wp_get_attachment_url( $logo['ID'], $size ); ?>" alt="<?php echo $logo['alt']; ?>">
You are using the wp_get_attachment_image() function to output your url
Documentation of wordpress tells us you can pass the alt as a parameter to fetch and output it:
https://developer.wordpress.org/reference/functions/wp_get_attachment_image/#parameters

ACF insert logo from option page

Using the plugin ACF
I want to insert from an options page, the logo in the header of all pages
I can not get the image url
<?php $logo = get_field( 'logo', 'option' ); ?>
<?php if ( $logo ) : ?>
<img src="<?php echo $logo['url']; ?>" alt="<?php echo $logo['alt']; ?>" />
<?php endif; ?>
What is the right method?
thank you
This code works for me. Make sure the image "Return Value" is set to "Image Array" in ACF settings.
<?php
$website_logo = get_field('website_logo', 'option');
if( !empty($website_logo) ):
?>
<img src="<?php echo $website_logo['url']; ?>" alt="<?php echo $website_logo['alt']; ?>">
<?php
endif;
?>
I had the same problem but a fix it.
First I put the ACF "logo" in a page, then a use the ID of this page to put the logo in header, at last I call the logo in header.php like this:
<?php
$logo = get_field('logo', 5); // 5 is the ID of the page where I put the logo
$size = 'full';
?>
<div id="logo" style="padding-top:10px;"><?php echo wp_get_attachment_image( $logo, $size ); ?></div>
Enjoy!

Add image URL to ACF Gallery images

I have ACF set up in WP with a Gallery field. Currently I am displaying my images as follows:
<p><?php echo get_the_content(); ?></p>
<?php $images = get_field('gallery_images');
if( $images ): ?>
<div>
<ul>
<?php foreach( $images as $image ): ?>
<li class="portrait float">
<img src="<?php echo $image['url']; ?>" />
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif;
?>
I have also installed the Simple Lightbox Plugin but have been unsuccessful so far. How do I add the URL link of my ACF Gallery images. I have tried wrapping my image tag in a link tag with rel="lightbox" and several other variations including:
<img rel="lightbox[gallery_images] src="<?php echo $image['url']; ?>" />
Is there any way I can enable Attachment Display Settings for my ACF Gallery images in my WP post. I think this might be handy to have?
Any help is much appreciated :)
I used the following which worked.
<img rel="lightbox[gallery_images]" src="<?php echo $image['url']; ?>" />
All my images are full size so didn't need the following at all:
echo $image_large[0];

Getting image alt text in Wordpress slider

Our web site is using the theme's slider.php on our front page. I'd like for the images displayed in that slider to use the alt text that is in the post meta (edited in the WP media library).
I've attempted to create a variable ($alt), and have that variable echoed when the img is called, but is coming up empty. Here's the relevant portion of slider.php:
$alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
<img src="<?php echo $thumbnail[0]; ?>" alt="<?php echo $alt[0]; ?>" />
</a>
<?php else: ?>
`
Any idea what I'm doing wrong?
You have set the third argument as true which means the function get_post_meta returns a string;
http://codex.wordpress.org/Function_Reference/get_post_meta
Therefore the following should work instead;
<img src="<?php echo $thumbnail[0]; ?>" alt="<?php echo $alt; ?>" />
Okay - so I've figured this out. The code above is trying to get the post meta from the thumbnail of the image - and, to my knowledge, the thumbnail image doesn't have meta data.
I've just created a custom field, and now the slider loop call thats field.

wordpress featured posts

i'm trying to create a portfolio website using wordpress,
each post has view costum fields, one of which is called type - with the value of "featured" or "not-featured"
now when user clicks on the post title - they go the the single.php to see the entire post, here i would love to display all featured thumbnails
i tried this
<?php while ( have_posts() ) : the_post() ?>
<?php if(get_post_meta($post->ID, 'type', true) == "featured") {; ?>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark">
<img src="<?php echo get_post_meta($post->ID, 'intro_thump', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" />
</a></h2>
<?php }; ?>
<div class="entry-content">
</div><!– .entry-content –>
<?php endwhile; ?>
(THIS CODE IS SIMILAR TO THE CODE I USE AT INDEX.PHP AND THERE IT DOES WORK, HERE AT SINGLE.PHP IT DOES NOT WORK)
but this does not display all the thumbnails (only the current posts' thumbnail (is it's a feature post))
this is my first attempt of trying to create a theme from blank so i'm not sure what the error could be
thanks for your help
The code in your question only loops through the posts returned by the query made for the current view, in the case of a single post view that is one post. You want to perform a new query to retrieve all the posts that have the required meta value:
<?php
query_posts(array("meta_key" => "type", "meta_value" => "featured"));
if (have_posts()) : while (have_posts()) : the_post();
?>
<!-- Display thumbnails -->
<?php endwhile; endif; ?>

Resources