按页面显示自定义变量

时间:2013-11-17 19:49:04

标签: wordpress

我想在特定页面上显示特定的帖子自定义变量数据。

我有以下代码

<?php
if ( is_page( '24' ) ) {
    // This is Podcast
    echo get_post_meta(570, "Youtube Video", true);
    } else if ( is_page ('25') ){
    // This is Video
    echo get_post_meta(568, "Youtube Video", true);
} else if ( is_front_page () ){
    // This is the Home Page
    echo get_post_meta(550, "Youtube Video", true);
} else {
    //Other Pages
    echo '<h1>APPLIES TO ALL INSIDE PAGES</h1>';
}
?>

这导致主页按预期使用“is_front_page”条件,但其他声明的页面将应用'else'。好像页面条件没有被挂钩。关于可能导致这种情况的任何想法?

1 个答案:

答案 0 :(得分:0)

解决。

这些项目是类别,而不是页面。通过检查wordpress菜单确认对象是什么来确认。

以下代码按预期运作。

<?php
if ( is_category( 'podcast' ) ) {
    // Display Podcast Specific Content
    echo get_post_meta(570, "Youtube Video", true);
    } else if ( is_category ('video') ){
    // This is Video
    echo get_post_meta(568, "Youtube Video", true);
} else if ( is_front_page () ){
    // This is the Home Page
    echo get_post_meta(550, "Youtube Video", true);
} else {
    //Other Pages (Display Home Page Video)
    echo get_post_meta(570, "Youtube Video", true);
}?>
相关问题