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 have set a static page for posts (page id = 110). This page shold only be included in the menu when the user is logged in. The latter is achieved with the following addition to header.php (snippet from inside the menu <ul> tag).

<?php wp_list_pages('sort_column=ID&exclude=100,110,145&title_li='); ?>
        <?php if ( is_user_logged_in() ) { ?>
            <li ><a href="<?php echo get_permalink(110); ?>">Title</a></li>
        <?php } else { ?>

        <?php } ?>

I'm using freshy2 and have customized the CSS so that the link for the current page in the header navigation menu has another background colour from the rest (standard procedure...).

However, as page with ID 110 is the static posts page, I cannot find a solution to do the same for this page. This is because is_page(110) returns false as it recognizes the current post type to be is_single() and when I query for post ID, the ID for the latest post is returned. I obviously can't use the latter for querying the current display as it changes all the time.

Here is what I have at the moment. This kind of works, but only halfway through as now the background colour is always the special colour, even if the posts page is not the current "item" on display.

<?php if ( is_user_logged_in() ) { ?>
            <li <?php
                if (get_option('page_for_posts'))
                { 
                    echo " class=\"page_item page-item-110 current_page_item\"";
                }
                else
                { 
    global $wp_query;
    $thePostID = $wp_query->post->ID;
                    echo " class=\"" . $thePostID . "\"";
                }
            ?>><a href="<?php echo get_permalink(110); ?>">Title</a></li>
        <?php } else { ?>

        <?php } ?>

Any ideas? Thanks a lot in advance!

EDIT:

This code, as suggested below, does the trick (I simply added the missing values from the original wp_list_pages):

        <?php if(!is_user_logged_in())
{
$args = array(
'exclude' => '100,110,145',
'sort column' => 'ID',
'title_li' => ''
 );
}
else
{
$args = array(
'exclude' => '100,145',
'sort column' => 'ID',
'title_li' => ''
 );
}

wp_list_pages( $args );
?>
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

I think this should work if you are wrapping the condition around the arguments, and not the menu link itself:

if(!is_user_logged_in())
{
$args = array(
'exclude'      => '100,110,145'
 );
}
else
{
$args = array(
'exclude'      => '100,145'
 );
}

wp_list_pages( $args );
share|improve this answer
    
Very good idea, but unfortunately this messes up my menu. It's meant to show all menu items in one row, whereas when I use your snip, I get a single item (untouched by CSS) "Pages", with the pages as submenu (dropdown). –  s.d Nov 15 '11 at 13:42
    
Ah, I've added the other values from the original wp_list_pages, and it works now. I'm accepting your answer, as it showed me the right way. Will add the code to my question. Thanks! –  s.d Nov 15 '11 at 13:48
1  
Yeah sorry, I did not add the html, because I was not sure, how to display it the way you wanted it. I'm always using it like: <ul><?php wp_list_pages($args) ?></ul> Anyway I am glad I could help :-) –  SamiSalami Nov 15 '11 at 13:55
    
No worries. All I had to do was add two more values to the array :). Thanks again! –  s.d Nov 15 '11 at 14:16
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.