简体   繁体   English

动态加载html title属性

[英]dynamically loading html title attribute

Here is an excerpt from my markup: 这是我的标记摘录:

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

I've put in the "title" attribute <?php the_tags(); ?> 我已经输入了“ title”属性<?php the_tags(); ?> <?php the_tags(); ?> which is a function from Wordpress. <?php the_tags(); ?>是Wordpress的功能。 When I check the markup in Firebug I see this: 当我在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;

I've tried to hide that text with : 我试图用以下方法隐藏该文本:

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



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

And it's not working, also you can see this here ( try to inspect a thumbnail) 而且它不起作用,您也可以在这里看到它(尝试检查缩略图)

the_tags() renders HTML, so you shouldn't put it inside the title attribute. the_tags()呈现HTML,因此您不应将其放在title属性内。 Put it outside of any HTML attributes: 将其放在任何HTML属性之外:

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

If you still want to do this for some reason, you can make it work by using htmlspecialchars : 如果由于某些原因您仍然想要这样做,可以使用htmlspecialchars使其起作用:

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

Or maybe you just want a comma-separated list of tags, in which case you can generate it using get_the_tags() (which gives you an array of tags that you can do whatever you want with). 或者,也许您只需要一个逗号分隔的标签列表,在这种情况下,您可以使用get_the_tags()生成它(它为您提供了一系列标签,您可以使用它们进行任何操作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM