0

我想在我的帖子中使用特色图片(缩略图)。

问题是,我希望能够在图像附加到帖子之后,但在帖子发布之前能够更改以下图像属性:

标题 替代文字 说明 说明

你是怎样做的?

4

3 回答 3

0

I'm still not clear what you're trying to do.

This will display the featured image in your markup using the post title as alt and title attributes.

$image_meta = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium'); 
// replace 'medium' with 'thumbnail', 'large', or 'full'.
echo '<img src="'.$image_meta[0].'" alt="'.$post->post_title.'" title="'.$post->post_title.'" width="'.$image_meta[1].'" height="'.$image_meta[2].'"/>';

If you want to actually change the featured image title, alt, caption, description etc in the database, then you could look at the post_publish hook. This should get you started:

function do_stuff($post_ID){
    global $post;
    $post_thumbnail_id = get_post_thumbnail_id($post_ID);
    if ($post_thumbnail_id){
        // Do Stuff with your featured image id - $post_thumbnail_id
    }
return $post_ID;
}
add_action('publish_post', 'do_stuff');
于 2011-11-01T09:30:58.400 回答
0
<?php 

$size = array(150,150);

$default_attr = array(
            'src'   => $src,
            'class' => "attachment-$size",
            'alt'   => trim(strip_tags( wp_postmeta->_wp_attachment_image_alt )),
            'title' => trim(strip_tags( $attachment->post_title )),
        );

the_post_thumbnail( $size, $attr ); 

?> 
于 2011-10-31T06:46:30.023 回答
0

试试这个,它的工作正常。

$title_attribute = the_title_attribute( array( 'echo' => FALSE ) );
the_post_thumbnail(
    'full', 
     array(
        'alt'   => $title_attribute, 
        'title' => $title_attribute 
    )
);
于 2013-03-09T12:44:18.797 回答