簡體   English   中英

帶有圖像鏈接的 wordpress 自定義字段不顯示圖像

[英]wordpress custom field with link to image not displaying image

我有一個帶有自定義字段的自定義帖子類型,該字段采用純文本值,我使用該值傳遞我網站的 /images 文件夾中圖像的文件路徑。 我想使用它根據帖子在 UI 中動態顯示圖像。

<div class="page-title-graphic" style="background-image: url(<?php echo get_post_meta(get_the_ID(), 'page_title_graphic', true); ?>)"></div>

由於某種原因,我無法加載實際圖像。 到目前為止,在自定義字段我曾嘗試: ../images/about-header.svg/localhost/wordpress/wp-content/themes/naked-wordpress-master/images/about-header.svg ,但暫時還沒有運氣。

下面是它的輸出: Chrome 中的 CSS 片段一切看起來都很好。 當我嘗試在新標簽頁中打開圖片時,我在我的 wordpress 網站上看到一個新頁面,上面寫着“尚未發布任何內容!”

關於為什么我無法引用圖像的任何想法? 謝謝!

請嘗試這樣,

對於自定義帖子類型,

<?php global $post;
    $query = new WP_Query( array( 'post_type' => 'YOUR_CUSTOM_POST_TYPE') );
    while ($query->have_posts()) : $query->the_post(); ?>
      <div class="page-title-graphic" style="background-image: url(<?php get_the_post_thumbnail_url($post->ID, 'full'); ?>)"></div>
<?php endwhile; // end of the loop. ?>

我希望這能幫到您!!!

暫無
暫無

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

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