WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Resizing of an image inside of an article (14 posts)

  1. ohrobot
    Member
    Posted 8 years ago #

    On the frontpage the teaser images should be clickable to get into one article. But within the article it shouldn't be a link anymore(!). How can I achieve this?

    I'm looking forward to any idea..

    :)
    Bernd.

  2. w3central
    Member
    Posted 8 years ago #

    If you allow php into your posts (there are some plugins for that) you could do it with a conditional:

    if not single: img thumb links to article
    else: full img

  3. ohrobot
    Member
    Posted 8 years ago #

    I thought this is kind of a standard-thing. Is there a plug-in for this solution too? (I have to admit that I am kind of afraid of having to insert php-code in all of my articles)

  4. Kafkaesqui

    Posted 8 years ago #

    A couple options:

    1. Place the thumbnail in the post, with the following two line after it:

    <!--noteaser-->
    <!--more-->

    (Info on "read more" feature.)

    Then follow that up with the full image, post text, whatever. This however does not make the thumbnail a permalink to the post. For that we need a bit of PHP (placed once in your template, not in each post) to parse out the thumbnail image and display it as the link:

    <?php
    preg_match("/(<img[^>]*>)/i", get_the_content(), $thumb);
    $thumb = trim($thumb[0]);
    ?>
    <a href="<?php the_permalink(); ?>"><?php echo $thumb; ?></a>

    2. Install my Post Image plugin, and in your template use:

    <a href="<?php the_permalink(); ?>"><?php post_image('', true); ?></a>

    With this, the uploaded/attached image to a post (with full image placed in the post content) will make use of the thumbnail as a link.

    ----------

    Note in both cases you want to replace the_content in your template (typically the theme's index.php) with the specified code. You should also have a single.php template (for displaying the individual posts), which has the_content() as normal.

    Pro/Con: Second option provides more automation (just upload the image and forget about setting things up correctly in each post), but the first gives you more control over what image/thumbnail to use, as well as not relying on WP2's built-in image attachment stuff.

  5. ohrobot
    Member
    Posted 8 years ago #

    em.. but what if there is a post with no picture. Doesn't these changes in the template mean that there has to be an image in every post or at least the template tries to display one.
    oh, perhaps I didn't get the point. :(

  6. Kafkaesqui

    Posted 8 years ago #

    "em.. but what if there is a post with no picture."

    Ah, but you didn't ask for that option! ;)

    1. Same initial steps, but revision to code displays post content (i.e. the_content()) if a post has no images:

    <?php
    preg_match("/(<img[^>]*>)/i", get_the_content(), $thumb);
    $thumb = trim($thumb[0]);
    ?>
    <?php if($thumb) : ?>
    <p><a href="<?php the_permalink(); ?>"><?php echo $thumb; ?></a></p>
    <?php else : ?>
    <?php the_content(); ?>
    <?php endif; ?>

    2. Does same (post content if no image attachment). Made a tweak to Post Image (now R1) that'll allow this:

    <?php $thumb = szub_post_image('&use_thumb=1&display=0'); ?>
    <?php if($thumb) : ?>
    <p><a href="<?php the_permalink(); ?>"><?php echo $thumb; ?></a></p>
    <?php else : ?>
    <?php the_content(); ?>
    <?php endif; ?>

  7. ohrobot
    Member
    Posted 8 years ago #

    oh, thank you so much.
    I feel i am very close now..
    i need only one more piece of the puzzle..
    How can I attach an image (in order to use it with post_image) to a post without actually inserting it?

  8. Kafkaesqui

    Posted 8 years ago #

    How do you mean? Using WordPress 2.0.x, Post Image works with images uploaded through the new post editor's upload utility. Images uploaded while creating/editing a post are considered to be "attachments" to that post. So if by "without actually inserting it" you mean you don't want to place the image (or thumbnail) in the post, it already works that way; it will automatically display it.

  9. ohrobot
    Member
    Posted 8 years ago #

    ok.
    the good news is: the enlarged image inside the article works (as as there is an image).

    the bad news (you can look it up on my site http://www.videofanzine.de - a german ezine about, yes - videofanzines ):

    in my single article view - template I inserted, like you said:

    <?php $thumb = szub_post_image('&use_thumb=0&display=0&css_class=articleview'); ?>
    <?php if($thumb) : ?>
    <?php echo $thumb; ?>
    <?php else : ?>
    <?php the_content(); ?>
    <?php endif; ?>

    and my index has this new lines of code:

    <?php $thumb = szub_post_image('&use_thumb=1&display=0&css_class=frontpageview'); ?>
    <?php if($thumb) : ?>
    "><?php echo $thumb; ?>
    <?php else : ?>
    <?php the_content(); ?>
    <?php endif; ?>

    so two last (i wish) problems:
    1. on the frontpage there's a link called 'Array' instead of the attached image
    2. when there's no image the text-content is displayed twice.

    I ask myself continuously - what have done wrong?

    Thank you so much so far!

  10. ohrobot
    Member
    Posted 8 years ago #

    1. on the frontpage there's a link called 'Array' instead of the attached image

    hmm.. this problem seems to have something to do with "&use_thumb=1" ..is it possible that there was no thumbnail created, yet?
    if I insert an image in a post manually (by send to editor) there is a thumbnail..thus the grafic functionality of my webserver seems to work.
    I have no idea :(

  11. ohrobot
    Member
    Posted 8 years ago #

    i made further observations..

    I have installed a german Version of WordPress 2.0.2. This means the thumbnail images are called e.g.
    "Slices106Vorschaubild.jpg"
    for the original-image "Slices106.jpg"
    -Vorschaubild- is the german term for thumbnail. Could this cause my problem with displaying thumbnails with szub_post_imagw()?

  12. ohrobot
    Member
    Posted 8 years ago #

    Yessss! That was the problem!

    I had to change line 75 to:
    $img_url = preg_replace("/.$ext$/", "Vorschaubild.$ext", $img_url);

    now it works with my german wp version, too
    :)

  13. Kafkaesqui

    Posted 8 years ago #

    Hmm. Suspect I should make the "thumbnail" insert a little more configurable...

  14. Rod
    Member
    Posted 7 years ago #

    Hummm I have a problem ...

    I use WordPress as gallery system but 100% FTP upload ... so I would like to know if it's possible to use the plugin

    ... my "default" upload is http://www.le-hiboo.com/wordpress/wp-content/uploads/ (uploaded with the WP upload system) ... and my photos are inside http://www.le-hiboo.com/wordpress/wp-content/uploads/albums/ (by FTP ...) an example result is = http://www.le-hiboo.com/clubbing/soiree-disco-au-so-be-concept/

    As you can see, on the right, I use post_image perfectly for CD and CINEMA ... (pics are up by WP upload system) ... is here a hack to take the first pic of a post gallery to realize the same thing ?

Topic Closed

This topic has been closed to new replies.

About this Topic