开发者

wordpress conditional statements

开发者 https://www.devze.com 2022-12-24 07:50 出处:网络
I am using this code in wordpress to display different content when different pages are loaded. I have 5 pages on the site called Home, Bio, Work, Contact and Notes. The Notes page is being used as a

I am using this code in wordpress to display different content when different pages are loaded. I have 5 pages on the site called Home, Bio, Work, Contact and Notes. The Notes page is being used as a blog. 开发者_高级运维Here is the code I am using.

                    <?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 } ?>

So if it the contact page, it displays "get in touch with me" and if it is a single blog post page it displays "a note from me". However this is where I have a problem. The next statement should display "the notes of me" when it is on the Notes page. However, this does not happen. Instead it shows the default content which is in the "else" statement. any idea on why this is happening?


This is what I would do instead.

            <?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 } ?>


please check whether the pages been puslished or not.


Comes to mind, that page name is not 'notes'. Check the URL of your page and see what is the page name.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号