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 );
?>
I think this should work if you are wrapping the condition around the arguments, and not the menu link itself: