如何根据自定义字段在WP文章标题旁边添加图标


How to add icon next to WP post title based on custom field

我正试图在每个有特定自定义字段的WordPress帖子标题旁边添加一个小图标(jpg(。有人会知道怎么做吗?

我为一些帖子定义了一个自定义字段:$custom=2,我希望这些帖子的标题包含一个图标。

因此,要访问特定的自定义字段,请使用以下命令:

get_post_meta($post_id, $key, $single);

其中$post_id=帖子的id(使用

$post->ID 

获取帖子的ID(

其中$key=自定义字段的名称(即"自定义"(

其中$single=如果设置为true,则函数将返回单个结果,作为字符串

所以你应该使用这样的东西:

$key = 'custom';
if (get_post_meta($post->ID, $key, true) == 2){
    //echo icon here
}

你也可以看看Wordpress的文章:http://codex.wordpress.org/Custom_Fields