Tài liệu về học lập trình web ,JavaScript,wordpress cho tất cả mọi người.
Trang 2WordPress Theme Development Beginner's Guide Third Edition
Table of Contents
WordPress Theme DevelopmentBeginner's GuideThird Edition
Credits
About the Authors
About the Reviewers
Trang 3Preface
What this book covers
Who this book is for
Conventions
Time for action – heading
What just happened?
Pop quiz – heading
Have a go hero – heading
Trang 4Does a WordPress site have to be ablog ?
Pick a theme or design of your ownDrawbacks of using an off-the-shelftheme
What about premium themes andframeworks?
What exactly is a premium themeWhat is a framework theme
Core technology you shouldunderstand
WordPress
CSS
HTML
PHP
Other helpful technologies
Tools of the trade
HTML editor
Trang 5Graphics editor
Web browser
Basics of a WordPress theme
The template hierarchy
The Loop
Template tags and API hooks
Our development strategies
Fonts and typefaces
A CSS strategy – font sizing withems
A CSS strategy – working with aCSS framework
Trang 6Choosing a hosting provider
Rolling out WordPress
Summary
2 Preparing a Design for OurWordPress Theme
Getting ready to design
Designing in the browser
Starting our design
Planning and sketching our designTime for action – planning ourdesign
What just happened?
Creating your design – from thesketch to the screen
Time for action – creating our staticHTML file
What just happened?
The semantic body
Trang 7Time for action – adding in basicHTML structure
What just happened?
Time for action – adding in thesemantic structure
What just happened?
Attaching our CSS stylesheet
Time for action – creating andincluding a style.css shell into yourindex.php page
What just happened?
Prepping for responsiveness –viewport and apple-mobile meta tags
Time for action – adding in theviewport and apple-mobile meta tags
What just happened?
Adding in content
Starting with the text
Trang 8Time for action – adding sampletext to our semantic sections
What just happened?
Styling our fonts
Styling font families
Time for Action – assigning yourfont families
What just happened?
@font-face techniques
Styling font sizes
Time for action – sizing your fontsWhat just happened?
Time for action – handling searchengine bots/screen reader text
What just happened?
Setting up our layout with CSSTime for action – referencing ourlayout core to set up our positions
Trang 9What just happened?
Time for Action – Adding ourmedia queries
What just happened?
Setting up the desktop view
Time for action – standard settingsWhat just happened?
Time for action – checking in onlarger desktops
What just happened?
Time for action – making suresmaller screens are handled
What just happened?
Setting up the tablet view
Time for action – adjusting thestandard layout for tablets
What just happened?
Setting up the small screen view
Trang 10Time for action – setting up oursmall screen layout
What just happened?
Adding design treatments
Time for action – setting up ourgraphic treatments in the stylesheet
What just happened?
Adding graphics and backgroundimages
Setting up our background images
in our stylesheet
Time for action – addingbackground images to our design
What just happened?
Time for action – addingbackground image styling to the mediaqueries
What just happened?
Trang 11Don't forget the favicon and touchicon
Adding a favicon
Time for action – adding thefavicon you just created
What just happened?
Have a go hero – making yourfavicon high-resolution
Touch icons
Time for action – adding a touchicon
What just happened?
Pop quiz – questions about themedesign
Summary
3 Coding it Up
WordPress theme basics
The Template hierarchy
Trang 12Why the Template hierarchy worksthe way it does
The WordPress theme API
Setting up your WordPressworkflow
Building your WordPress themetemplate files
Starting with a blank slate
Creating a new theme directoryTime for action – setting up ourtheme directory
What just happened?
Including WordPress content
Time for action – getting your CSSstyles to show up
What just happened?
Understanding WordPress templatetags and hooks
Trang 13Template tags
Hooks
Looping it! – The WordPress LoopThe Loop in a nutshell – how itworks
Time for action – creating a basicLoop
What just happened?
Time for action – adding contentWhat just happened?
Time for action – adding metadata,the timestamp, and author template tags
What just happened?
Keeping up-to-date withWordPress
Adding to the Loop
Time for action – displaying thenumber of comments
Trang 14What just happened?
Time for action – adding inautogenerated classes
What just happened?
One last look – our full loop
Breaking the code up into templatefiles
Including everyone
Creating a header file
Time for action – creating theheader.php file
What just happened?
Separating out our sidebar
Time for action – creating thesidebar.php file
What just happened?
Finishing off with the footer
Time for action – creating the
Trang 15footer.php template file
What just happened
Time for action – don't forget theplugin hooks
What just happened
Creating a template file for staticpages
Time for action – creating a custompage.php template file
What just happened?
Pop Quiz – questions aboutWordPress theme structure
Trang 16Time for action – adding the sitetitle and description to your theme
What just happened?
Pretty permalinks
Time for action – setting up prettypermalinks
What just happened?
Permalinks – a quick guide
Menus
Registering navigation menus
Time for action – registering anavigation menu
What just happened?
Time for action – adding menus toour theme's header.php file
What just happened?
Setting up our menu
Defining our Reading settings
Trang 17Time for action – defining Readingsettings
What just happened?
Creating a menu
Time for action – creating a newWordPress menu
What just happened?
Adding pages and other content toour menu
Time for action – adding pages to amenu
What just happened?
Time for action – adding a customlink to the menu
What just happened?
Time for action – adding a categorylink to the menu
What just happened?
Trang 18The WordPress Menus admin – thepossibilities
What just happened?
Time for action – adding widgetareas to sidebar.php
What just happened?
Time for action –adding widgetareas to footer.php
What just happened?
Widget areas – not just for thesidebar and footer
Adding widgets in the Widgetsadmin screen
Trang 19What widgets will we need
Time for action – adding sidebarwidgets
What just happened?
Time for action – adding footerwidgets
What just happened?
Featured images
Time for action – adding featuredimages to our theme
What just happened?
Time for action – adding featuredimages to the site
What just happened?
Time for action – displayingfeatured images differently in differenttemplate files
What just happened?
Trang 20Parent and child themes
Pop Quiz – understanding advancedtheme features
Summary
5 Debugging and Validation
Debugging and validationworkflow
Browser tools for debugging
Trang 21Time for action – finding and fixingerrors
What just happened?
Time for action – fixing our codeWhat just happened?
Validating CSS
Time for action – using the W3C'sCSS validator
What just happened?
Testing on multiple browsers andplatforms
Which browsers to support
Approaches to browser supportGraceful degradation
Progressive enhancement
Troubleshooting basics
PHP template tags
CSS quick fixes
Trang 22Fixing CSS across browsers
Common browser problems
Adding an IE-specific stylesheetTime for action – setting up analternative IE stylesheet
What just happened?
Checking your work in InternetExplorer
Time for action – testing our themewith BrowserLab
What just happened?
Testing on mobile devices
Summary
6 Your Theme in Action
The WordPress Theme Reviewguidelines
The theme preview screenshotTime for action – snagging a
Trang 23thumbnail of your theme
What just happened?
Packaging your theme up
Tidying up your theme
Time for action – tidying up yourtheme
What just happened?
Describing your theme in thestylesheet
Time for action – describing yourtheme
What just happened?
Your theme's license
Time for action – adding licenseinformation to our theme
What just happened?
Zipping up your theme
Time for action – zipping up your
Trang 24What just happened?
One last test
Time for action – testing the themeWhat just happened?
Have a go hero – using theWordPress Theme Unit Test
Pop Quiz - questions on packaging
up your theme
Summary
7 Tips and tricks
Adding more template files to yourtheme
A search.php file for search resultsTime for action – creating asearch.php template file
What just happened?
Creating a custom page template
Trang 25Time for action – creating a custompage template
What just happened?
Time for action – assigning acustom page template to a page in oursite
What just happened?
Have a go hero – styling the custompage template
Working with conditional tags
Conditional tags' syntax
Incorporating conditional tags inour theme
Using conditional tags to hide thehome page's title
Time for action – using CSS to hideour home page's title
What just happened?
Trang 26Time for action – using aconditional tag to hide our home page'stitle
What just happened?
Have a go hero – other ways ofshowing conditional content
The Theme Customizer
Time for action - adding the ThemeCustomizer to our theme
What just happened?
Time for action – adding somemore options to the Theme Customizer
What just happened?
Time for action – ensuring ThemeCustomizer changes are carried through
to the CSS
What just happened?
Theme Customizer – the
Trang 27Optimizing images and links withalt and title attributes
Time for action – optimizing a logofor SEO
What just happened?
Using optimized meta tags – pagetitles and descriptions
Trang 28Time for action – optimizing ourtheme's page meta tags
What just happened?
Summary
Pop Quiz Answers
Chapter 2, Preparing a Design forOur WordPress Theme
Pop quiz – questions about themedesign
Trang 30preparation of this book to ensure theaccuracy of the information presented.However, the information contained inthis book is sold without warranty,either express or implied Neither theauthors, nor Packt Publishing, and itsdealers and distributors will be heldliable for any damages caused or alleged
to be caused directly or indirectly bythis book
Packt Publishing has endeavored toprovide trademark information about all
of the companies and productsmentioned in this book by theappropriate use of capitals However,Packt Publishing cannot guarantee theaccuracy of this information
First published: May 2008
Trang 31Second edition: November 2009Third edition: March 2013
Production Reference: 1130313Published by Packt Publishing Ltd.Livery Place
Trang 33Conidon Miranda
Cover Work
Conidon Miranda
About the Authors
Rachel McCollin is a web designer
and developer specializing inWordPress development Shediscovered WordPress when looking for
a CMS that made the transition fromstatic HTML relatively straightforward,and hasn't looked back since
Rachel runs Compass Design, aweb design agency based inBirmingham, England, but with clientsacross the UK and internationally Theagency was established in 2010 andquickly began specializing in building
Trang 34WordPress themes and sites, with a slanttowards responsive themes The agencynow has a great team of designers anddevelopers, including some WordPressspecialists.
I've learned most of what I knowabout WordPress from the web designcommunity I'd like to thank all of theWordPress developers and designerswho have inspired and taught me, inparticular the organizing team forWordCampUK, without whom I neverwould have even thought of writingabout WordPress
A number of friends and colleagueshave provided support with my writingand have helped me develop my
Trang 35WordPress skills, as well as givinguseful feedback for this book Theyinclude Mark Wilkinson, Jon Hickman,Scott Evans, Tammie Lister, NiviMorales, and Jonny Allbut Rob Ashton
at Emphasis has set me straight ongrammar when I've needed it KartikeyPandey at Packt Publishing showed theconfidence in my work to ask me to take
on my second project for PacktPublishing—I'm grateful for this, and forhis positivity and encouragement Mostimportantly, my husband Pete hasencouraged and supported me all along,and has spent many Saturdaysentertaining our two boys, so that I couldget on with the task of writing
Trang 36Tessa Blakeley Silver's
background is in print design andtraditional illustration She evolved overthe years into web and multi-mediadevelopment, where she focuses onusability and interface design Prior tostarting her consulting and developmentcompany, hyper3media (pronounced
http://hyper3media.com, Tessa was the
VP of Interactive Technologies ateHigherEducation, an online learningand technology company developingcompelling multimedia simulations,interactions, and games that met onlineeducational requirements like 508,AICC, and SCORM She has also
Trang 37worked as a consultant and freelancerfor J Walter Thompson and TheDiamond Trading Company (formerlyknown as DeBeers) and was a DesignSpecialist and Senior Associate forPricewaterhouseCoopers' East RegionMarketing department Tessa authorsseveral design and web technology
blogs Joomla! Template Design is her
first book
About the Reviewers
Srikanth is a web developer,
passionate about developing andoptimizing websites for better userexperience, performance, and searchengine visibility He is particularlyinterested in adapting content
Trang 38management systems for developingstructured and scalable websites.
Check out his portfolio athttp://srikanth.me
Steve Graham is a programmer
turned web-developer with years ofexperience, building large-scaledatabases to run manufacturing controland international banking systems Hisexperience at the back-end of the ITindustry has given him a keenunderstanding of the needs of the finalusers and it's this knowledge andexpertise that he brings to his work withWordPress As one half of the InternetMentor team (www.internet-mentor.co.uk) his passion is developingthemes that help to solve some of the
Trang 39most frustrating aspects of marketingonline Focusing on the key businessobjectives, his aim for all clients is toensure that they derive measurable andsustainable direct results that drivebusiness growth.
He spends much of his timeworking on theme development for nicheareas Rather than producing themes thatare so generic that the only real reasonthey appeal to a market is the name ofthe theme or the type of backgroundimage, these themes are designed toprovide real solutions and are createdwith a a knowledge and thoroughunderstanding of the challenges their endusers have to overcome
Steve is also a passionate speaker
Trang 40and networking skills coach, who is able
to bring a different perspective to themessages his clients are delivering in theonline world Relationship marketing iskey to success in the 21st century andhaving an understanding of how effectiveboth the on and off-line networks can be,
is essential to the success of almost allbusinesses
Did you know that Packt offers