Grow your CSS skills. Land your dream job.

WordPress Question for a new poster and WP coder

  • # November 19, 2012 at 9:16 pm

    @chrisburton

    # November 19, 2012 at 9:17 pm

    @chrisburton – I installed the “attachments” plugin -activated to a new test template, works but it won’t display the image as an image… Is there a simple call in the PHP that he provided on the site to make the image display? Here is my test page: http://weir-tsus.com/attachments/

    Here is the code I placed inside my template:

    < ?php
    if( function_exists( ‘attachments_get_attachments’ ) )
    {
    $attachments = attachments_get_attachments();
    $total_attachments = count( $attachments );
    if( $total_attachments ) : ?>

      < ?php for( $i=0; $i<$total_attachments; $i++ ) : ?>

    • < ?php echo $attachments[$i]; ?>
    • < ?php echo $attachments[$i]; ?>
    • < ?php echo $attachments[$i]; ?>
    • < ?php echo $attachments[$i]; ?>
    • < ?php echo $attachments[$i]; ?>
    • < ?php echo $attachments[$i]; ?>
    • < ?php endfor; ?>

    < ?php endif; ?>
    < ?php } ?>

    Confused!
    Thanks

    # November 19, 2012 at 9:30 pm

    Hey @chrisburton I think I figured it out! Thanks!

    # November 19, 2012 at 10:39 pm

    @zeech You sure?

    # November 20, 2012 at 12:24 am

    @chrisburton – I believe so – I figured out how to attach and show the image in the correct DIV on the template. I can style the image with CSS.
    Here is my markup in my template:

    < ?php
    $attachments = attachments_get_attachments();
    $total_attachments = count($attachments);
    ?>
    < ?php if( $total_attachments > 0 ) : ?>

    < ?php for ($i=0; $i < $total_attachments; $i++) : ?>

    < ?php
    $tmp_attachment_id = $attachments[$i];
    $tmp_post_id = get_post($tmp_attachment_id);
    $tmp_title = $tmp_post_id->post_title;
    $tmp_path_array = explode(“/”,$attachments[$i]);
    $tmp_array_length = sizeof($tmp_path_array)-1;
    $tmp_filename = $tmp_path_array[$tmp_array_length];
    $j=$i+1;
    ?>

    < ?php
    echo wp_get_attachment_image($attachments[$i], $size=’full’, $icon = true);
    ?>

    < ?php endfor ?>

    < ?php endif ?>

    Here is the basic CSS for the image:
    .attachments-div {
    position: relative;
    float: right;
    width: 35%;
    }

    .attachments-div img {
    border:#000 solid 1px;
    float:left;
    }

    And now using this template I can allow the client to upload and attach an image to the right hand column.

    My PHP is limited, so not totally sure what all the code means on the PHP side, but it worked! Do you see any thing wrong with it?
    Thanks again @chrisburton

    zack

    # November 20, 2012 at 4:08 am

    Depending on the dimensions for `$size=’full’`, you might want to replace ‘full’ with ‘thumbnail’. If they are already sized correctly that code should work.

    # November 20, 2012 at 11:12 am

    Yeah I saw that in the code, actually changed it to full from thumbnail – one quick question, is there a PHP call that I can add for a hyperlink? Say I want to use the images and have them link to a specific page? An example (excuse the funky CSS background color) is this page: using attachments to build the thumbs, but would like them to link to the proper case studies page: http://weir-tsus.com/attachments/

    If you have quick answer thanks! If not I have hassled you enough! Thanks again @chrisburton
    cheers
    zack

    # November 20, 2012 at 1:48 pm

    @zeech This is what I use:

    < ?php $attachments = attachments_get_attachments(); ?>
    < ?php if( function_exists( 'attachments_get_attachments' ) ) {
    $attachments = attachments_get_attachments();
    $total_attachments = count( $attachments ); if( $total_attachments ) : ?>
    < ?php for( $i=0; $i<$total_attachments; $i++ ) : ?>
    “>

    # November 25, 2012 at 12:58 am

    @chrisburton thank your for the code!
    I did a slight modification to this chunk:
    “>

    # November 25, 2012 at 1:02 am

    Sorry not letting me post the code properly… Trying again:

    “>

    # November 25, 2012 at 1:07 am

    @zeech I don’t think that’s correct. I believe it should be:

    “>

    You must be logged in to reply to this topic.

    Projects

    *May or may not contain any actual "CSS" or "Tricks".