如何在头部区域调用自定义字段?

时间:2011-01-20 04:09:06

标签: php wordpress

我试图在header.php模板区域输出自定义字段的内容(通过More Field插件创建):

<?php if ( in_category('5') ) {echo '<meta property="text" content="' . get_post_meta(get_the_ID(), 'custom_field', true) . '" />';}?>

...目前正在输出:

<meta property="text" content="" />

正如您所看到的,它并没有抓住'custom_field'中的值。

有人可以告诉我如何成功获取该自定义字段的值吗?

P.S。我认为这与循环有关,但我还没有弄清楚如何应用正确的语法使其工作。任何帮助表示感谢,谢谢。

1 个答案:

答案 0 :(得分:0)

啊,感谢this post

代码如下:

<?php 
if (in_category('5')) 
{ 
    the_post(); 
    rewind_posts();
    echo '<meta property="text" content="' . get_post_meta(get_the_ID(), 'custom_field', true) . '" />';
} 
?>

感谢你的回复PeterWong。

相关问题