Home » Blog » Genesis Theme Framework: password protect a category

Genesis Theme Framework: password protect a category

Here is a fun problem I came a cross today.
The client wanted to password protect one category in their Genesis WordPress site.
I looked for a plugin but they where all too complex for what I needed.

So I wrote this little function and placed it in the theme’s function file:

Remember that this function is written to work with a Genesis WordPress website.

/**************************************
*************Hide Category*************
***************************************/
// This is called by replacing the genesis_loop()
// with hide_category()
// in main genesis theme template page (index.php)
function hide_category(){
$categories = get_the_category(get_the_post_id());
foreach ($categories as $message) {
$category_id=$message->cat_ID;
$category_parent=$message->category_parent;
if ($category_id == 4 OR $category_parent == 4){
// get the┬áregistration page’s URL
$reg_link=get_bloginfo(‘url’).“/wp-login.php?action=register”;
$gw_output=“<h2>Please Login</h2>”;
$gw_output .=<p>Welcome to the News for Members blog.
If you are a member, please <a href=\””.wp_login_url( get_permalink() ).“\” title=\”Login\”>login</a>.
If you are not a member and would like to become one please
<a href='” . $reg_link . “‘>fill out an application.</a></p>”;
} // end if
} // end loop
if( !is_user_logged_in() and isset($gw_output) ){
echo ($gw_output);
} else {
genesis_loop(); // put the genesis loop back in
}
}

One comment

Leave a Reply