簡體   English   中英

PHP-add_image_size

[英]PHP - add_image_size

我在購買的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,但我什至不知道從哪里開始?

也許我需要顯示更多代碼以便你們幫助我,如果是這種情況,請告訴我,我會繼續尋找...

最終通過將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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM