SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to get featured image link url?

    Hi guys I have been trying to get the set the featured image url but it I can only link to the post itself or to the image itself, when I add featured image on the link URL I add a different link but it doesnt work is there a way I can add different link on the featured image and then retrieve this link on the code? so it would be something like

    <a href="<?php link_url(); ?>"><?php the_post_thumbnail('medium'); ?></a>

  2. #2
    Quality not quantity. bo5ton's Avatar
    Join Date
    Oct 2003
    Location
    Australia
    Posts
    654
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    This depends on whether you want to get the featured image for the individual post or for multiple posts (for example on a blog index page).

    For a single post you can just use the function get the post thumbnail which you can read about in the Wordpress Codex here.

    You also need to first enable featured images in your wordpress theme if you're starting from scratch or your theme isn't currently 'featured post' enabled. You can do this by putting:

    Code PHP:
    add_theme_support( 'post-thumbnails' );

    in your functions.php file

    But basically something like this should work:

    Code PHP:
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?> //This is your loop starting, it is used in most Wordpress themes.
     
    <?php 
    if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
      the_post_thumbnail();
    } 
    ?>
     
    <?php endwhile; endif; ?> //This is your loop ending.

    Looking at the codex link above you'll also find you're able to specify sizes.

    Hope this helps.

  3. #3
    SitePoint Addict
    Join Date
    Apr 2010
    Posts
    390
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi the featured image display fine what I am trying to do is link the featured image to something else, when you upload the image the upload box theres is the Link URL,so I had to link to a another website but it doesnt link? or even save teh Link URL is it only possible to link to image path or the page itself??


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •