Viewing 8 replies - 1 through 8 (of 8 total)
  • Just put the image in the title of the post.

    I don’t think that would work. Did you try it, Evita?

    Yes moshu, I tried it local before I posted my answer.
    If this is not normally in WP, so maybe it works because I deleted the wp-autop in the functions.php?

    My plugin can let you do this:

    https://guff.szub.net/2006/02/09/post-image/

    Here is how to do it without a plugin:

    1- Start a post in wordpress

    2- Under custom fields create a key titled “img_post_header” or something similar

    3- For the value, insert the location of the image

    4- If you want more image atributes (such as alt text), make more keys and remember what they are called

    5- Save/publish that stuff

    6- Open /wp-content/themes/[themename]/index.php, after the <div class=”post”> but before the <h2> title (should be around line 9), add this line:

    <img src=”<?php echo get_post_meta($post->ID, ‘img_post_header’, true);?>” width=”600″ height=”200″ />

    Of course edit width and height to your specifications. If say you wanted to make the post title the alt text add: alt=”<?php the_title(); ?>” inside the img tag

    It took me some time to come up with this, and I hope it helps someone out there.

    marktastic, great work around… I am having some problems implementing it to do what I want though, and I’d much appreciate if somebody could help me…

    I don’t want it to try and load an image unless I’ve actually specified one, I get that I should use some kind of “if” but no idea how.

    Also, using “alt” and custom width and height must be easy, I suppose? Do I just add more custom fields and call them with something similar to “<?php echo get_post_meta($post->ID, ‘img_post_header’, true);?>”?

    // This statement checks to see if img_post_header exists and then if it does, write the img tag:

    <?php
    if(get_post_meta($post->ID, 'img_post_header', true))
    { ?>

    // We jump out of php to show the img tag. If you wanted you could do a print function instead, but this is how I did it.

    // I added an example of a specified alt text (the key was img_post_header_alt). If you want to do width and height make keys for them and add them the same way (make new keys). I would think it would be more ideal to have the width/height constant, but if it’s what you need then go for it:

    <img src="<?php echo get_post_meta($post->ID, 'img_post_header', true);?>" width="600" height="200" alt="<?php echo get_post_meta($post->ID, 'img_post_header_alt', true); ?>" />

    // This closes the if statement

    <?php } ?>

    Hope it helps!
    -Mark

    Thanks. That helped a lot.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘image above title of post’ is closed to new replies.