根据条件Wordpress更改页面内容

时间:2015-03-17 15:15:16

标签: php wordpress-plugin wordpress-theming wordpress

我想根据登录用户的角色更改为wordpress网站的主页。

对于简单的情况(即用户是否登录)我尝试使用函数is_user_logged_in()

代码如下:

if(!is_user_logged_in()){
                while ( have_posts() ) : the_post();
                    // Include the page content template.
                    get_template_part( 'content', 'page' );
                    // If comments are open or we have at least one comment, load up the comment template.
                    if ( comments_open() || get_comments_number() ) {
                        comments_template();
                    }
                endwhile;
            }else{
                echo "you are logged in";
            }

但问题是它改变了每一页的内容。我想仅针对特定页面进行此操作..(即主页)。我怎么做?任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

要做到这一点,你必须添加另一个条件,例如主页:

if(!is_user_logged_in() && is_home()){

...

}

类似于其他类型的内容:is_page()is_category()is_author()等。请查看文档here

答案 1 :(得分:-1)

检查页面ID并将其与您想要的特定页面进行比较 您也可以为要更改的页面设置一个类别,然后进行检查

相关问题