wordpress条件语句

时间:2010-03-25 15:42:13

标签: php wordpress

我在wordpress中使用此代码在加载不同页面时显示不同的内容。我在网站上有5个页面,名为Home,Bio,Work,Contact和Notes。 Notes页面用作博客。这是我正在使用的代码。

                    <?php if (is_page('contact')) { ?>
                    get in touch with me
                <?php } elseif (is_single()) { ?>
                    a note from me
                <?php } elseif (is_page('notes')) { ?>
                    the notes of me
                <?php } else { ?>
                    the <?php the_title(); ?> of me
                <?php } ?>

因此,如果是联系页面,则会显示“与我联系”,如果是单个博客帖子页面,则会显示“来自我的说明”。然而,这是我遇到问题的地方。下一个语句应该在Notes页面上显示“我的笔记”。但是,这不会发生。相反,它显示“else”语句中的默认内容。关于为什么会发生这种情况的任何想法?

3 个答案:

答案 0 :(得分:2)

这就是我要做的事情。

            <?php if (is_page('contact')) { ?>
                get in touch with me
            <?php } elseif (is_page()) { ?>
                the <?php the_title(); ?> of me
            <?php } elseif (is_single()) { ?>
                a note from me
            <?php } else { ?>
                the notes of me
            <?php } ?>

答案 1 :(得分:1)

请检查页面是否已被删除。

答案 2 :(得分:0)

请记住,页面名称不是“注释”。检查页面的URL,看看页面名称是什么。

相关问题