Support » Themes and Templates » Conditional code to relative position attached images only

  • Hey everybody,

    So I got the idea to write a grid-style theme with a clickable thumbnail above each post.

    My one question so far is how to make it so that the default thumbnail (for posts with no image) stays right where it is, but when an attached image is displayed as the thumbnail, it is moved relatively upward.

    I have tried adding <?php ( if is_attachment()) { echo 'class=""' }; ?> to my existing code like this:

    <img <?php ( if is_attachment()) { echo 'class=""' }; ?> border="0" width="200" src="<?php echo catch_that_image() ?>" alt="<?php the_title(); ?>">

    to see if I could assign a class only to attached images, but I get this error:

    Parse error: syntax error, unexpected T_IF in /blah/blah/blah/wp-content/themes/WFHS/index.php on line 16

    I’m sure this must be simple. I just want to assign a class only to attached images so that the default image can stay in place and attached images can be positioned relatively upward (like position: relative; top: -15px; or something).

    If you want to see the page it’s here. I’m using my old high school as a guinea pig for the theme. The content is all from feeds (just for the example).

    You can see that by displaying the very top of each thumbnail you often end up with something that only shows the top of somebody’s hair or something.

    I also want to add a featured post slider above the post excerpts, but one thing at a time…


Viewing 3 replies - 1 through 3 (of 3 total)
  • Michael


    Forum Moderator

    without trying to understand what you are after, the error message comes from a typo in the sequence of the brackets:
    ( if is_attachment())
    was meant to be:
    if (is_attachment())

    Thanks. I also had a semicolon out of place. I changed it to

    <?php if (is_attachment()) { echo 'class=""'; } ?>

    and now there is no error message but it also doesn’t echo anything. I also tried print instead of echo.

    Basically, I’m using the code here in my theme’s functions.php to get the first image associated with the post and display it. That works fine. All I’m trying to do now is write a conditional tag that will make that image move up relatively. The div that it goes in is set to overflow: hidden; so the result is that the image appears to be cropped differently.

    I can get it to work for all images. I just can’t figure out how to write a conditional tag so that only images associated with posts are moved up and the default image (which displays when the post has no image) does not move.

    I guess the Rube Goldberg method would be to make my default image taller and have them all move up, but that seems sort of bogus.

    Thanks for any further advice.

    I made the default image taller and am having them all move up relatively. It’s not exactly elegant but it gets the job done with the same visual result.

    BTW that link no longer works. I have moved the theme files off of that site.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conditional code to relative position attached images only’ is closed to new replies.