我购买的Wordpress主题中有以下代码行: -
add_image_size( 'homeland_property_medium', 330, 230, true );
这会在页面上添加以下HTML: -
<img class="attachment-homeland_property_medium wp-post-image" width="330" height="230" alt="7-020130322113404" src="http://nathandasilva.co.uk/butlinps/wp-content/uploads/2014/11/7-020130322113404-330x230.jpg"></img>
我已经替换了以下代码: -
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) { the_post_thumbnail('homeland_property_medium'); } ?>
</a>
<figcaption><a href="<?php the_permalink(); ?>"><i class="fa fa-link fa-lg"></i></a></figcaption>
使用: -
<svg width="296" viewBox="0 0 1.286956522 1" height="230" style="margin-left: 0px; margin-top: -17px; z-index: 1;">
<defs style="">
<clipPath id="shape">
<path d="M0.6434782609,0 L1.286956522,0.166666666667 L1.286956522,1 L0,1 L0,0.166666666667z"></path>
</clipPath>
</defs>
<a xlink:href="<?php the_permalink(); ?>">
<image y="-0.1" x="0" clip-path="url(#shape)" xlink:href="http://nathandasilva.co.uk/butlinps/wp-content/uploads/2014/11/7-020130322113404-330x230.jpg" height="1px" width="1.286956522px"></image>
</a>
</svg>
对于替换代码,我为图像添加了静态图像(http://nathandasilva.co.uk/butlinps/wp-content/uploads/2014/11/7-020130322113404-330x230.jpg
),我需要以某种方式将其替换为相关属性图像的URL,但我甚至不知道从哪里开始?
也许我需要显示更多代码才能让你们帮助我,让我知道如果是这样的话我会继续寻找......
答案 0 :(得分:0)
通过将HTML部分更改为: -
来管理以解决此问题 <? $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<svg width="296" viewBox="0 0 1.286956522 1" height="230" style="margin-left: 0px; margin-top: -17px; z-index: 1;">
<defs style="">
<clipPath id="shape">
<path d="M0.6434782609,0 L1.286956522,0.166666666667 L1.286956522,1 L0,1 L0,0.166666666667z"></path>
</clipPath>
</defs>
<a xlink:href="<?php the_permalink(); ?>">
<image y="-0.1" x="0" clip-path="url(#shape)" xlink:href="<?php echo $url; ?>" height="1px" width="1.286956522px"></image>
</a>
</svg>
基本上补充一点: -
<? $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
要获取缩略图ID的URL,请将图像的href设置为: -
<image y="-0.1" x="0" clip-path="url(#shape)" xlink:href="<?php echo $url; ?>" height="1px" width="1.286956522px"></image>