将课程名称添加到发布缩略图
3 个回答
- 投票数
-
- 2013-06-06
是的-您可以将要使用的类作为属性参数的一部分传递给
the_post_thumbnail()
,例如<?php the_post_thumbnail('thumbnail', array('class' => 'your-class-name')); ?>
参考: http://codex.wordpress.org/Function_Reference/the_post_thumbnail#Styling_Post_Thumbnails
Yep - you can pass the class you want to use to
the_post_thumbnail()
as part of the attributes argument, for example<?php the_post_thumbnail('thumbnail', array('class' => 'your-class-name')); ?>
Ref: http://codex.wordpress.org/Function_Reference/the_post_thumbnail#Styling_Post_Thumbnails
-
但这将删除类" attachment- $ size".But this will remove the class `attachment-$size`.
- 5
- 2013-06-06
- fuxia
-
但是您可以添加类" attachment- $ sizemy-class-name"But can you add the class "attachment-$size my-class-name"
- 0
- 2013-06-07
- Simon Cooper
-
我做了@SimonCooper,现在该类具有附件-没有大小.@SimonCooper I did and the class now has attachment- without the size.
- 0
- 2015-04-27
- Zhianc
-
这通常是不好的且非通用的解决方案.即使是硬编码附件-$ size,也将删除所有可能的将来的类注入.This is generally bad and non-generic solution. Even hardcoding attachment-$size, erases all possible future class injections.
- 0
- 2019-02-18
- Fusion
-
- 2013-06-07
您可以过滤这些类.
function alter_attr_wpse_102158($attr) { remove_filter('wp_get_attachment_image_attributes','alter_attr_wpse_102158'); $attr['class'] .= ' new-class'; return $attr; } add_filter('wp_get_attachment_image_attributes','alter_attr_wpse_102158');
在调用
the_post_thumbnail
之前添加过滤器.过滤器将自动删除自己.到达那里有点跋涉,但
the_post_thumbnail
使用get_the_post_thumbnail
,它使用wp_get_attachment_image
,即可应用该过滤器.You can filter those classes.
function alter_attr_wpse_102158($attr) { remove_filter('wp_get_attachment_image_attributes','alter_attr_wpse_102158'); $attr['class'] .= ' new-class'; return $attr; } add_filter('wp_get_attachment_image_attributes','alter_attr_wpse_102158');
Add the filter just before you call
the_post_thumbnail
. The filter will remove itself automatically.It is a bit of trek to get there but
the_post_thumbnail
usesget_the_post_thumbnail
which useswp_get_attachment_image
which applies that filter.-
函数名称" alter_attr_wpse_102158"是否具有特定含义,是否可以将该函数称为myClass-functionmyClass($ attr){Does the function name 'alter_attr_wpse_102158' have a particular meaning could this function be called myClass - function myClass($attr) {
- 0
- 2013-06-07
- Simon Cooper
-
名称有点描述性,后缀引用了这个问题.否则,没有特殊含义.在类实例(例如插件类)内部,可以使用`array($this,'methodname')`,并且可以通过使用array('ClassName','methodname')使用带有过滤器的静态类.The name is somewhat descriptive and the suffix references this question. Otherwise, no particular meaning. From inside a class instance-- say a plugin class-- you can use `array($this,'methodname')` and you can use static classes with filters by using `array('ClassName','methodname')`
- 0
- 2013-06-07
- s_ha_dum
-
http://codex.wordpress.org/Function_Reference/add_filter#Noteshttp://codex.wordpress.org/Function_Reference/add_filter#Notes
- 0
- 2013-06-07
- s_ha_dum
-
为什么要添加一个可自行删除的过滤器?Why are you adding a filter that removes itself?
- 1
- 2013-09-29
- AlxVallejo
-
@AlxVallejo:因此,它只在您希望其运行的特定情况下运行一次.@AlxVallejo : So that it only runs once in the particular circumstance that that you want it to run.
- 2
- 2013-09-29
- s_ha_dum
-
- 2016-12-29
您的图片标签没有类,您只需编写此代码
<?php the_post_thumbnail(); ?>
,但是您的图片标签具有您只需编写此代码的类<?php the_post_thumbnail('thumbnail', array( 'class' => 'class_name' )); ?>
Your image tag have no class you just write this code
<?php the_post_thumbnail(); ?>
but your image tag have class you just write this code<?php the_post_thumbnail('thumbnail', array( 'class' => 'class_name' )); ?>
我正在使用帖子缩略图链接到页面.
是否可以在帖子缩略图中添加班级名称.