Attachment page

Discussion in 'WordPress' started by Sake7, Sep 1, 2010.

  1. #1
    Hi,

    I'm currently working on a wordpress theme for one of my websites and i have a question about images/attachment pages.

    I'll have on single.php an image which will be include with timthumb (this mean i don't use gallery)

    Well, i want this page to link to the attachment page. I know the link for that is something link this: domain.com/pots-permalink/picture_title and i don't know how to generate it dynamically.

    "post-permalink" can be founded easy (the_permalink() ) ;) but i don't know how to take image title.

    I have this:

    What to put there? (red part) or is any other method?
     
    Sake7, Sep 1, 2010 IP
  2. unomateo

    unomateo Peon

    Messages:
    41
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    This is how you get the attachment images
    
    $args = array(
    'post_type' => 'attachment',
    'numberposts' => null,
    'post_status' => null,
    'post_parent' => $post->ID
    ); 
    $attachment = get_posts($args);
    $image = wp_get_attachment_image_src($attachment[0]->ID, 'medium');
    
    PHP:
    you can have more then 1 attachment, so you need to figure out how to get the ID of the attachement. The easiest way is to just make sure the attachment you want to link to is always added last
    you can get any size of the attachment. In the example, I get the medium. You can use thumbnail or large (i think, maybe full)

    if you need to get the url use this function instead wp_get_attachment_url($attachment[0]->ID);

    Hope that helps
     
    unomateo, Sep 1, 2010 IP