[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

Wordpress Custom Theme Concepts

I've decided to start doing my sites in Wordpress because more and more clients are asking for a CMS to edit their site.  It seems like a good fit - and it's easy to install and use, so - why not.

As I'm trying to take the next step and create a custom theme, including a home.php page that mimics my site, I'm struggling to come up with the best way to do it.

I include get_header(), get_sidebar(), and get_footer() in the home.php file, including all my text and images from the original design.

This particular page has a few paragraphs on it - and Ideally it would be great if the users could change this without needing to access home.php.   Is this possible?  The page doesn't show up in "pages" in Wordpress' back end - (and I'm sure missing whatever code would be needed anyway (on home.php) to take a value from the database.)

Also, the right column (side_bar) is kind of similar throughout the entire site with 2 or 3 sections: a block quote, an area for quick facts, and all pages except the home page also have a quick contact form.

Since I want the block quotes and quick facts to be different on each page (user input) I was wondering if custom fields were the best way to do this, or if there was a better way.

Hope this isn't too confusing of a question.  Thanks for the help!
0
slightlyoff
Asked:
slightlyoff
  • 2
  • 2
2 Solutions
 
Tom BeckCommented:
In WordPress, it's common to generate all content via posts. The key mechanism is "The Loop" as described here:

http://codex.wordpress.org/The_Loop

To restrict which posts appear on which page of the site you can compose your content in posts and then divide your posts into categories. Then in the php file for the page you want to fill with content, restrict the Loop to only those posts from a certain category like this:

<?php query_posts('cat=2'); ?>

In addition to your custom home.php page you may want to create other custom pages to display different posts as content. Creating custom pages is easy, just clone the home.php page, rename it, and place the required template info at the top. Doing this causes the template to appear in the drop down list of templates when creating new pages in the Dashboard. An example of what to place at the top of a template page:

<?php
/*
 * Template Name: About Page Template
 * Description: About page template.
 */
?>

The words "About Page Template" will appear in the drop down for you to select when you create an About page for example.

Keep all templates including the custom home.php in the child theme folder.
0
 
slightlyoffAuthor Commented:
Perfect!  

Just to clarify - I'd create a page called homepage content, put it in a category and in my home.php file I'd limit the query_posts inside The Loop to the category that has the homepage content in it.  Right?

Thanks for the quick reply!
0
 
Tom BeckCommented:
Set up your WP file structure like this if you have not already:

<root>/wp-content/themes/<parent theme>
    --> original home.php
    --> original functions.php
    --> original styles.css
    --> etc, etc,

<root>/wp-content/themes/<child theme>
    --> cloned, customized home.php
    --> cloned, customized functions.php (if needed)
    --> cloned, customized styles.css (if you want to tweak the original theme)
    --> <page template 1 name>.php (these can be clones of home.php to start with)
    --> <page template 2 name>.php
    --> <page template 2 name>.php
    --> etc, etc.

Be sure to name each template in the comment area at the top of the php file.

You can use the cloned home.php as your customized home page or rename it homepage.php or whatever. You can designate any page as the home page.

It's important to set up the file structure this way because you will inevitably have to reinstall WordPress somewhere down the line. By keeping all of the customized files in one place, you can back that up and reinstall WP without worry. Never alter original WP files.

Now, from the WP Dashboard, create categories for posts. A category corresponding to each page name.

Create new post(s) for the content you want to appear on each page and be sure to check the appropriate post category that corresponds to the page name.

On your <page template 2 name>.php files add the <?php query_posts('cat=2'); ?> to the code where appropriate to add only the posts associated with that page.
0
 
Jason C. LevineNo oneCommented:
slightlyoff,

Please read this WordPress Codex entry on Template Hierarchy

http://codex.wordpress.org/Template_Hierarchy

Basically, you want to create custom templates and then match them up to something (read the article see the definition of "something") like the post ID or slug and then use custom fields to control any variable content.
0
 
slightlyoffAuthor Commented:
Thanks for your help - I think I'm getting the hang of it.  I'm posting another question about best practices - and would love your feed back.

Thanks again!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now