dtczp02204 2014-12-14 13:35
浏览 18
已采纳

PHP - add_image_size

I have the following line of code in a Wordpress theme which I purchased which is:-

add_image_size( 'homeland_property_medium', 330, 230, true );

This adds the following HTML on the page:-

<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>

I have replaced the below code:-

<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>

With:-

<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>

For the replaced code I added a static image (http://nathandasilva.co.uk/butlinps/wp-content/uploads/2014/11/7-020130322113404-330x230.jpg) for the image, I need to somehow replace this with the URL to the associated property image but I don't even know where to start?

Maybe I need to show more code in order for you guys to help me, let me know if this is the case and I'll carry on looking...

  • 写回答

1条回答 默认 最新

  • duanfei7508 2014-12-16 15:18
    关注

    Managed to fix this in the end by changing the HTML section to:-

                    <? $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>  
    

    Basically added this:-

    <? $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>

    To get the URL of the thumbnail ID, then set the href for the image as:-

    <image y="-0.1" x="0" clip-path="url(#shape)" xlink:href="<?php echo $url; ?>" height="1px" width="1.286956522px"></image>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码