Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

WordPress Development at PHP Quebec - Nov 2009


Published on

Is WordPress PHP? We will look at how WP uses PHP, discuss what Template tags are and how to extend them. We will also convert a basic PHP function into a WP Plugin.

Published in: Technology
  • Login to see the comments

WordPress Development at PHP Quebec - Nov 2009

  1. 1. Development PHP Quebec – November 09 Gathering
  2. 2. full-time now!
  3. 3. What is ? We’ll skip the basics and head straight to the code…. … if you’re interested you can check out Some of my other presentations later
  4. 4. Getting started
  5. 5. What you need PHP version 4.3 or greater MySQL version 4.0 or greater Creativity and Passion
  6. 6. Theming <ul><li>Create or download a Photoshop design. Create a static HTML+CSS template of each page . </li></ul>
  7. 7. Theming <ul><li>Why Create a Static HTML File First? </li></ul><ul><li>Mainly because it will make the development process a lot </li></ul><ul><li>easier. I usually create a HTML file for every template that I </li></ul><ul><li>need, test it across all browsers, validate both HTML and CSS </li></ul><ul><li>markups, then all I have to do is cut & paste the WordPress </li></ul><ul><li>code. By doing so, I don’t have to worry about HTML or CSS </li></ul><ul><li>bugs during my theme making process. </li></ul>
  8. 8. Yes, I know, this is PHP Quebec… Ok, back to the code.
  9. 9. Templating How it all works If you go the default theme folder ( wp-content/themes/default ), you will see many PHP files (these are template files) and one style.css file. When you are viewing the front page, WordPress actually uses several template files to generate the page ( index.php << header.php , sidebar.php , and footer.php ).
  10. 10. Templating The front page
  11. 11. Templating Splitting the file
  12. 12. Templating Let’s start with the Template System Template Tags Conditional Tags PHP Function Calls
  13. 13. Templating <?php // syntax #1: curly braces if ( condition to check ){ // code to execute if the condition is true } // syntax #2: colon and endif if ( condition to check ): // code to execute if the condition is true endif; ?> <?php if ( is_home() ): ?> <h3>Main Page</h3> <?php elseif( is_archive() ): ?> <h3>Archives Page</h3> <?php else: ?> <h3>Welcome to my blog!!</h3> <?php endif; ?> Standard PHP WordPress
  14. 14. Templating Template Tags Include tags <ul><li>get_header </li></ul><ul><li>get_sidebar </li></ul><ul><li>get_search_form </li></ul><ul><li>comments_template </li></ul><ul><li>get_footer </li></ul>Blog info tags <ul><li>bloginfo </li></ul><ul><li>bloginfo_rss </li></ul><ul><li>get_bloginfo </li></ul><ul><li>get_bloginfo_rss </li></ul>Lists & Dropdown tags <ul><li>wp_list_authors </li></ul><ul><li>wp_list_categories </li></ul><ul><li>wp_list_pages </li></ul><ul><li>wp_list_bookmarks </li></ul><ul><li>wp_list_comments </li></ul><ul><li>wp_get_archives </li></ul><ul><li>wp_page_menu </li></ul><ul><li>wp_dropdown_pages </li></ul><ul><li>wp_dropdown_categories </li></ul><ul><li>wp_dropdown_users </li></ul>Login/Logout tags <ul><li>is_user_logged_in </li></ul><ul><li>wp_login_url </li></ul><ul><li>wp_logout_url </li></ul><ul><li>wp_lostpassword_url </li></ul><ul><li>wp_registration_url </li></ul><ul><li>wp_logout </li></ul><ul><li>wp_loginout </li></ul><ul><li>wp_register </li></ul>Post tags <ul><li>the_ID </li></ul><ul><li>the_title </li></ul><ul><li>the_title_rss </li></ul><ul><li>the_title_attribute </li></ul><ul><li>single_post_title </li></ul><ul><li>the_content </li></ul><ul><li>the_content_rss </li></ul><ul><li>the_excerpt </li></ul><ul><li>the_excerpt_rss </li></ul><ul><li>wp_link_pages </li></ul><ul><li>posts_nav_link </li></ul><ul><li>next_post_link </li></ul><ul><li>next_posts_link </li></ul><ul><li>previous_post_link </li></ul><ul><li>previous_posts_link </li></ul><ul><li>next_image_link </li></ul><ul><li>previous_image_link </li></ul><ul><li>sticky_class </li></ul><ul><li>the_category </li></ul><ul><li>the_category_rss </li></ul><ul><li>the_tags </li></ul><ul><li>the_meta </li></ul>Comment tags <ul><li>wp_list_comments </li></ul><ul><li>comments_number </li></ul><ul><li>comments_link </li></ul><ul><li>comments_rss_link </li></ul><ul><li>comments_popup_script </li></ul><ul><li>comments_popup_link </li></ul><ul><li>comment_ID </li></ul><ul><li>comment_id_fields </li></ul><ul><li>comment_author </li></ul><ul><li>comment_author_link </li></ul><ul><li>comment_author_email </li></ul><ul><li>comment_author_email_link </li></ul><ul><li>comment_author_url </li></ul><ul><li>comment_author_url_link </li></ul><ul><li>comment_author_IP </li></ul><ul><li>comment_type </li></ul><ul><li>comment_text </li></ul><ul><li>comment_excerpt </li></ul><ul><li>comment_date </li></ul><ul><li>comment_time </li></ul><ul><li>comment_form_title </li></ul><ul><li>comment_author_rss </li></ul><ul><li>comment_text_rss </li></ul><ul><li>get_avatar </li></ul><ul><li>permalink_comments_rss </li></ul><ul><li>comment_reply_link </li></ul><ul><li>cancel_comment_reply_link </li></ul><ul><li>previous_comments_link </li></ul><ul><li>next_comments_link </li></ul><ul><li>paginate_comments_links </li></ul>
  15. 15. Templating Template Tags Category tags <ul><li>the_category </li></ul><ul><li>the_category_rss </li></ul><ul><li>single_cat_title </li></ul><ul><li>category_description </li></ul><ul><li>wp_dropdown_categories </li></ul><ul><li>wp_list_categories </li></ul>Tag tags <ul><li>the_tags </li></ul><ul><li>tag_description </li></ul><ul><li>single_tag_title </li></ul><ul><li>wp_tag_cloud </li></ul><ul><li>wp_generate_tag_cloud </li></ul>Author tags <ul><li>the_author </li></ul><ul><li>the_author_link </li></ul><ul><li>the_author_posts </li></ul><ul><li>the_author_posts_link </li></ul><ul><li>the_author_meta </li></ul><ul><li>wp_list_authors </li></ul><ul><li>wp_dropdown_users </li></ul>Date and Time tags <ul><li>the_time </li></ul><ul><li>the_date </li></ul><ul><li>the_date_xml </li></ul><ul><li>the_modified_time </li></ul><ul><li>the_modified_date </li></ul><ul><li>the_modified_author </li></ul><ul><li>single_month_title </li></ul>Edit Link tags <ul><li>edit_post_link </li></ul><ul><li>edit_comment_link </li></ul><ul><li>edit_tag_link </li></ul><ul><li>edit_bookmark_link </li></ul>Permalink tags <ul><li>permalink_anchor </li></ul><ul><li>get_permalink </li></ul><ul><li>the_permalink </li></ul><ul><li>permalink_single_rss </li></ul>Links Manager tags <ul><li>wp_list_bookmarks </li></ul><ul><li>get_bookmarks </li></ul><ul><li>get_bookmark </li></ul><ul><li>get_bookmark_field </li></ul>Trackback tags <ul><li>trackback_url </li></ul><ul><li>trackback_rdf </li></ul>Title tags <ul><li>wp_title </li></ul><ul><li>single_post_title </li></ul><ul><li>single_cat_title </li></ul><ul><li>single_tag_title </li></ul><ul><li>single_month_title </li></ul><ul><li>the_search_query </li></ul>Query tags <ul><li>get_posts </li></ul><ul><li>query_posts </li></ul>
  16. 16. Templating The Loop The Loop is used to display posts and it also lets you control what to display. Basically, The Loop checks if there are posts in your blog, while there are posts, display it, if no post found, say &quot;Not Found&quot;.
  17. 17. Templating A complete template In this example we are using some standard Template Tags to display the title of the post the_title() and we are linking it using the_permalink() . We call use the_date() and display the_content() . Finally for fun we call link_pages() .
  18. 18. Templating Playing with the code <?php wp_list_categories('show_count=1&title_li=<h2>Categories</h2>'); ?> Most blogs display categories somewhere, usually the side bar. The easiest way to do this is with the wp_list_categories() Template Tag.
  19. 19. Templating Playing with the code <ul> <li id=&quot;categories&quot;> <?php wp_dropdown_categories('title_li=&hierarchical=0&show_count=1&child_of=9'); ?> <script type=&quot;text/javascript&quot;> <!-- var dropdown = document.getElementById(&quot;cat&quot;); function onCatChange() { if ( dropdown.options[dropdown.selectedIndex].value > 0 ) { location.href = &quot;<?php echo get_option('home'); ?>/?cat=&quot;+dropdown.options[dropdown.selectedIndex].value; } } dropdown.onchange = onCatChange; --> </script> </li> </ul> What if I wanted to display specific categories and have them in a dropdown box? * See the full tutorial at
  20. 20. Templating Playing with the code <?php if(is_page(&quot;landing&quot;)) : ?> <h5 class=&quot;tagline&quot;> Hello! I'm Brendan Sera-Shriar A.K.A. <span class=&quot;blue&quot;>digibomb</span>, a freelance web designer from Montreal, Canada. </h5> <?php elseif(is_page(&quot;work&quot;) || is_page(&quot;branding&quot;) || is_page(&quot;other-projects&quot;) || is_page(&quot;client-list&quot;)) : ?> <h5 class=&quot;tagline&quot;> I don't just build <span class=&quot;blue&quot;>websites</span> I build <span class=&quot;blue&quot;>communities</span>! </h5> <?php endif; ?> What if I wanted to display different taglines on each page? * See it in action at
  21. 21. Theming <ul><li>Loop Resources </li></ul><ul><li>The Loop in Action </li></ul><ul><li>Template Tags </li></ul><ul><li>Using the Loop in Template Files </li></ul><ul><li>Matt Read Loop Article </li></ul><ul><li>MaxPower Dynamic Sticky Tutorial </li></ul><ul><li>IfElse Query_post Redux </li></ul><ul><li>1001 WordPression Loops </li></ul><ul><li>Global Variables and the WordPress Loop </li></ul><ul><li>WordPress Triple Loop Tutorial </li></ul><ul><li>Multiple Loops with Multiple Columns </li></ul><ul><li>WordPress - modified, dependent and extra Loops </li></ul><ul><li>Super Loop: Exclude Categories and Limit Number of Posts </li></ul><ul><li>Easily Adaptable WordPress Loop Templates: Basic Loops, Mullet Loops, and More </li></ul>* See my presentation on WordPress Theme Design
  22. 22. Writing Plugins “ Plug-ins can extend WordPress to do almost anything you can imagine.” * See my presentation on WordPress Plugin Development and Making the Most of Plugins <ul><li>Conventions </li></ul><ul><li>For each new plug-in I create a folder in the /wp-content/plugins/ pluginname / and then in that folder I create the main plug-in file with the same name as the folder + .php so the plug-in file is /wp-content/plugins/pluginname/ pluginname.php . </li></ul><ul><li>I usually start by converting a php function that I have built or found and convert it by adding the necessary WP code. </li></ul><ul><li>Main Elements </li></ul><ul><ul><li>Header Stuff (Name, version, etc…) </li></ul></ul><ul><ul><li>Add Menu Option </li></ul></ul><ul><ul><li>Set Up the Options Page </li></ul></ul><ul><ul><li>Register the Activation and Deactivation Hooks </li></ul></ul><ul><ul><li>The Main Function </li></ul></ul><ul><ul><li>*Always make sure to include a readme.txt with your plug-in package. </li></ul></ul>
  23. 23. Writing Plugins The PHP Function function randomflashloader(){ srand(microtime() *1000000); $num= rand (0,3); $project = array(); $project[0] = &quot;;; $project[1] = &quot;;; $project[2] = &quot;;; $project[3] = &quot;;; $frame.= &quot;<center>&quot;; $frame.= &quot;<embed src=&quot;$project[$num]&quot; &quot;; $frame.= &quot;width =&quot;300&quot; height=&quot;250&quot; bgcolor=&quot;#000000&quot; border=&quot;0&quot;/>&quot;; $frame.= &quot;</a>&quot;; echo($frame); }
  24. 24. Writing Plugins The WordPress Plugin Hooks //Check install directory $rfl_directory = 'wp-content/plugins/randomflashloader/'; if ((!strstr(dirname(__FILE__).'/', $rfl_directory)) && (!strstr(dirname(__FILE__).'apos;, str_replace('/', 'apos;, $rfl_directory)))) { trigger_error(sprintf(__('<b>Random Flash Loader is not installed in the proper directory!</b><br />It won't work until installed in <b>%s</b><br />', 'randomflashloader'), $rfl_directory), E_USER_ERROR); return; } // Add the Options Menu add_action('admin_menu', 'random_flash_loader_options_setup'); // Setup the Options Page function random_flash_loader_options_setup() { global $random_flash_loader_data; add_options_page($random_flash_loader_data['Name'], 'RandomFlashLoader', 8, basename(__FILE__), 'random_flash_loader_page'); } // Activation and Deactivation Hooks register_deactivation_hook(__FILE__, 'random_flash_loader_deactivate'); register_activation_hook(__FILE__, 'random_flash_loader_activate'); * Download plugin here
  25. 25. Essential Plugins <ul><li>Ad Rotator - </li></ul><ul><li>Advanced Random Post - </li></ul><ul><li>AFD Admin Theme - </li></ul><ul><li>Akismet - </li></ul><ul><li>All in One SEO Pack - </li></ul><ul><li>Article Templates - </li></ul><ul><li>Audio player - </li></ul><ul><li>Blogroll Page - </li></ul><ul><li>Different Posts Per Page - </li></ul><ul><li>Disable WordPress Core Update - </li></ul><ul><li>Executable PHP widget - </li></ul><ul><li>Kimili Flash Embed - </li></ul><ul><li>Lightbox 2 - </li></ul><ul><li>Maintenance Mode - </li></ul><ul><li>myStatus - </li></ul><ul><li>NextGEN Gallery - </li></ul>
  26. 26. Essential Plugins <ul><li>p2pConverter - </li></ul><ul><li>Post2pdf - </li></ul><ul><li>PXS Mail Form - </li></ul><ul><li>QuickTime Embed - </li></ul><ul><li>Random Featured Post - </li></ul><ul><li>Riffly Video/Audio Comments - </li></ul><ul><li>Role Manager - er </li></ul><ul><li>Widget Logic - </li></ul><ul><li>WordPress Database Backup - </li></ul><ul><li>Wordpress Download Monitor - </li></ul><ul><li>WP Cache - </li></ul><ul><li>WP e-commerce - </li></ul><ul><li>WP Polls - </li></ul><ul><li>WP SpamFree - </li></ul><ul><li>WP-Sticky - </li></ul><ul><li>WP Shopping Cart - </li></ul>
  27. 27. Resources <ul><li>Documentation </li></ul><ul><li>Codex - </li></ul><ul><li>Site Architecture – </li></ul><ul><li>Template Hierarchy - </li></ul><ul><li>WordPress Plugins - </li></ul><ul><li>WordPress Theme Hacks - </li></ul><ul><li>Tutorials </li></ul><ul><li>Web Designer Wall - </li></ul><ul><li>Six Revisions – </li></ul><ul><li>NetTuts - </li></ul><ul><li>Tutorial 9 – </li></ul><ul><li>WPTopics - </li></ul><ul><li>WordPress Tutorials - </li></ul><ul><li>Themes </li></ul><ul><li>Function - </li></ul><ul><li>WPSnap - </li></ul><ul><li>WooThemes – </li></ul><ul><li>StyleShout - </li></ul>
  28. 28. Resources <ul><li>Plugins </li></ul><ul><li>Simplified AJAX For WordPress Plugin Developers using Jquery </li></ul><ul><li>“Desenvolvendo Plugins para WordPress” by Rafael Dohms (in Brazilian Portuguese) </li></ul><ul><li>12 part “How to Write a Wordpress Plugin” at by Ronald Huereca ( PDF ) </li></ul><ul><li>How to create WordPress Plugin from a scratch </li></ul><ul><li>Using AJAX with your WordPress Plugin , also at </li></ul><ul><li>How to Write a Simple WordPress Plugin at ATD </li></ul><ul><li>Other </li></ul><ul><li>BuddyPress - </li></ul><ul><li>WordPress MU – </li></ul><ul><li>WP e-Commerce – </li></ul><ul><li>Thematic – </li></ul><ul><li>WpTouch – </li></ul><ul><li>WordPress Mobile – </li></ul>
  29. 29. <ul><li>Where to find me… </li></ul><ul><li>Thank You </li></ul><ul><li> </li></ul><ul><li> </li></ul><ul><li>[email_address] </li></ul><ul><li> </li></ul>