我需要在单个帖子页面(single.php)上显示自定义类别元字段(存储在wp_options
表格中)。
我有这个代码在单个帖子页面上不起作用(single.php):
$cat_id = get_query_var('cat');
$cat_data = get_option("category_$cat_id");
echo $cat_data['custom_field'];
这仅适用于category.php/archive.php
页面,但不适用于单个帖子页面(single.php)。该帖子只属于一个类别,我需要该类别的自定义字段而不使用任何插件。
有没有办法做到这一点?
答案 0 :(得分:0)
也许这是你的答案(如果你使用wordpress代码):
http://codex.wordpress.org/Function_Reference/get_post_custom_keys