Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Wordpress Question

Featured Replies

Hello,

 

I am a bit stuck on getting an image to show.

 

I want an image (thumbnail) to be set via Featured Image. Easy.

Next, I want to be able to click on the image and get the original, full size image to appear...Not so easy.

 

Can anyone help me with this?

 

here is my code:

 

<a class="fancybox" title="<?php the_title(); ?>" href="???????"><?php the_post_thumbnail( 'artwork-thumbnail' ); ?></a>

 

Cheers

  • Author

If someone can help me with this, I am willing to pay £10.

 

I am totally stuck and have tried several different approaches with no luck, I am not a PHP expert so that doesn't help!

 

Basically, I need a dynamic way of calling the original size image when the thumbnail is clicked on, and maybe (if poss), to make it so that it's not over 800px wide. As if the user uploads a very large image, then that would be no good when blown up full size!

 

If someone could let me know if they can do this, I'd be very happy man!

 

I can give you access via FTP to do this.

 

Here is the page so you can get an idea whats going on: My link

 

Huw

Would love to help - but you know my Wordpress / PHP knowledge! Hope you get it sorted :)

 

Gem

  • Author

Are you using a custom field for the image URI?

 

I am using the 'Featured Image', section of a custom post. And the post_thumbnail snippet to display it.

 

 

 

I didn't want to use custom fields to make this site as easy as possible as the client (my auntie!) isn't very tech savvy, at all!

 

:)

I think your hyperlink needs some work. You want it set up so that the hyperlink calls the image that you've uploaded, so you need to work out how Wordpress stores the images that you're uploading. I think the default is in date and time folders, so your link will be something like this:

 

<a href="http://www.yourdomain.com/wp-content/uploads/<?php the_time('Y') ?>/<?php the_time('m') ?>/<?php the_title(); ?>.jpg" class "fancybox"></a>

 

Will take a bit of fiddling, but I hope that helps. :)

Use this instead. In functions.php add

 

if ( function_exists( 'add_theme_support' ) ) { // Added in 2.9
add_theme_support( 'post-thumbnails' );
add_image_size( 'artwork-thumbnail', 171, 171, true ); 
}

function artwork-thumbnail-image(){

if ( has_post_thumbnail() ) {
 the_post_thumbnail( 'artwork-thumbnail', array('class' => 'postim') );
} else {?>
<img class="postim" src="<?php bloginfo('template_directory'); ?>/images/defaultthumb.gif" alt=""  />
<?php
};

}

 

Modify defaultthumb.gif to your default image which you want to show when their is no image uploaded.

 

Than modify your code to

 

<a class="fancybox" title="<?php the_title(); ?>" href="???????"><?php artwork-thumbnail-image()?></a>

ah you want full image as well. You will have to use a custom field as well and that insert custom field value in href="" tag because featured image function outputs code in img tag not in a simple link. Maybe some php guru can help here.

This code is common to enable WP Thumbnail support. Put this in your functions.php

 

functions.php

if(function_exists('add_theme_support')) 
{
	add_theme_support('post-thumbnails');
               // This is the small version for a list of posts.
	add_image_size('small-thumb', 150, 150);
               // This is the medium version, style as you see fit.
	add_image_size('medium-thumb', 420, 9999);
	// This is the large version (arbitiary large version) for single and full view.
	add_image_size('full-thumb', 800, 9999);
}

 

index.php

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>            
               <div class="post">
                   <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                   <a href="<?php the_permalink() ?>"><?php the_post_thumbnail('small-thumb') ?></a>
                   <?php the_excerpt(''); ?> 
                   <a class="more" href="<?php the_permalink() ?>">Read more . . .</a>
               </div>
               <!-- END post -->         		
           <?php endwhile; else: ?>        	
           <p>There have been no posts created yet.</p>            
<?php endif; ?>   

 

single.php

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>            
               <div class="post">
                   <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
                   <a href="<?php the_post_thumbnail('full-thumb') ?" class="fancybox"><?php the_post_thumbnail('medium-thumb') ?></a>
                   <?php the_content() ?>
                   <a class="more" href="<?php the_permalink() ?>">Read more . . .</a>
               </div>
               <!-- END post -->         		
           <?php endwhile; else: ?>        	
           <p>There have been no posts created yet.</p>            
<?php endif; ?>   

 

 

I assume for a fancy box to work you apply a class of "fancybox". So give the anchor the path to the large and the image the path to the small or any other combo. You can create as many versions as post thumb passing the parameter of a name. Then call the function with the desired size / name from any theme file as desired.

why don't you simply use this plugin ?

http://www.pedrolamas.com/projectos/jquery-lightbox-en/

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.