douju6542 2014-04-30 00:37
浏览 100

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

I am trying to add a little icon (jpg) next to every WordPress posts' titles that have a specifc custom field. Anyone would know how to do it?

I have defined a custom field for some posts like this: $custom = 2 and i want these posts' titles to include an icon.

  • 写回答

1条回答 默认 最新

  • dongzhi6087 2014-04-30 01:24
    关注

    So to access the specific custom field, use this:

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

    Where $post_id = the id of the post (use

    $post->ID 
    

    to get a post's ID)

    Where $key = the name of the custom field (ie. "custom")

    where $single = If set to true then the function will return a single result, as a string

    So you'd use something like:

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

    You can also check out Wordpress's article on it: http://codex.wordpress.org/Custom_Fields

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序