Tag Archives: WordPress


Tutorial – Add a User Agreement Message to your WordPress

March 14th, 2011 by

This will allow you to require your visitors to accept your User Agreement Terms with this little bit of code. This is great if you want to put a disclaimer, copyright notice, age required notice, or even adult content warning. The code is fairly simple and easy to implement, you will be adding it to your loop file(s) in your theme. Instead of showing you the code in one snippet I will be breaking it up into two because there is a part that goes at the top of the loop and the other part will go at the bottom.

Put this at the very top of your loop file(s)

  1. <?php
  2. session_start();
  3. if(!isset($_SESSION['grant_access'])) {
  4.         $_SESSION['grant_access'] = ‘unset’;
  5. }
  6. if(isset($_POST['agree'])) {
  7.         $_SESSION['grant_access'] = ‘set’;
  8. }
  9. if($_SESSION['grant_access'] == ‘unset’) {
  10. ?>
  11.         <h1>You don’t have Access to this content.</h1>
  12.         <h2>You must click the I Agree button to view this content.</h2>
  13.         <form method="post">
  14.                 <input type="submit" value="I Agree" name="agree" />
  15.         </form>
  16. <?php
  17. } else {
  18. ?>

Put this at the very bottom of your loop file(s)

  1. <?php } ?>

Here is what a very basic loop.php file would look like with the added code.

  1. <?php
  2. session_start();
  3. if(!isset($_SESSION['grant_access'])) {
  4.         $_SESSION['grant_access'] = ‘unset’;
  5. }
  6. if(isset($_POST['agree'])) {
  7.         $_SESSION['grant_access'] = ‘set’;
  8. }
  9. if($_SESSION['grant_access'] == ‘unset’) {
  10. ?>
  11.         <h1>You don’t have Access to this content.</h1>
  12.         <h2>You must click the I Agree button to view this content.</h2>
  13.         <form method="post">
  14.                 <input type="submit" value="I Agree" name="agree" />
  15.         </form>
  16. <?php
  17. } else {
  18. ?>
  19. <?php
  20. if (have_posts()) :
  21.    while (have_posts()) :
  22.       the_post();
  23.       the_content();
  24.    endwhile;
  25. endif;
  26. ?>
  27. <?php } ?>

Now that you have both parts that will be needed lets break it down a little bit further.

  1. <?php
  2. session_start();
  3. if(!isset($_SESSION['grant_access'])) {
  4.         $_SESSION['grant_access'] = ‘unset’;
  5. }

This part of the code is doing two things, first it is telling server to start a session which essentially means it allows your code to use and check for temporarily set cookies. These cookies will only stay on your computer until you close the browser you’re using. This is great for making sure the person who clicked accept is the one viewing your website since once they close the window the cookie will disappear.

The second part is checking if the cookie grant_access has not been set, if it hasn’t then we say it has a value of unset. We need to do this because by default cookies aren’t set until the page is reloaded. On to the next part of the code:

  1. if(isset($_POST['agree'])) {
  2.         $_SESSION['grant_access'] = ‘set’;
  3. }

This is a checking to see if the button “I agree” has been pressed and in turn posted its value. Once the button has been pressed/posted it changes the value of the temp cookie grant_access to set instead of unset. Now onto the third check:

  1. if($_SESSION['grant_access'] == ‘unset’) {
  2. ?>
  3.         <h1>You don’t have Access to this content.</h1>
  4.         <h2>You must click the I Agree button to view this content.</h2>
  5.         <form method="post">
  6.                 <input type="submit" value="I Agree" name="agree" />
  7.         </form>
  8. <?php
  9. } else {
  10. ?>

This part of the code is checking to see if the temp cookie grant_access value is unset. Remember the default value is unset as we defined it above. If it is then it spits out the little bit of HTML. If it value isn’t unset it will show the content as normal. Now for the last bit of the code:

  1. <?php } ?>

This is simply closing the else statement around the code that makes loop function once the user has clicked the I Agree button.

Note: If a user doesn’t have cookies enabled for whatever reason then this message will reappear on every page/post they try to visit as the temporary cookie being set isn’t saving due to cookies being disabled.


Photo Excerpt WordPress Theme Sneak Peak

January 7th, 2011 by

I decided to post a sneak peak of the wordpress theme I’m working on for distribution as it isn’t quite as “quick and easy” as I first thought. Well to be honest I came up with more features I thought should be included by default.

That being said here’s a preview of how the posts will appear on the home page:

Wordpress Photo Excerpt Theme by Robert Heck

If there is no image in the post it will show a question mark. If there is a picture in the post it will scale it down a bit and put it in the gray area instead of the question mark. If there are several pictures in a given post it will grab the first image of the post.


Kelley Pool Repair Inc. Business Website

December 21st, 2010 by

Kelley Pool Repair Inc. designed by Robert Heck

Client: Andy
Website:http://www.kprepair.com
Site Features:

  • XHTML Coding
  • PHP Coding
  • CSS Styling
  • WordPress CMS

Info:Andy came to me with the idea of building a website for the family business as a Christmas present to his father. I went over a couple of ideas with Andy and his sister until we came up with this final layout that they liked. After building the initial mock up in hand coded HTML/PHP/CSS Andy and his sister went over some features they wanted to have added which involved them being able to create/update/delete pages.

They wanted an easy way to do this without having to work around my schedule so I went over a few options and I decided to use WordPress for it. This way they had a simple and easy to use back-end that gave them the ability to create/update/delete posts as they needed and I even built each page through the WordPress back-end so they could change the text on them if they felt the need.


Mrs. Heck Classroom Website

December 20th, 2010 by

Mrs. Heck Website designed by Robert Heck

Client: Alexis
Website:http://www.mrsheck.com
Site Features:

  • XHTML Coding
  • PHP Coding
  • CSS Styling
  • WordPress CMS

Info:Alexis came to me with the idea of a website for her class where she could post homework and images for her students and their parents/guardians. I decided to go with WordPress because it would allow me the ease of being able to give it the cute cartoon bubbly look that matches Alexis’ personality that she carries over even as a teacher. The other reason was because blogs are something she is really familiar with so it would be easy for her to update.


Tutorial – Customizing your Sidebar

August 28th, 2010 by

This tutorial is meant to further expand upon my “Building a WP Theme from Scratch” tutorial.


Just setting up the linking to this page for now.


Tutorial – Building a WordPress 3 Theme From Scratch

August 27th, 2010 by

I’ve wanted to learn how to build a wordpress 3 theme myself. The problem I’ve come across is that there aren’t very many tutorials on building a wordpress 3 theme and the documentation on WordPress.org is a bit confusing when it comes to learning how to setup the files past the true bare minimum without knowing how to hunt through several different links. That being said I hope to clear this up in this tutorial on how to build a basic wordpress theme from scratch.


With that out of the way lets get started. These are the bare minimum files you need inside your theme’s folder to get a WP theme working.
index.php
style.css

Each of these files require some code inside them and that code is:
index.php(Found here):

  1. <?php get_header(); ?>
  2. <?php get_footer(); ?>

This will call the header.php and footer.php files in the default theme folder. You can create your own custom header.php and footer.php files and put them in your theme folder and it will call those instead without having to change this code later. In another tutorial I will go over customizing your own header and footer files for now this will work for a basic setup.

style.css(Found here):

  1. /*
  2. Theme Name:
  3. Theme URL:
  4. Description:
  5. Author:
  6. Author URI:
  7. Version: 1.0
  8. Tags:
  9. Change Log : 1.0.0.0 – Original version
  10. */

Fill out this portion of the CSS as this is what gets loaded for the theme information in the wordpress backend.
Here is what your index page should look like now:

Now that you have the bare minimum you’ll have a site that loads your header and footer but nothing else. So lets add the next set of PHP required to load the actual blog posts. That is the loop.php file.


Here is the most basic loop.php code (taken from The Loop in Action) you’ll need to see your blog posts:

  1. <?php
  2. if (have_posts()) :
  3.    while (have_posts()) :
  4.       the_post();
  5.       the_content();
  6.    endwhile;
  7. endif;
  8. ?>

Here’s what you’ll see with this code if you’ve added the loop call below, notice there is no title for the blog post:

What I want to show you, and have you use is actually a bit more of an advanced version than the bare minimum, this set of code will pull in the title, link to the post, date, author, the post itself, and the category it was posted under. Here is what should go in your loop.php:

  1. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  2.  
  3.  <div class="post">
  4.  
  5.  <!– Display the Title as a link to the Post’s permalink. –>
  6.  <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
  7.  
  8.  <!– Display the date (Month day, year) and a link to other posts by this posts author. –>
  9.  <small><?php the_time(‘F jS, Y’) ?> by <?php the_author_posts_link() ?></small>
  10.  
  11.   <div class="entry">
  12.     <?php the_content(); ?>
  13.   </div>
  14.  
  15.   <p class="postmetadata">Posted in <?php the_category(‘, ‘); ?></p>
  16.  </div>
  17.  
  18.  <?php endwhile; else: ?>
  19.  <p>Sorry, no posts matched your criteria.</p>
  20.  <?php endif; ?>

Save your loop file and now go back to the index.php file so we can add the call for the loop. This is the line of code to call the loop in:

  1. <?php get_template_part( ‘loop’, ‘index’ ); ?>

Add that in between the calls for the header and the footer as you want the posts to show up inside of the website’s top and bottom. Your index.php should look like this now:
index.php:

  1. <?php get_header(); ?>
  2. <?php get_template_part( ‘loop’, ‘index’ ); ?>
  3. <?php get_footer(); ?>

Here is what this will look like or should:

There is one last call that is optional which is adding the sidebar which can be done by adding this simple call to your index.php:

  1. <?php get_sidebar(); ?>

So your index.php will look like this:

  1. <?php get_header(); ?>
  2. <?php get_sidebar(); ?>
  3. <?php get_template_part( ‘loop’, ‘index’ ); ?>
  4. <?php get_footer(); ?>

You can move the sidebar later on as needed for design purposes, just remember keep it inside the header and footer calls.
After adding the sidebar call your page will look something like this, now keep in mind since you don’t have any CSS styling your page the sidebar will now be at the top of the page:

Save all your files and check your blog out. Now this won’t be pretty as you don’t actually have any styling code in your style.css but it will give you plenty of ids and classes to attach styling to your blog.


Thank you for taking the time to read through this tutorial and I hope you found it useful.