Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to add some code depending on which page the users are.

  <?php 
$arr = array(2506, 2516,2512,2513,2509,2515,2510,2508,2514,2511,2507);
if (in_array(the_ID(),$arr)){
    if ($_SESSION['logged'] != 'true'){
        echo '<script>document.location.href="./connexion";</script>'; //Not logged so good bye !
    }
} 
?>

I know my that it's not quite accurate but can you check it out ?

Any clue on how to make this ?

share|improve this question
1  
You've posted your attempted implementation, but haven't really identified what exactly you're trying to accomplish. From your code, I assume you're trying to identify when you're on a given set of pages, by Page ID? –  Chip Bennett Nov 15 '12 at 19:37
    
I have modified it so it could be easier to understand now –  Warface Nov 15 '12 at 19:43
add comment

1 Answer

up vote 1 down vote accepted

Assuming that you want to output content conditionally, depending on whether you are on a given set of static pages, by Page ID, you can simply wrap your code in an is_page() conditional.

To determine if the current user is logged in, you can use the is_user_logged_in() conditional.

For example

// Array of Page IDs
$page_ids = array( 2506,2516,2512,2513,2509,2515,2510,2508,2514,2511,2507 );

// If the current context is a static page with one of the above IDs
// and the current user is logged in
if ( is_page( $page_ids ) && is_user_logged_in() ) {
    // This is one of our pages
    // Do something
}

Or for the case in which the current user is not logged in:

// Array of Page IDs
$page_ids = array( 2506,2516,2512,2513,2509,2515,2510,2508,2514,2511,2507 );

// If the current context is a static page with one of the above IDs
// and the current user is NOT logged in
if ( is_page( $page_ids ) && ! is_user_logged_in() ) {
    // This is one of our pages
    // Do something
}
share|improve this answer
    
I'm not using the user login from wordpress unfortunately that why I'm using that session. But the code is great. Thanks –  Warface Nov 15 '12 at 19:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.