WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] different links for same image (5 posts)

  1. bloggingcss
    Member
    Posted 5 years ago #

    Hi all,

    I'm quite new to WordPress, but I think I did a good job at customizing the Kubrick theme over at my brand-new blog.

    I have a technical question though. As you can see on the blog home page, I've got big images for each post which of course is the same you see on the post single page. What I'd like to do is make the image on the home page link to the post permalink, so that when I click on it the post page opens up; but once I'm on the single page, I want that same image to link to an external website. How do I do so?

    To get the image on the home page I'm using the_content(), with a "read more" link between the parenthesis (which I customize thanks to the Headspace plugin). Don't know if this has anything to do with it.

    Hope I can get some help!

    TIA

  2. lhoylhoy
    Member
    Posted 5 years ago #

    edit your index.php and single.php, index.php to link to your permalink(to your post) and single.php(to whatever link you want)

  3. blogbreaking
    Member
    Posted 5 years ago #

    Im not sure if theres a way to do conditionals within a blogpost,

    A way that would work is if you were to use a custom field and store the url to your photo in each post.

    http://codex.wordpress.org/Using_Custom_Fields
    http://codex.wordpress.org/Function_Reference/get_post_meta

    Then in your index.php file, in your loop pull out the custom field into an image tag and wrap it with an link tag that links to your permalink. Use the except field in to copy the first paragraph of your post and pull the excerpt out in the loop as well.

    Something like this:

    <a href="<?php the_permalink() ?>"><img src="<?php echo get_post_meta($post->ID, pic, true); ?>" alt="<?php the_title(); ?>" border="0" /></a>
    
    <?php the_excerpt(); ?>
  4. bloggingcss
    Member
    Posted 5 years ago #

    Hi blogbreaking,

    thanks for your answer. However I don't think that yours can be a solution since I add the code for the image in the WordPress dashboard, not directly in the index.php file (not all of my posts have that structure).

    Thanks anyway ;)

  5. bloggingcss
    Member
    Posted 5 years ago #

    I came up with a solution, which turns out to be very similar to the one blogbreaking has posted.

    I found it in this post by Nick La. It's the snippet under "Custom field".

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags