Monday 15 February 2010

php - Change page content based on condition Wordpress -


I want to change the homepage of a WordPress website based on the log-in user's role.

For simple case (i.e. whether user is logged in or not) I have tried to use the function is_user_logged_in ()

; The code is as follows:

  if (! Is_user_logged_in ()) {while (is_pause ()): the_post (); // page content template included. Get_template_part ('content', 'page'); // If the comments are open or we have at least one comment, then load the comment template. If (comments_open () || get_comments_number ()) {comments_template (); } Nearby; } And {echo "you are logged in"; }  

But the problem is that it changes the content in each page. I want to do this only for a specific page .. (i.e. the homepage). How do I do that? Any help would be greatly appreciated.

You will need to add another condition to do this, such as for the homepage:

< Pre> if_user_logged_in () and is_home ()) {...}

and similarly for content of other types: is_page () , is_category () , is_author () , etc. Check the docs.


No comments:

Post a Comment