WordPress.org

Ready to get started?Download WordPress

Forums

conditionally displaying an image (19 posts)

  1. anatman
    Member
    Posted 10 years ago #

    Hey,
    I don't know if this can be done, but i would like to post an article with a "more" tag in it, nut with an image before the "more" tag. However i want the image to be displayed only if the permalink is clicked, not if the teaser only is visible.
    Better yet would be to display only a thumbnail in the teaser, but the full image in the complete article (i can of course prepare the thumbnail manually, no need to use a photolog hack).
    Any idea how to do this?
    Thanks,
    Eduardo

  2. carthik
    Member
    Posted 10 years ago #

    If it is before the more tag, then when someone clicks on it, the image won't be visible, 'cause clicking on the more tag by default takes you to the position of the more-text in the page..(scrolls down that far automatically.
    Why don't you put the image inside the more-text, so that only someone who clicks the more link can see it?

  3. anatman
    Member
    Posted 10 years ago #

    Hm, yeah. I forgot that the page will scroll down...
    The reason for the question is: i would like to have a light-weight (a few KBs) thumbnail to make the post look good and attract atention, and when the permalink was clicked the reader would see the full-sized picture (like 50-90KB).
    I would have a few posts (five) like this on the front page: if i don't use thumbs, the page will be heavy and slow to load. If i use the thumbs, it won't be too heavy and i still keep some of the colorful looks on the front page.
    Anyway, if it can't be done i will put the image after the "more" tag...

  4. tamper
    Member
    Posted 9 years ago #

    I think the above is what I'm looking for too:

    Bascially I'd like a convenient method of adding an image to a post, such that an auto-generated thumbnail appears with the post intro, but the full-size image appears on the post's permalink page, along with the full-text of the post.

    Is there a favoured image plug-in that will handle this?

    Cheers,
    tamper

  5. rocky2889
    Member
    Posted 9 years ago #

    I am looking for this too. I think is possible by modify the single.php to exclude the thumbnail and replace with fullsize image. If only I am the expert of the php scripts.

    Let says:
    * Large and small image show up at same spot in post & single page
    * Large file is something like myimage.jpg
    * Small file has same name, but with "-thm": myimage-thm.jpg

    So when you click on the permalink bring you to the single.php and the single.php just strip off the "-thm" so the image will display on the single page.

  6. wesley88
    Member
    Posted 9 years ago #

    I am also looking for this plugin.

  7. mumkin
    Member
    Posted 9 years ago #

    Depending on how much text you want to display for your post's intro, you could just embed your thumbnail in the post's excerpt. call the_excerpt in the loop on index.php and the_content on single. A bit annoying to have to do for every post, but it's one way to accomplish your goal short-term.

  8. wesley88
    Member
    Posted 9 years ago #

    Mumkin, I total agreed with you. It pain in the $ss to do that every post.

  9. mumkin
    Member
    Posted 9 years ago #

    The Excerpt Reloaded plugin may go some way to streamlining the process, though I've not tried it myself.

  10. wesley88
    Member
    Posted 9 years ago #

    I am trying to use "The Excerpt Reloaded Plugin" I can't get the thumbnail to show on the frontpage and the full fullsize image to show on the full page. Do you have any ideas how can I accomplish this task. Thanks

  11. kektex
    Member
    Posted 9 years ago #

    I am also looking exactly for this...I want to show just a thumbnail in the front page and full size image on the posts page. I think rocky2889s (6 posts above this) idea is the best way.
    Im willing to try this but I have no idea where in the code this can be done. Im thinking maybe in the comments page of your template but Im really not sure.
    If anyone tells me where to start looking , I
    ll find a way to hack something up.

  12. Root
    Member
    Posted 9 years ago #

    Let us just reexamine what the question really is. Something like *Can we put php in the middle of post text* ? The answer probably is yes we can. But not without very considerable rengineering I would think. Plugins are going to be needed. Hacking is going to be required. But yes. In principle why not ?

  13. kektex
    Member
    Posted 9 years ago #

    Isnt there a way to tell if we are currently in the comments page?
    I was thinking of adding code to the start of the comments page for the template I
    m using.I saw this at the beggining but Im not sure if this is what Im looking for:

    if ('comments.php' == basename($_SERVER['SCRIPT_FILENAME']))
    die ('Please do not load this page directly. Thanks!');

    Cant I add a piece of code similar to that that will tell it to load
    img.jpg instead of img_thm.jpg?

    Ive just started using WP a few days ago so Im still learning how it works.Im looking through the wiki but some parts are not complete.

  14. Root
    Member
    Posted 9 years ago #

    is_single() will get us started.The respective file paths need to be stored in a new variable I would think.

  15. kektex
    Member
    Posted 9 years ago #

    alright I was just reading upon is_single() Root
    One thing Im still not getting:
    You are saying that you can
    t (or at least it would take too much work) insert php code in to a post? From what Ive read the part Im interested in would be The Loop. Maybe I could use a plugin I saw somewhere for inserting PHP code into a post?

  16. kektex
    Member
    Posted 9 years ago #

    All right, I got this working. I set it up on my test blog and its working perfectly for now.Im using Photopress and Priyadis PHP Exec plugin.
    1)Get both plugins
    -PHP Exec Plugin
    -Photopress

    Install them both as you normally would.

    2)Now as per the PHP Exec plugins instruction insert php code in your post like this:


    <phpcode>
    <?php
    if (is_single()) {
    echo "<img src=http://example.com/wp-content/photos/photo.jpg><br>
    This is for post page";
    }
    else {

    echo "<img src=http://example.com/wp-content/photos/thumb_photo.jpg width=130 height=69><br>
    This is for frontpage ";
    }
    ?>
    </phpcode>


    You can see it in action Here
    It really wasnt that hard and my php knowledge is practically zero.Im sure someone can make it much prettier.
    Photopress makes the thumbnailed image automatically for you so you only have to upload your picture and tell it to post the thumbnail.Then just copy and paste the image insertion code into the code I posted above. You cant preview so try testing it somewhere first.
    I
    m going to try to merge this into Photopress so you don`t have to go cutting and pasting stuff everywhere and it places everything in its place.
    This code might also have to be edited to display thumbnails for frontpage and archive pages depending on whether your template shows posts while in the archive

  17. rocky2889
    Member
    Posted 9 years ago #

    kektex, is working fine if you don't use the Wysi-Wordpress. I am using Wysi-Wordpress, so this solution doesn't work. I am looking to find another solution to embed code in the single(). Thanks

  18. Root
    Member
    Posted 9 years ago #

    OK here is a butt ugly but non php kluge. We edit quicktags js and add a new image tag with a new class. In the CSS that class is set to display:hidden. It wont show. In our single view (either another template or by using is_single) we call further CSS to overrride the first so now the image appears. Magic. I will leave you guys to figure out the details :)

  19. kektex
    Member
    Posted 9 years ago #

    rocky2889 I really couldnt tell you since Im just getting started with wordpress. I was just reading on wyi-wp.Isn`t there a way to post sometimes with the wysi plugin and other times without it?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags