簡體   English   中英

動態加載html title屬性

[英]dynamically loading html title attribute

這是我的標記摘錄:

    <img src="<?php echo get_post_meta($post->ID, 'thumbnail_value', true); ?>" title="<?php the_tags(); ?>" alt="" class="thumb"></a>

我已經輸入了“ title”屬性<?php the_tags(); ?> <?php the_tags(); ?>是Wordpress的功能。 當我在Firebug中檢查標記時,會看到以下內容:

li class="view view_2 view-first">
<a id="50" href="" class="thumb_link" onclick="update_default_proj_list(1, '', '_'); getProject(50);"><span class="selected"></span><img 

src="13370318682.jpg" title="Tags: &lt;a href=" http:="" whiteandgold.ro="" realty="" ?tag="house&quot;" rel="tag">house</a>, <a href="http://

whiteandgold.ro/realty/?tag=rent-3" rel="tag">rent</a>" alt="" class="thumb"&gt;

我試圖用以下方法隱藏該文本:

img.thumb[title] {text-indent:-9999px;}



a[rel~="tag"] { text-indent:-999px;}`

而且它不起作用,您也可以在這里看到它(嘗試檢查縮略圖)

the_tags()呈現HTML,因此您不應將其放在title屬性內。 將其放在任何HTML屬性之外:

<div id="thepost">
  // stuff
  <?php the_tags(); ?>
</div>

如果由於某些原因您仍然想要這樣做,可以使用htmlspecialchars使其起作用:

<img src="<?php echo get_post_meta($post->ID, 'thumbnail_value', true); ?>" title="<?php htmlspecialchars(the_tags()); ?>" alt="" class="thumb"></a>

或者,也許您只需要一個逗號分隔的標簽列表,在這種情況下,您可以使用get_the_tags()生成它(它為您提供了一系列標簽,您可以使用它們進行任何操作)。

暫無
暫無

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

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