CYAN YELLOW MAGENTA BLACK PANTONE 123 C www.it-ebooks.info BOOKS FOR PROFESSIONALS BY PROFESSIONALS® THE EXPERT’S VOICE® IN WEB DEVELOPMENT Companion eBook Available Beginning WordPress 3 Beginning Dear Reader, W When I began looking for WordPress books, I found plenty of incredibly basic guides for blogging and a few hardcore advanced guides for developers, but nothing in-between for beginners who want to get more out of WordPress. This book fills that gap. It’s a beginning developer guide that treats WordPress like o Beginning the powerful content management system it has become. If you’re a web devel- Stephanie Leary oper who already understands HTML, CSS, and maybe a little PHP, but you’ve r never used WordPress before, this book is for you. Inside, you’ll learn how to install, configure, and customize WordPress to d make it the perfect CMS for your next project. It walks you through the com- WordPress 3 plete development of a WordPress site, starting with importing content from P another CMS, or creating your own from scratch. You’ll then learn how to cre- ate custom themes that give you complete control over your site’s appearance, including optimizing it for that that all-important search engine optimization. r You’ll see how to extend WordPress with widgets and plugins when your needs e outstrip the built-in features. Finally, you’ll learn how to secure your WordPress installation and optimize its performance. s This book also covers two of the big new features in WordPress version 3: custom content types, which let you take your content beyond basic blog posts Make great websites the easy way and pages, and the network (the integration of WordPress MU into the core s software), which lets you build numerous connected WordPress sites from a single software installation. The code samples in this book include two themes that you can customize 3 fully, and several complete plugins that you can work through and modify. By the end of the book you will have the knowledge to create your own plugins and share them with other users on the WordPress Extend site. Every example in this book was taken from a real-world project and has been tested and proven A complete beginner's guide to WordPress that out in the open. I hope that all of the information, examples, and source code provided in this book helps you learn to use and adapt WordPress in your own shows you how to create a customized website for Companion eBook work, and to create some great sites. I look forward to seeing them. yourself, your business, or your social network Stephanie Leary See last page for details on $10 eBook version Stephanie Leary SOURCE CODE ONLINE www.apress.com ISBN 978-1-4302-2895-0 L e 53999 a r y US $39.99 Shelve in: Web Development/General User level: 9 781430 228950 Beginner this print for content only—size & color not accurate 7.5 x 9.25 spine = 0.8125" 432 page count www.it-ebooks.info www.it-ebooks.info Beginning WordPress 3 (cid:132) (cid:132) (cid:132) Stephanie Leary www.it-ebooks.info Beginning WordPress 3 Copyright © 2010 by Stephanie Leary All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-2895-0 ISBN-13 (electronic): 978-1-4302-2896-7 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. President and Publisher: Paul Manning Lead Editor: Ben Renow-Clarke Technical Reviewer: Shelley Keith Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Laurin Becker, Fran Parnell Copy Editor: Mary Behr Compositor: Bytheway Publishing Services Indexer: Toma Mulligan Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer Science+Business Media, LLC., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer- sbm.com, or visit www.springeronline.com. For information on translations, please e-mail [email protected], or visit www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. The source code for this book is available to readers at www.apress.com. You will need to answer questions pertaining to this book in order to successfully download the code. www.it-ebooks.info (cid:132) CONTENTS Contents at a Glance (cid:132) Contents.................................................................................................................iv (cid:132) About the Author..................................................................................................xvi (cid:132) About the Technical Reviewer............................................................................xvii (cid:132) Acknowledgments.............................................................................................xviii (cid:132) Introduction.........................................................................................................xix (cid:132) Chapter 1: About WordPress...................................................................................1 (cid:132) Chapter 2: Installing and Upgrading.....................................................................15 (cid:132) Chapter 3: Dashboard and Settings......................................................................41 (cid:132) Chapter 4: Working with Content..........................................................................61 (cid:132) Chapter 5: Importing Content.............................................................................105 (cid:132) Chapter 6: Creating a Basic Theme ....................................................................125 (cid:132) Chapter 7: Creating an Advanced Theme............................................................173 (cid:132) Chapter 8: Creating Widgets...............................................................................205 (cid:132) Chapter 9: Creating Plugins................................................................................225 (cid:132) Chapter 10: Users and Roles...............................................................................271 (cid:132) Chapter 11: Performance and Security ..............................................................289 (cid:132) Chapter 12: Custom Content Types, Taxonomies, and Fields.............................309 (cid:132) Chapter 13: Setting up the Network...................................................................347 (cid:132) Appendix 1: Plugin Index....................................................................................373 (cid:132) Appendix 2: Theme Functions.............................................................................381 (cid:132) Appendix 3: Plugin Recipes................................................................................385 (cid:132) Index...................................................................................................................389 iii www.it-ebooks.info (cid:132) CONTENTS Contents (cid:132) Contents at a Glance..............................................................................................iii (cid:132) Contents.................................................................................................................iv (cid:132) About the Author..................................................................................................xvi (cid:132) About the Technical Reviewer............................................................................xvii (cid:132) Acknowledgments.............................................................................................xviii (cid:132) Introduction.........................................................................................................xix (cid:132) Chapter 1: About WordPress...................................................................................1 Why WordPress?................................................................................................................1 Easy to Set Up..........................................................................................................................................1 Easy to Use...............................................................................................................................................2 Easy to Extend..........................................................................................................................................3 The Business Benefits of WordPress........................................................................................................4 Sites Built with WordPress................................................................................................4 Personal Blogs..........................................................................................................................................4 Blog Networks..........................................................................................................................................6 Social Networks........................................................................................................................................8 Colleges and Universities.........................................................................................................................9 Small Businesses...................................................................................................................................10 WordPress Tour...............................................................................................................11 Anatomy of a post...................................................................................................................................12 Summary.........................................................................................................................14 (cid:132) Chapter 2: Installing and Upgrading.....................................................................15 iv www.it-ebooks.info (cid:132) CONTENTS System Requirements.....................................................................................................15 One-click Installation.......................................................................................................15 Installation Using the Web Interface................................................................................16 Logging In........................................................................................................................20 Editing and Uploading wp-config.php..............................................................................22 Troubleshooting...............................................................................................................23 Installing Themes............................................................................................................25 Installing Plugins.............................................................................................................28 Plugging the gaps: Essential Plugins......................................................................................................32 Upgrading Plugins..................................................................................................................................33 Upgrading WordPress......................................................................................................35 Automatic Upgrades...............................................................................................................................36 Manual Upgrades....................................................................................................................................38 Moving a WordPress Site.................................................................................................39 Summary.........................................................................................................................40 (cid:132) Chapter 3: Dashboard and Settings......................................................................41 The Dashboard.................................................................................................................42 QuickPress..............................................................................................................................................43 Incoming Links.......................................................................................................................................43 WordPress Development Blog................................................................................................................44 Plugin dashboard widgets......................................................................................................................44 Dashboard Widgets and Users...............................................................................................................44 Settings............................................................................................................................45 General...................................................................................................................................................45 Writing....................................................................................................................................................47 Reading..................................................................................................................................................48 Discussion..............................................................................................................................................49 Media......................................................................................................................................................54 v www.it-ebooks.info (cid:132) CONTENTS Privacy....................................................................................................................................................56 Permalinks..............................................................................................................................................57 Summary.........................................................................................................................59 (cid:132) Chapter 4: Working with Content..........................................................................61 Posts................................................................................................................................61 Content...................................................................................................................................................63 Permalinks..............................................................................................................................................70 Publish Settings......................................................................................................................................70 Categories..............................................................................................................................................71 Tags........................................................................................................................................................72 Featured Images.....................................................................................................................................74 Excerpts..................................................................................................................................................75 Comments and Trackbacks....................................................................................................................75 Revisions................................................................................................................................................77 Custom Fields.........................................................................................................................................78 Pages...............................................................................................................................78 Page Attributes: Parents, Templates, and Order....................................................................................78 Posts vs. Pages: Same, but Different...............................................................................82 Posts are Pages; Pages are Posts..........................................................................................................83 Editing Posts and Pages.........................................................................................................................83 Media Files......................................................................................................................88 Images and Galleries..............................................................................................................................88 Video.......................................................................................................................................................94 Audio......................................................................................................................................................96 Other File Types......................................................................................................................................97 The Media Library...................................................................................................................................97 Links................................................................................................................................98 Basic Link Attributes..............................................................................................................................98 vi www.it-ebooks.info (cid:132) CONTENTS Link Relationships: XFN™......................................................................................................................99 Advanced Link Attributes......................................................................................................................101 Link Feed..............................................................................................................................................101 Feeds.............................................................................................................................101 Summary.......................................................................................................................103 (cid:132) Chapter 5: Importing Content.............................................................................105 Before Importing............................................................................................................105 Importing Blogs.............................................................................................................105 Importing from WordPress.com............................................................................................................107 Importing from Blogger........................................................................................................................110 Importing Joomla or Mambo Sites.................................................................................113 Importing Other MySQL-based Sites.............................................................................116 Drupal...................................................................................................................................................116 Importing HTML Files.....................................................................................................117 After Importing: Fixing What’s Broken...........................................................................120 Link URLs..............................................................................................................................................120 Paths to Linked Files............................................................................................................................121 Truncated or Garbled Content..............................................................................................................122 Summary.......................................................................................................................123 (cid:132) Chapter 6: Creating a Basic Theme ....................................................................125 Using Widgets................................................................................................................125 Using Menus..................................................................................................................127 Creating a Menu...................................................................................................................................127 Editing Menu Items...............................................................................................................................128 Creating Multiple Menus......................................................................................................................129 Using Header and Background Images..........................................................................130 Turning HTML into a Theme...........................................................................................132 vii www.it-ebooks.info (cid:132) CONTENTS Header..................................................................................................................................................134 Body......................................................................................................................................................135 Footer...................................................................................................................................................141 Stylesheet.............................................................................................................................................141 Template Tags...............................................................................................................142 Theme Files...................................................................................................................144 Theme File Hierarchy.....................................................................................................145 The Home Page....................................................................................................................................146 Single Posts..........................................................................................................................................146 Pages....................................................................................................................................................146 Custom Content Types..........................................................................................................................146 Category Archives.................................................................................................................................147 Tag Archives.........................................................................................................................................147 Custom Taxonomy Archives.................................................................................................................147 Author Archives....................................................................................................................................148 Date-Based Archives............................................................................................................................148 Search Results......................................................................................................................................148 Error 404 (File Not Found) Page...........................................................................................................148 Attachment Pages................................................................................................................................149 Listing Comments..........................................................................................................149 Including Additional Files...............................................................................................151 Styling Content..............................................................................................................151 Changing Appearance Based on Context.......................................................................151 Conditional Tags...................................................................................................................................152 Posts vs. Pages.....................................................................................................................................153 Categories............................................................................................................................................153 Author Archives....................................................................................................................................154 Search Results......................................................................................................................................155 viii