在wordpress中,我正在创建一个主题,但我需要帮助,
<? the_post_thumbnail();?>当我这样做的时候,它会给我整个<img src=#>.....
到目前为止,一切都很好,但是我想做一些事情,比如
<a href="UPLOADEDIMAGEURL"><? the_post_thumbnail();?></a>因此,我需要采取上传的图片网址,并包装它与锚点,然后替换上传的图片网址,我怎么做?我已经在jQuery中尝试了一些,但我想我也可以在php中做到这一点?
这是jQuery版本(因为我不能接受img src属性并替换为href)。
$('.floatedImg').find('img').wrap( "<a href='#' class='colorbox'></a>" );解决方案1:可以通过jQuery处理方案2:可以通过php
问候
发布于 2014-06-05 02:14:15
试试这个:
<?php
$img_url = wp_get_attachment_img_src( get_post_thumbnail_id(), 'thumbnail');
?>
<a href="<?php echo $img_url[0]; ?>"><?php the_post_thumbnail();?></a>供参考:
发布于 2014-06-09 23:31:11
您可以在functions.php文件中放入类似这样的内容
function get_thumbnail_url() {
if ( has_post_thumbnail() ) {
$thumb_url = wp_get_attachment_img_src( get_post_thumbnail_id(), 'thumbnail');
return $thumb_url[0];
}
else {
return get_bloginfo( 'stylesheet_directory' ) . '/images/thumbnail-default.jpg';
}
}然后
<a href="<?php echo get_thumbnail_url(); ?>"><? the_post_thumbnail();?></a>https://stackoverflow.com/questions/24044506
复制相似问题