如何将自定义域添加到我的主题模板文件?

时间:2014-09-01 作者:alex

我正在使用4个自定义字段,并通过以下方式在我的主题页中显示自定义字段

$quote_text_1 = get_post_meta($post->ID, \'quote_text_1\', true);
$quote_text_1_author = get_post_meta($post->ID, \'quote_text_1_author\', true);
echo \'<p>\'.$quote_text_1.\'<br/>\'.$quote_text_1_author .\'</p>\';

$quote_text_2 = get_post_meta($post->ID, \'quote_text_2\', true);
$quote_text_2_author = get_post_meta($post->ID, \'quote_text_2_author\', true);
 echo \'<p>\'.$quote_text_2.\'<br/>\'.$quote_text_2_author.\'</p>\';
如何将自定义字段添加到特定的主题模板页面,以便用户知道他/她可以使用这些字段?

1 个回复
SO网友:Elisha Terada

假设您正在寻找一种在面向公众的页面(非编辑页面)上有条件显示自定义字段的解决方案,您可以使用WordPressConditional Tags.

if ( is_page_template(\'template-name.php\') ) { 
    // Execute Your Code
}

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register