® Smashing WordPress Themes Table of Contents Introduction Part I: What Are WordPress Themes? Part II: Hacking a Theme Part III: Building Your Own Theme Part IV: Taking Themes Further Chapter 1: Getting Started with WordPress Installing WordPress in Just Five Minutes Running WordPress Using a Web Host Running WordPress Locally Fine Tuning Your WordPress Settings Permalinks Media Settings and the Upload Folder Other noteworthy Settings Shameless Self Promotion WordPress Theme Files WordPress As a CMS Posts, Pages, and New Custom Post Types Taxonomies Custom Post Types The WordPress Codex Wrapping It Up Chapter 2: This is a Theme About Themes The Stylesheet Theme Declaration Set tags for your theme Define a child theme Add comments for developers The template files at your disposal Header and Footer Template Files The Loop and your Content What is the Wordpress Loop? The Loop TEMPLATE tag Using the Loop in TEMPLATE FILEs The Functions.PHP File Using Page Templates Creating a Page Template Why use Page Templates? Understanding Template Tags Wrapping It Up Chapter 3: Digging into the Twenty Ten Theme Working With the loop The external loop.php file Do I have to use loop.php? The Twenty Ten loop Displaying Posts with loops Example: Listing Only Titles in Category Archives Working With Template Tags Passing parameters about strings, booleans, and integers Finding the template tag you want A few words about localization Conditional Content with Conditional Tags Working with conditional tags Example: Adding Conditional Sidebars Enabling Features in functions.php Add the add_theme_support template tag Pass the correct parameters Adding Widgets using template files Define widget areas Add widget areas to the template files Put widgets to good use Example: Adding a New Widget Area The Power of Custom Page templates Create a Custom page template Example: Creating an Archives Page Template Finding Your Way With custom Menus Declare a Menu Area Add A Menu area to your template files Example: Adding a Menu Area Changing your Header Image Define the header in functions.php Display the header in your theme Example: Adding a Custom Header Adjusting Your Site Background Wrapping It Up Chapter 4: Using Child Themes The Child Theme Concept Why are child themes so great? How Child Themes Work Getting parent theme styles into a child theme Finding images in child themes Functions and child themes Example: Creating a Simple Child Theme The perfect Twenty Ten project Twenty Ten and Child Themes Example: Adding a Second Sidebar Using Child Themes in Multiple Network Sites Wrapping It Up Chapter 5: Choosing a Theme Picking the Right Theme Design issues Layout issues Development issues Theme Frameworks What Is A Good Framework, Then? Commercial themes The Official Themes Directory Things to be Wary About Wrapping It Up Chapter 6: Planning the Theme Plan Before You Build The site concept stage The site design Your Own Theme Framework The purpose of a framework Should you build a theme framework? Releasing Themes to the public Getting your themes on wordpress.org Picking the right license Localization The Checklists The theme checklist The theme framework checklist The child theme checklist Wrapping It Up Chapter 7: A Semi-Static Theme WordPress and Semi-Static web Sites Our fictional semi-static Web site Web site requirements Making Categories and Pages Work in Harmony Fixing the category URLs Why is this important? The Semi-Static Theme Layout What is what in the mock-ups? Building the semi-static Site The fundamentals: style.css and functions.php theme files for our shell (header, footer, and index) The various sidebars The loop template The front page template Wait, what about the stylesheet? And We’re Done! Get the semi-static theme for free Building child themes on Semi-Static sites Wrapping It Up Chapter 8: A Media Theme Building sites for Images and Video Site layout Making Everything Fit Together The content flow Building the Media site The functions.PHP file Setting up the basic shell Single posts and attachments The attachment sidebar Thumbnail browsing in posts Taking care of the footer Spicing It Up with Plugins Lightboxes Wrapping It Up Chapter 9: A Magazine Theme Planning an Online Magazine The Notes Mag 1.0 theme layout Dynamic elements for Notes Mag Building The magazine site The basic site structure Starting with the header Ending with the footer Getting to the content Creating the stylesheet Viewing The theme thus far Adding Functionality Starting with functions.php Adding widget areas Planning the custom menu Adding Our custom header logo Creating Action Hooks Viewing our final functions.php Templates, Templates, Templates Setting up the front page Populating The front page with content Single Posts and Pages The archives Making Notes Mag Look Good Styling the menu A quick look at the archives Single posts and Pages Wrapping It Up Chapter 10: The Buddypress Community What is BuddyPress? Should I use BuddyPress? The BuddyPress Template Pack The BuddyPress template files overview Adding the BuddyPress Template Pack to a WordPress site Case Study: Adding buddypress Community Features to a site A few words about buddypress upgrades Modifying the template files to fit a site What are all those new tags? Fixing permalinks and localization Adding bbPress to Your Groups About BuddyPress Themes Focus on community features Child theming BuddyPress themes Wrapping It Up Chapter 11: Extending with Plugins When Should You USE Plugins? Developing themes that rely on plugins How to pick the right plugin 25 Truly Great Plugins Commenting plugins Content related stuff Lightbox Plugins CMS plugins Writing Your Own Plugins Wrapping It Up Smashing WordPress Themes Making Wordpress Beautiful Thord Daniel Hedengren This edition first published 2011 © 2011 John Wiley & Sons, Ltd. Registered office John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex, PO19 8SQ, United Kingdom Editorial office John Wiley & Sons Ltd, The Atrium, Southern Gate, Chichester, West Sussex, PO19 8SQ, United Kingdom For details of our global editorial offices, for customer services and for information about how to apply for permission to reuse the copyright material in this book please see our website at www.wiley.com. The right of the author to be identified as the author of this work has been asserted in accordance with the Copyright, Designs and Patents Act 1988. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, except as permitted by the UK Copyright, Designs and Patents Act 1988, without the prior permission of the publisher. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. Designations used by companies to distinguish their products are often claimed as trademarks. All brand names and product names used in this book are trade names, service marks, trademarks or registered trademarks of their respective owners. The publisher is not associated with any product or vendor mentioned in this book. This publication is designed to provide accurate and authoritative information in regard to the subject matter covered. It is sold on the understanding that the publisher is not engaged in rendering professional services. If professional advice or other expert assistance is required, the services of a competent professional should be sought. Trademarks: Wiley and the Wiley Publishing logo are trademarks or registered trademarks of John Wiley and Sons, Inc. and/ or its affiliates in the United States and/or other countries, and may not be used without written permission. iPhone, iPad and iPod are trademarks of Apple Computer, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc. is not associated with any product or vendor mentioned in the book. This book is not endorsed by Apple Computer, Inc. A catalogue record for this book is available from the British Library. ISBN 978-0-470-66990-7 Set in Minion Pro 10/12 by Wiley Composition Services Printed in U.S. by CJK February 2011 Publisher’s Acknowledgments Some of the people who helped bring this book to market include the following: Editorial and Production VP Consumer and Technology Publishing Director: Michelle Leete Associate Director-Book Content Management: Martin Tribe Associate Publisher: Chris Webb Publishing Assistant: Ellie Scott Project Editor: Susan B. Cohen Copy Editor: Susan B. Cohen Technical Editor: John O’Nolan Editorial Manager: Jodi Jensen Senior Project Editor: Sara Shlaer Editorial Assistant: Leslie Saxman Marketing Senior Marketing Manager: Louise Breinholt Marketing Executive: Kate Parrett Composition Services Compositor: Indianapolis Composition Services Proofreader: Susan Hobbs Indexer: Potomac Indexing, LLC Smashing WordPress Themes is dedicated to the WordPress community. We’re all playing an important part by making free speech easier online. The more people can express their thoughts, dreams, and ideas, the better for everyone. Open source in general, and WordPress in particular, play an important role in the free speech movement. Keep up the great work, dear community. Thord Daniel Hedengren About the Author Thord Daniel Hedengren is addicted to words, which led him to launch his first online newsletter in 1996. It all went downhill from there, with dozens of Web sites, and a career as an editor and freelancer in both Sweden and abroad. His international career began with a blog post, which led to a book deal for Smashing WordPress: Beyond the Blog, with Wiley Publishing, Inc., and an even stronger voice in the WordPress community. You’re now holding Thord’s second book. When not obsessed with words, Thord and his friends build cool Web sites using WordPress at his Web design firm, Odd Alice. He also edits magazines and writes freelance articles for both print and Web publications (in Swedish and English). You can follow everything Thord on http://tdh.me. Thord lives in the land of kings, Sweden.