The Graphic Design Shop is a full service provider of Website Design and Graphic Design. We would be happy to assist you with everything from web design and web development to Logo Design and Promotion. If you're in business, whether you need a website or a full corporate identity, The Graphic Design Shop can help you increase your company's visibility and improve its graphic image.

Wordpress and Conditional Menu Items

Over the past couple of weeks, I have been working on a paid membership site. The site handles Content Protection, Payment Processing, and Dynamically Generates a Membership Card. We used Wordpress as the foundation of the site and during the process, there were a few features that I had a hard time finding documentation on.

If a non-member were to view the site, protected pages are not visible. Makes sense right? The problem however, is that the page link is still in the drop down navigation menu. The link doesn’t go anywhere, but it’s just sloppy development.

The solution is conditional menu items.

Here we have the standard code displaying page links with order arguments.

1
2
3
4
5
<ul>
 
<?php wp_list_pages('orderby=ID&order=ASC&hide_empty=0&title_li='); ?>
 
</ul>

And here, if the user is logged in, we use the exact same code to show our link. If not (else) we add the exclude argument with the page id’s separated by comas.

1
2
3
4
5
6
7
8
9
10
11
<ul>
<?php if ( is_user_logged_in() ):
 
     wp_list_pages('orderby=ID&order=ASC&hide_empty=0&title_li=');
 
else : 
 
     wp_list_pages('orderby=ID&order=ASC&hide_empty=0&title_li=&exclude=1,2,3');
 
endif; ?>
</ul>

It’s that simple. Stay tuned for more hard to find solutions.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • StumbleUpon
  • Twitter
  • Reddit
This entry was posted in Blog. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared.