You are previewing WordPress 2.8 Themes Cookbook.
O'Reilly logo
WordPress 2.8 Themes Cookbook

Book Description

Over 100 simple but incredibly effective recipes for creating powerful, custom WordPress themes

  • Take control of the look and feel of your WordPress site

  • Quick recipes to get started and successfully build advanced themes

  • Step-by-step instructions and useful screenshots for easy learning

  • Give a professional look to your web site with popular JavaScript libraries

  • In Detail

    Themes are among the most powerful features that can be used to customize a web site and give it a professional look, especially in WordPress. Using custom themes you can brand your site for a particular corporate image, ensure standards compliance, and create easily navigable layouts. But most WordPress users still continue to use default themes as developing and deploying themes that are flexible and easily maintainable is not always straightforward and lot of issues pop up during the process.

    This easy-to-use step-by-step guide will help you create powerful themes for your WordPress web site, and solve your theme development problems in a quick and effective way. It enables you to take full control over your site's design and branding and make it look smarter.

    WordPress is distributed with two ready-to-use themes. You can use these themes to give a common look to your website, or use the techniques described in this book to create custom themes. This book includes over 100 useful recipes to help you get started and create advanced themes. It starts with the basics of WordPress themes and creating a theme from scratch. Then, it covers how to enhance your template and add effects to get a rich look. You will learn how to manage pages, categories, and tags for your blogs, and how to make your posts look unique. You will also learn about the comment system and sidebars that will help you give a new feel to your blog and web site.

    This book will help you through the most common problems encountered when developing a WordPress theme. You will get tips to enhance your design skill and eventually enhance your blog's design.

    Get solutions to common WordPress theme design problems and create custom themes to make your web site look smarter

    Table of Contents

    1. WordPress 2.8 Themes Cookbook
      1. WordPress 2.8 Themes Cookbook
      2. Credits
      3. About the Authors
      4. About the Reviewers
      5. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Errata
          2. Piracy
          3. Questions
      6. 1. WordPress Theme Basics
        1. Introduction
        2. Finding documentation on WordPress.org
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Downloading themes from the WordPress theme repository
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Try search
            2. Tag filter
        4. Downloading themes from third-party websites
          1. How to do it...
          2. How it works...
          3. There's more...
        5. Installing and activating a theme
          1. Getting ready
          2. How to do it...
          3. How it works...
        6. Displaying the blog name
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Blog info available
            2. Retrieving information without displaying it
        7. Getting the absolute directory path of the active theme
          1. How to do it...
          2. How it works...
        8. Creating a theme from scratch
          1. How to do it...
          2. There's more...
            1. Recognized WordPress files
            2. Organizing a theme
          3. See also
        9. Creating a child theme
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Maintaining default styling
          5. See also
        10. Creating a theme by using a theme framework
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        11. Adding expected WordPress hooks
          1. How to do it...
          2. How it works...
          3. There's more...
        12. Including PHP files from your theme
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
      7. 2. Creating Navigation
        1. Introduction
        2. Listing all of the pages that exist on a blog
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Passing parameters
        3. Listing all of the categories defined for a blog
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Passing parameters
        4. Listing all of the tags in use on a blog
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Passing parameters
        5. Highlighting the current page in the navigation
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Adding a search function to a theme
          1. How to do it...
          2. How it works...
          3. There's more...
        7. Getting the category page link from a category name
          1. How to do it...
          2. How it works...
        8. Displaying page links only if the destination page exists
          1. How to do it...
          2. How it works...
        9. Creating a category drop-down menu
          1. How to do it...
          2. How it works...
        10. Creating drop-downs using child pages
          1. Getting started
          2. How to do it...
          3. How it works...
          4. See also
      8. 3. The Loop
        1. Introduction
        2. Creating a basic Loop
          1. How to do it...
          2. How it works...
        3. Displaying ads after every third post
          1. How to do it...
          2. How it works...
        4. Removing posts in a particular category
          1. How to do it...
          2. How it works...
        5. Removing posts with a particular tag
          1. How to do it...
          2. How it works...
        6. Highlighting sticky posts
          1. How to do it...
          2. How it works...
        7. Creating multiple loops in a single template
          1. How to do it...
          2. How it works...
          3. There's more…
        8. Displaying only posts in a particular category
          1. How to do it...
          2. How it works...
        9. Styling every other post differently
          1. How to do it...
          2. How it works...
        10. Styling posts in a particular category differently
          1. How to do it...
          2. How it works...
        11. Showing every post in a category on a category archive page
          1. How to do it...
          2. How it works...
          3. See also
      9. 4. Template Tags
        1. Introduction
        2. Displaying the post title
          1. How to do it...
          2. How it works...
          3. There's more...
          4. See also
        3. Automatically limiting the number of words of content
          1. How to do it...
          2. How it works...
        4. Determining if the user is on a specific page
          1. How to do it...
          2. How it works...
        5. Determining if the user is viewing a post in a particular category
          1. How to do it...
          2. How it works...
          3. There's more...
        6. Displaying the post date for each post
          1. How to do it...
          2. How it works...
        7. Highlighting search terms in post content
          1. How to do it...
          2. How it works...
        8. Displaying login/logout links
          1. How to do it...
          2. How it works...
          3. There's more...
        9. Adding navigation through older/newer posts
          1. How to do it...
          2. How it works...
          3. There's more...
        10. Displaying an edit link for posts
          1. How to do it...
          2. How it works...
        11. Displaying custom field content
          1. How to do it...
          2. How it works...
          3. There's more...
        12. Displaying a post author's avatar
          1. How to do it...
          2. How it works...
      10. 5. Comments
        1. Introduction
        2. Displaying a comment form on a post
          1. How to do it...
          2. How it works...
          3. There's more...
        3. Displaying comments on a post
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Separating comments and trackbacks
            2. Changing the Avatar size
            3. Available parameters
        4. Displaying the latest comments on your blog
          1. How to do it...
          2. How it works...
          3. There's more...
            1. Getting only certain comment types
            2. Getting only comments for a particular post
            3. Available parameters
        5. Highlighting the post author's comments
          1. How to do it...
          2. How it works...
          3. See also
        6. Alternating the style for comments
          1. How to do it...
          2. How it works...
          3. See also
        7. Displaying threaded comments properly
          1. How to do it...
          2. How it works...
          3. See also
      11. 6. Sidebars
        1. Introduction
        2. Using the Text widget for custom sidebar content
          1. Getting ready
          2. How to do it...
        3. Including a dynamic sidebar in your theme
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Finding inspiring sidebars for your theme design
        4. Including multiple dynamic sidebars in your theme
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Sidebar parameters
            2. Default content
        5. Setting the default widgets for a sidebar in your theme
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Widget IDs
        6. Positioning multiple sidebars in your theme by using CSS
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Position: absolute versus float
            2. Doing more with design and layout
        7. Styling the appearance of sidebars in your theme by using CSS
          1. Getting ready
          2. How to do it…
          3. How it works…
          4. There's more…
            1. Design and Layouts: The WordPress codex
            2. Sandbox: The theme for maximum appearance options
        8. Displaying different widgets on different pages by using the Widget Logic plugin and conditional tags
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Getting more out of conditional tags
            2. Specific sidebars for custom theme pages
        9. Showing asides in the sidebar by using the Miniposts plugin
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more…
            1. Creating custom asides
        10. Adding an interactive Facebook-style wall to a sidebar by using jQuery
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Doing more with WP Wall
      12. 7. Custom Page Templates
        1. Introduction
        2. Creating a simple page template
          1. Getting ready
          2. How to do it...
          3. How it works...
        3. Creating an archives page template
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Listing archive links
            2. Listing Categories
          5. See also
        4. Creating a taxonomy navigation template
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        5. Displaying author avatars and descriptions
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        6. Creating a table of contents page template
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. There's more...
          5. See also
        7. Showing your pictures from Flickr
          1. Getting ready
          2. How to do it...
          3. How it works...
          4. See also
        8. Displaying a special template for a specific category
          1. Getting ready
          2. How to do it...
          3. How it works...
      13. 8. Integrating Media
        1. Introduction
        2. Aligning images properly within a post
          1. Getting started
          2. How to do it...
          3. How it works...
        3. Styling image galleries
          1. Getting started
          2. How to do it...
          3. How it works...
        4. Styling image captions
          1. Getting started
          2. How to do it...
          3. How it works...
          4. See also
        5. Creating a media template
          1. Getting started
          2. How to do it...
          3. How it works...
          4. See also
        6. Creating a media template for a specific media type
          1. Getting started
          2. How to do it...
          3. How it works...
          4. There's more…
            1. Using file and image attachments in WordPress
          5. See also
        7. Displaying a related image for every post
          1. Getting started
          2. How to do it...
          3. How it works...
          4. There's more…
            1. Using Viper's Regenerate Thumbnails plug-in
        8. Creating video posts by using the Viper's Video QuickTags plug-in
          1. Getting started
          2. How to do it…
          3. How it works...
          4. There's more…
            1. Adapting your site for mobile content viewing by using the WPtouch theme
      14. 9. Showing Author Information
        1. Introduction
        2. Getting author data via an author's ID
          1. Getting started
          2. How to do it...
          3. How it works…
        3. Dynamically displaying the author's name and linked e-mail address
          1. Getting started
          2. How to do it…
          3. How it works...
          4. There's more…
            1. Dive deeper into data
        4. Listing all of the published authors on a site
          1. Getting started
          2. How to do it...
          3. How it works...
        5. Listing the authors who most recently published a post
          1. Getting started
          2. How to do it...
          3. How it works...
          4. See also
        6. Listing authors by the total number of comments that their posts have received
          1. Getting started
          2. How to do it...
          3. How it works...
          4. See also
        7. Adding a custom user field to display an author's Twitter link
          1. Getting started
          2. How to do it...
          3. How it works...
          4. There's more…
            1. Displaying an image next to the 'Follow' link
      15. 10. Adding JavaScript Effects
        1. Introduction
        2. Linking to your theme's JavaScript files directly
          1. Getting started
          2. How to do it...
          3. How it works...
          4. See also
        3. Adding JavaScript files to your theme programmatically
          1. Getting started
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Placing wp_enqueue_script in the footer for better site performance
            2. Taking advantage of wp_register_script
        4. Adding a bundled library to your theme programmatically
          1. Getting started
          2. How to do it...
          3. How it works...
          4. There's more...
            1. List of bundled scripts
          5. See also
        5. Creating a featured post slider
          1. Getting started
          2. How to do it...
          3. How it works...
          4. There's more…
            1. Theming your slider with Themeroller
          5. See also
        6. Making sidebar widgets toggle-able
          1. Getting started
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Remembering the widget's state
        7. Adding a font size toggle
          1. How to do it...
          2. How it works…
      16. 11. Advanced WordPress Themes
        1. Introduction
        2. Adding a theme options page
          1. Getting started
          2. How to do it...
          3. How it works...
          4. There's more…
            1. Diving into administrative settings for themes
        3. Allowing for multiple theme color schemes
          1. Getting started
          2. How to do it...
          3. How it works...
          4. See also
        4. Changing the default Gravatar icon for your theme
          1. Getting started
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Forcing your theme to use your default avatar
        5. Registering shortcodes for your theme
          1. How to do it…
          2. There's more…
            1. Displaying Twitter trends by using shortcodes in posts
        6. Localizing your theme
          1. How to do it…
          2. How it works…
          3. There's more…
            1. Becoming a WordPress theme translator
        7. Displaying information based on the logged-in user's role
          1. How to do it…
          2. How it works…
          3. There's more…
            1. Easier ways to use user roles in WordPress 3.0
        8. Packaging your theme for distribution
          1. How to do it…
          2. There's more…
            1. Is your theme really ready for public release?
        9. Uploading your theme to the WordPress.org theme repository
          1. Getting started
          2. How to do it…
          3. How it works…
      17. 12. Layout
        1. Introduction
        2. Adding a skip navigation link for usability
          1. Getting started
          2. How to do it...
          3. How it works...
        3. Centering your site's layout in the browser window
          1. Getting started
          2. How to do it...
          3. How it works...
        4. Setting up a randomly-rotating header image
          1. Getting started
          2. How to do it...
          3. How it works...
        5. Making theme components drag-and-drop
          1. Getting started
          2. How to do it...
          3. How it works...
          4. There's more...
            1. Saving the category order
          5. See also
        6. Creating a global toolbar for your theme
          1. Getting started
          2. How to do it...
          3. How it works...
        7. Creating tabbed navigation for your theme
          1. Getting started
          2. How to do it...
          3. How it works...
          4. There's more…
            1. Many menus, many resources