WordPress 2.7 Complete 184719656X, 9781847196569

This book is easy to read. Covers all of the bases you need to get started. I am an experienced web designer just gettin

312 95 8MB

English Pages 295 Year 2009

Report DMCA / Copyright

DOWNLOAD PDF FILE

Recommend Papers

WordPress 2.7 Complete
 184719656X, 9781847196569

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

WordPress 2.7 Complete

Create your own complete blog or website from scratch with WordPress

April Hodge Silver Hasin Hayder

BIRMINGHAM - MUMBAI

WordPress 2.7 Complete

Copyright © 2009 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: May 2009

Production Reference: 2040609

Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847196-56-9 www.packtpub.com

Cover Image by Parag Kadam ([email protected])

Credits Authors April Hodge Silver

Editorial Team Leader Abhijeet Deobhakta

Hasin Hayder Project Team Leader Reviewers

Lata Basantani

Lee Jordan Narayan Bhat Paul Thewlis

Project Coordinator Leena Purkait Indexer

Acquisition Editor

Rekha Nair

David Barnes Proofreader Development Editor

Sandra Hopper

Ved Prakash Jha Production Coordinator Technical Editor

Shantanu Zagade

Reshma Sundaresan Cover Work Copy Editor Sneha Kulkarni

Shantanu Zagade

About the authors April Hodge Silver has been designing and developing new websites from scratch since 1999, just before her graduation from Columbia University. Early in her career, she worked for several web companies and startups, including DoubleClick and About.com. Since 2004, she has been self-employed through her company Springthistle Design and has worked with a staggering variety of companies, non-proits, and individuals to realize their website dreams. In her professional work, April's focus is always on usability, eficiency, lexibility, clean design, and client happiness. WordPress is the best solution for many of Springthistle's clients, though April also develops custom web applications using PHP and MySQL. You can ind out more about April's professional work at http://springthistle.com. In her free time, April enjoys developing recipes in the kitchen, bicycling, and relaxing with her daughter, dog, and darlin' wife. Of course, I am so grateful to everyone at Packt who worked with me to make this book possible. Also, a huge bunch of thanks to my wife Tessa, who made the connection in the irst place and helped me get started in this medium. Finally, thanks go to Ruth and Hazel, who provided guidance on commas.

Hasin Hayder graduated in Civil Engineering from the Rajshahi University of

Engineering and Technology (RUET) in Bangladesh. He is a Zend-certiied Engineer and expert in developing localized applications. He is currently working as a Technical Director in Trippert Labs and managing the local branch in Bangladesh. Beside his full time job, Hasin writes his blog at http://hasin.wordpress.com, writes article in different websites and maintains his open source framework Orchid at http://orchid.phpxperts.net. Hasin lives in Bangladesh with his wife Ayesha and his son, Aif. First of all, I would like to thank David Barnes, Patricia Weir, Abhijeet Deobhakta, and Nikhil Bangera, without whom the book would have never seen the daylight. After writing for so many sleepless nights, the book is inally over; but I want to thank all those who supported me at that time. My wife Ayesha for storytelling, Little Aif for missing his Papa, the staff of Somewhere In for receiving a sleepy developer in the morning, the staff of Pagelakes for their inspiration, and all the members of my PHP group, phpexperts. I would also like to thank all my family members for their great support during this period. Finally, I dedicate this book to the person who would have been the happiest person to see it; my father, Ali Akbar Mohammad Mohiuddin Hayder (1934-2006).

About the reviewers Lee Jordan is a web developer with a large collection of web technology acronyms on her resume that sound like the names of laundry detergents and cause glazed expressions in school children. She designs and maintains internal and external enterprise-level websites and web-based applications as part of a project team for a privately held technical services company. Her work includes proposing, writing, and editing web content and user guides people actually read. She began her career in 1997 as a web designer after graduating from Florida State University with a Bachelor of Fine Arts, where she swears that she missed at least one home football game while in the computer lab. Lee later convinced Seminole Community College to give her a Web Programming degree in 2003 even though her inal project was a Java-based application that actually contained a usable help ile. Web development topics or whatever she can think of at the time are posted on her blog at http://leejordan.net.

Narayan Bhat's current passion is blogging. You can meet him at his site: The Blog Doctor (http://www.blogdoctor.me). He has reviewed Blogger Beyond the Basics and WordPress for Business Bloggers, both by Packt Publishing.

Paul Thewlis has worked as a web communications professional in the public and private sectors. He is currently E-Communications Manager for a multinational transport company headquartered in the UK. He began his web career as a Technical Editor, working on web design books for a well-known publisher. He has extensive experience of many content management systems and blogging platforms. He is an expert in the use of social media within corporate communications and blogs about that subject, as well as WordPress and the Web in general at http://blog.paulthewlis.com. Paul is the author of WordPress For Business Bloggers, also by Packt Publishing

Table of Contents Preface Chapter 1: Introduction to WordPress What is a blog? Common terms Post Categories and tags Comments Permalinks Theme RSS Page What is WordPress? Why choose WordPress? A long time in refining Active in development Large community of contributors Amazingly extendable Detailed feature list Online WordPress resources WordPress news The Codex Theme and plugin directories WordPress.com Summary

1 7 7 8 8 8 8 9 9 9 10 10 10 10 10 11 11 11 12 12 12 13 14 14

Table of Contents

Chapter 2: Getting Started

15

Where to build your WordPress website Building on WordPress.com Installing WordPress manually Preparing the environment Downloading WordPress Uploading the files Installing WordPress

16 17 20 20 21 22 24

Upgrading WordPress from older installations The WP Admin panel Changing the password Changing general blog information Your first post Your first comment Retrieving a lost password Summary

Chapter 3: Blogging Your Heart Out Posting on your blog Adding a simple post Common post options

29 30 34 35 36 38 39 39

41 41 41 45

Categories and tags Adding an image to a post Using the Visual editor versus the HTML editor Drafts, timestamps, and managing posts

Advanced post options

45 48 51 52

54

Excerpt Trackbacks Discussion Custom Fields Password and private protection Post slug

54 55 56 57 58 59

Additional writing options

59

Press This Posting via email

59 61

Discussion on your blog—comments Adding a comment Discussion settings Submission, notification, and moderation settings When to moderate or blacklist a comment Avatar display settings

Moderating comments How to eliminate comment spam

61 62 62 63 64 66

67 69

Getting a WordPress.com API key Activating Akismet

70 70 [ ii ]

Table of Contents

Adding and managing categories Summary

72 73

Chapter 4: Pages, Images, Plugins, and More

75

Pages Adding a page Managing pages Links Adding a new link Managing links and categories Media library Adding an image gallery Choosing a post or page Uploading images Tweaking your gallery Adding plugins Finding your plugin Downloading the plugin Uploading and activating the plugin Configuring and/or implementing—if necessary Auto-installation Summary

75 76 78 79 79 82 83 85 86 86 89 92 92 92 93 95 97 97

Chapter 5: Choosing and Installing Themes

99

Finding themes WordPress Theme Directory Top WP themes Template Monster Finding more themes Factors to consider when choosing a theme Installing and changing themes What makes a theme? Downloading and extracting Uploading the theme Previewing and activating Using widgets Enabling basic widgets Multiple sidebars Adding new widgets Summary

100 100 103 104 105 105 105 106 106 107 109 111 111 115 116 116

[ iii ]

Table of Contents

Chapter 6: Developing Your Own Theme Setting up your design Designing your theme to be WordPress-friendly Converting your design to code Examining the HTML structure Examining the CSS

117 117 118 120 120 123

Converting your build into a theme Creating the theme folder Adding WordPress content The tag The header and footer The sidebar

128 128 133 133 134 136

Main column—the loop Creating templates within your theme Understanding the WordPress theme Breaking it up header.php footer.php sidebar.php Your four template files

138 142 143 143 143 144 145 145

Archive template Single template Page template Other WordPress templates Creating and using a custom template Making your theme widget-friendly Making sure your sidebar is one big

    tag Adding functions.php Adding conditional code to sidebar Adding some widgets Further widgetizing options Sharing your theme Summary

    Chapter 7: Feeds and Podcasting Feed basics Feed readers Your built-in WordPress feeds Adding feed links Feeds for the whole website Feeds for categories Feeds for post comments Tracking subscribers with FeedBurner [ iv ]

    147 149 151 152 153 156 156 157 158 158 159 160 160

    161 161 162 163 164 164 166 167 168

    Table of Contents Create FeedBurner account FeedSmith plugin

    168 169

    Aggregating feeds Displaying an external feed in the sidebar Displaying an external feed in a page Other useful plugins for syndication Podcasting How to podcast? Record yourself Make a post

    170 171 172 175 176 177 177 178

    Dedicated podcasting Podcasting plugins

    179 180

    PodPress Podcasting iPodCatter

    180 181 181

    Using archive.org to host audio files for free Summary

    Chapter 8: Developing Plugins and Widgets Plugins Plugin code requirements Basic plugin—adding link icons

    181 182

    183 183 184 184

    Naming and organizing the plugin files Writing the plugin's core functions Adding hooks to the plugin Trying out the plugin

    185 186 187 190

    Adding an admin page

    191

    Adding management page functions Modifying the regex() function Adding hooks Trying out the plugin

    192 194 195 195

    A plugin with DB access

    196

    Getting the plugin to talk to the database Adding management page functions Adding hooks Trying out the plugin

    197 198 198 199

    Widgets Top searched words widget

    201 201

    Naming the widget Initializing the widget Adding the widget's functions Adding the widget hook Trying out the widget

    202 202 203 206 206

    Combining the widget and the plugin Summary [v]

    208 208

    Table of Contents

    Chapter 9: Community Blogging

    209

    Concerns for a multiuser blog Users roles and abilities Administrator Editor Author Contributor Subscriber Managing users Useful plugins Role Manager Summary

    209 210 210 210 212 213 213 213 218 218 221

    Chapter 10: WordPress as a CMS Designing your theme Approach—the flexible WP Post Getting ready Using a simple version of the theme Inputting all content Product pages Main products page template Product category page template Single product page template Adding custom variables to the products Add a custom field to a post Displaying a custom field in the template

    223 223 225 225 225 226 229 230 232 234 236 237 238

    The home page Setting up the home page Inserting the news items Inserting the two blurbs

    239 240 241 243

    Using posts—again! Using the Text Snippets plugin

    243 244

    Customizing the news blog News category page Single news item page Summary

    246 246 248 250

    Chapter 11: Administrator's Reference System requirements The importance of backing up Easy, quick, frequent content backups Backing up everything Verifying your backups [ vi ]

    251 251 252 252 252 253

    Table of Contents

    A closer look at upgrading WordPress Backing up your WordPress files Deactivating all your plugins Downloading and extracting WordPress Deleting old files Uploading the new files Running the WordPress upgrade program Updating permalinks and .htaccess Installing updated plugins and themes Migrating or restoring a WordPress site Setting file permissions What are file permissions? How to set permissions Troubleshooting Troubleshooting during installation Headers already sent Page comes with only PHP code Cannot connect to MySQL database

    253 254 254 255 255 256 256 256 256 257 258 258 260 260 260 260 261 261

    Basic troubleshooting

    261

    Cannot see posts Making a blog totally private I don't receive the emailed passwords

    262 262 263

    Tips for theme development Template tags Class styles generated by WordPress Summary

    Index

    263 264 266 267

    269

    [ vii ]

    Preface Using WordPress, you can easily create dynamic blogs and websites with great content and many outstanding features. It is an ideal tool for developing blogs and though it is chiely used for blogging, it can also be used as a complete CMS for a regular website with very little effort. You can customize the features, incorporate your own design, and even write your own plugins with ease. Its versatility and ease of use has attracted a large, enthusiastic, and helpful community of users. Although it is easy to get started with WordPress, its full power is not immediately obvious. If you want to create a powerful, fully featured blog or non-blog website in no time, this book is for you. This book will help you learn everything WordPress has to offer from the ground up, so you can build your complete website. You will see many of WordPress's hidden powers that will help you build a fully functioning website.

    What this book covers Chapter 1—Introduction to WordPress introduces everything about blogging, including what a blog is, the common terms used in blogging and what they mean, what WordPress has to offer to a blogger, and why to choose it. Chapter 2—Getting Started explains the choices of where you can build your WordPress website, upgrading from an older version of WordPress, and getting familiar with the WordPress Administration Panel. Chapter 3—Blogging Your Heart Out covers the complete process of creating new posts for your blog, including applying categories and tags to your post, using the rich text editor, and controlling the timestamp. It also includes more advanced options such as including excerpt and trackbacks. This chapter also covers controlling commenting and discussion on your blog, as well as keeping out comment spam.

    Preface

    Chapter 4—Pages, Images, Plugins and More... explains that blog posts aren't the only content in your blog. You also can control pages of static information, upload and manage images on your site, keep a list of bookmarked links, and add plugins. Chapter 5—Choosing and Installing Themes covers how to ind and use existing themes from a variety of reliable websites, how to choose which theme is right for your website or blog, and the process of installing and using your new theme. This chapter also covers enabling and using widgets in your theme. Chapter 6—Developing Your Own Theme covers the process of creating your own theme from soup to nuts. This includes setting up your design to accommodate your blogging goals, converting your initial build into an authentic WordPress theme, creating templates within your theme to serve different purposes for your blog, making your theme widget-friendly, and sharing your theme with the WordPress community. Chapter 7—Feeds and Podcasting explains what feeds are and how to add them to your WordPress website, tracking subscribers to your blog, and aggregating feeds from other sources on your blog. This chapter also covers using your WordPress website to create a podcast. (It's easy!) Chapter 8—Developing Plugins and Widgets is for the more advanced user. This chapter shows you how to create plugins and widgets that will work with any installation of WordPress. It includes step-by-step instructions so you don't get lost along the way. Chapter 9—Community Blogging covers managing and handling a multiuser blog, including a detailed outline of the roles and capabilities included in WordPress. Chapter 10—WordPress as a CMS covers from start to inish how to use WordPress to create a non-blog website. This chapter includes explanations of designing your theme, setting it up, creating custom pages that display post content in non-blog ways, customizing the home page to contain dynamic content, and creating a news page. Chapter11—Administrator's Reference covers all of the basic things a WordPress administrator needs to know from system requirements to detailed step-by-step instructions on installing WordPress, moving your WordPress website from one place to another, backing up, common template tags, and basic troubleshooting.

    [2]

    Preface

    What you need for this book The minimum system requirement for WordPress is a web server with the following software installed: • •

    PHP Version 4.3 or greater MySQL Version 4.0 or greater

    Who this book is for This book is a guide to WordPress for both beginners and progressive learners. It's for people who are new to blogging and want to create their own blogs in a simple and straightforward manner, and it's also for those who want to learn how to customize and expand the capabilities of a WordPress website. It does not require any detailed knowledge of programming or web development, and any IT-conident user will be able to use the book to produce an impressive blog.

    Conventions In this book, you will ind a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning. Code words in text are shown as follows: "...you can add the above text anywhere in single.php so long as it is inside the if and while loops of the loop." A block of code will be set as follows: function modify_menu_for_supportedtypes() { add_management_page( 'Document Types', // Page 'Document Types', // Menu title 7, // What level of user __FILE__, //File to open 'supportedtypes_options' //Function to call ); }

    [3]

    Preface

    When we wish to draw your attention to a particular part of a code block, the relevant lines or items will be shown in bold: