Support » Plugins » Hacks » Custom Menu Automation – Logged In, Logged Out, and Both

  • Resolved questions4wp


    I’m working on a site that functions basically as two different sites – the initial site has a number of pages, whose intention is to sell a product to the customer. The initial site also has a Login form. Customers of the product will receive accounts. Should a user log in, they’ll have a different set of pages available to them.

    There are three groups of pages – those that are available to only users who are logged in, those that are available to only users that are logged out, and those that are available to both.

    Up until this point, I basically have all of this working fine. The menu is in my sidebar, so I have the following code snippet in my sidebar.php:

    //Display these pages if the user is logged in or not
    	//Display these pages only if the user is logged in-->
    	if(is_user_logged_in()) wp_list_pages('include=98&title_li=');}
    	//Display these pages only if the user is logged out-->
    	else {wp_list_pages('include=101&title_li=');}

    This all works just as I intended it to. However, the client wants to be able to add or remove pages at will, like they can with a regular WordPress menu. Unfortunately, my menus are built using the wp_list_pages() function, which hardcodes the page ID’s in the include parameter. Does anyone have any suggestions on the best method to go about giving the content publisher the choice of grouping a page into “logged in users”, “logged out users”, or “both”?

    What I was thinking was making three different templates, so that when publishing a page, the user will have the choice of what template they want, and then instead of saying “include=8”, I would say “include=[every page with the ‘only logged in users’ template]”, and that way whenever they switched templates or deleted pages, the menus would update.

    Thoughts, suggestions, and constructive criticism are greatly appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • If it was me doing this, I’d set up a new plugin that added a meta box to the normal ‘page’ content type. I’d use this to store the visibility settings for that page as an extra custom meta option for the pages. This would let you set the page as ‘public’, ‘private’ or ‘both’. The best way that I’ve seen to learn this is to do some searches on custom content types, and just apply the details to the ‘page’ content type, not a custom one.

    The benifit of this is that you can include the meta values in a query like getA_posts(). This lets the pages get pulled dynamically so that there’s no hard-coding of page ID’s or anything else.



    Awesome, worked like a charm. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Menu Automation – Logged In, Logged Out, and Both’ is closed to new replies.