Tag Archives: pages

Password protect a web page

Here is the code you can use to password protect a web page quickly and easily.

If the web page you wish to password protect is an HTML page, open it in a text editor and save it as a PHP page.

Copy and paste this code at the very top of the page you have open in a text editor:

<?php  // Define your username and password  
$username = "someuser"; 
$password = "somepassword";  
if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {  ?>
<h1>Login</h1>  
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">     
<p><label for="txtUsername">Username:</label>     
<br /><input type="text" title="Enter your Username" name="txtUsername" /></p>    
<p><label for="txtpassword">Password:</label>    
<br /><input type="password" title="Enter your password" name="txtPassword" /></p>     
<p><input type="submit" name="Submit" value="Login" /></p>  
</form>  
<?php  }  else {  ?>  
<p>This is the protected page. Your private content goes here.</p> 
<?php  }  ?> 

 

First, you will obviously need to define the username and password that you want to use to protect the page.

Next, replace the text that says “This is the protected page…” in the code you just added to your page with the content of the web page that you want to be password protected.

You can password protect just one particular part of your web page if you want to by copying and pasting the code above into wherever on your web page you want to password protect, as long as the web page is a php page. See this post for an example of a web page with only part of it’s content password protected.

Note: if you are trying to password protect just one section of your web page, please refer to my next post on how to password protect part of a web page.

WordPress: Display latest posts from a particular category in the sidebars of specific pages

After spending hours trying to figure out a way to display the latest posts from a certain category in WordPress on specific pages, I have finally found a solution!

First of all, it is important to note that the site I am working on is set up to display only posts from a particular category on specific pages.

The first thing I did was install the Exec-PHP plugin (which allows you to add php code to your sidebar widgets) and the Widget Logic plugin (which allows you to control which widgets show up on which pages’ sidebars).

Next, I added a “text” widget to my sidebar. I named the widget “Latest posts in Video.”

Then I pasted this code into the text area of the widget:

<?php
 global $cat;
 $recentPosts = new WP_Query();
 $recentPosts->query('showposts=5&cat=7');
?>
<?php while ($recentPosts->have_posts()) : $recentPosts->the_post(); ?>
 <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li>
<?php endwhile; ?>

I changed the category ID (in this case: “7″) to the category ID that I wanted to display on the Video page.

Next, in the Widget Logic field of the widget, I used this line of code to tell the widget which page to appear on:

is_category(7)

That is where I had been going wrong. I had been using is_page(26) (which is the page ID where I have Video posts being displayed), but WordPress sees that page as a category page and not as a page page (because of the fact that I had it set up to show only a certain category of posts), so once I changed the Widget Logic code to is_category, rather than is_page, my solution worked perfectly.

As always, let me know if you have any questions or issues with this, I would be happy to help.

WordPress: Changing the default home page title in the navigation menu (Twenty-Ten theme)

Today, while working on a WordPress website, I noticed that when I selected a static page of the site to be the home page, it automatically re-named the page “Home” in the navigation menu rather than keeping the original title of the page.

To solve this, I opened the functions.php file in the admin panel. Then I found this block of code:

function twentyten_page_menu_args( $args ) {
 $args['show_home'] = true;
 return $args;
}
add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );

I erased that block of code and saved the file. Now the page shows the title I gave it in the navigation menu – problem solved!

Let me know if you are running into the same issue I was and this tip doesn’t help you, and I’ll try to help you.