WordPress: Using static page and latest post link
So when doing a recent wordpress template i encountered one problem. The front page was meant to be a static page but the latest post function was still supposed to work on another link (Blog). Finding out the link to access the latest posts was quick. You can always find it over:
yoursite.com/?p=all
But now i wanted the mark up to work. Usually wordpress marks current items with the class “current_page_item”. Since this was a custom link, i had to do this mark up myself. I was searching quite some time for this. At the end i was able to solve it like this:
<li class="blog <?php if ( preg_match("/.*p=all.*/i", $_SERVER['QUERY_STRING']) || is_single() ) { ?>current_page_item<?php } ?>"><a href="?p=all" title="<?php _e('title', 'default'); ?>"><?php _e('Blog', 'default'); ?></a></li>
I tried all kinds of functions that wordpress is offering. is_home, is_page, is_singular etc. But only this did the final trick since these latest posts are not a page neither just one post. Now it adds the class “current_page_item” to this link when a user is on it. Solved.