Web Designers Meetup Cairo - 17th November 2012               Dig Deeper into               WordPress(C) 2012 Mohamed Mosa...
Why?Have you ever thought                      over 70-million websites out                        there are using WordPre...
flexi                             WordPress main feature isbility(C) 2012 Mohamed Mosaad. All Copyrights Reserved
Custom Post TypesCustom Meta BoxesCustom TaxonomiesAdvanced QueriesCustom Admin Panels/OptionsPlugin APIHooks, Actions and...
Custom Post Types           <?php register_post_type( $post_type,                        $args ); ?>	  	  $labels	  =	  ar...
Custom Meta Boxes    <?php add_meta_box( $id, $title, $callback,         $post_type, $context, $priority,              $ca...
Custom Meta Boxes (cont.)/*	  When	  the	  post	  is	  saved,	  saves	  our	  custom	  data	  */function	  myplugin_save_p...
Custom Taxonomies          <?php register_taxonomy($taxonomy,                $object_type, $args); ?>	  	  //	  Add	  new	...
Custom Taxonomies  <?php register_taxonomy($taxonomy,        $object_type, $args); ?>	  	  //	  Add	  new	  taxonomy,	  NO...
Advanced Queries<?php $the_query = new WP_Query( $args ); ?>WP_Query is a class defined in wp-includes/query.php that deal...
Advanced Queries (cont.)<?php $the_query = new WP_Query( $args ); ?>Class Methods                                         ...
Advanced Queries (cont.)   <?php $wpdb->get_results( MYSQLQuery ); ?>The $wpdb object can be used to read data from any ta...
Scan My vCard   wpmonkeys.com   fb.com/banhawi   be.net/banhawi   eg.linkedin.com/in/banhawi   twitter.com/banhawi   www. ...
Thank You§   Mohamed Mosaad    UX Evangelist & WordPress Expert    wpmonkeys.com
Dig Deeper into WordPress - WD Meetup Cairo
Dig Deeper into WordPress - WD Meetup Cairo
Upcoming SlideShare
Loading in …5
×

Dig Deeper into WordPress - WD Meetup Cairo

1,349 views

Published on

Dig deeper into WordPress is a presentation made for Web Designers Meetup in Cairo taken place on 17th Dec 2012.

Signup at WPMonkeys.com to get notified when awesome new WordPress related content is published.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,349
On SlideShare
0
From Embeds
0
Number of Embeds
119
Actions
Shares
0
Downloads
4
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Dig Deeper into WordPress - WD Meetup Cairo

  1. 1. Web Designers Meetup Cairo - 17th November 2012 Dig Deeper into WordPress(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  2. 2. Why?Have you ever thought over 70-million websites out there are using WordPress(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  3. 3. flexi WordPress main feature isbility(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  4. 4. Custom Post TypesCustom Meta BoxesCustom TaxonomiesAdvanced QueriesCustom Admin Panels/OptionsPlugin APIHooks, Actions and FiltersCustomizable Advanced User Capabilities+ many more....(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  5. 5. Custom Post Types <?php register_post_type( $post_type, $args ); ?>    $labels  =  array(        name  =>  _x(Books,  post  type  general  name,  your_text_domain),        singular_name  =>  _x(Book,  post  type  singular  name,  your_text_domain),        add_new  =>  _x(Add  New,  book,  your_text_domain),        add_new_item  =>  __(Add  New  Book,  your_text_domain),        edit_item  =>  __(Edit  Book,  your_text_domain),        new_item  =>  __(New  Book,  your_text_domain),        all_items  =>  __(All  Books,  your_text_domain),        view_item  =>  __(View  Book,  your_text_domain),        search_items  =>  __(Search  Books,  your_text_domain),        not_found  =>    __(No  books  found,  your_text_domain),        not_found_in_trash  =>  __(No  books  found  in  Trash,  your_text_domain),          parent_item_colon  =>  ,        menu_name  =>  __(Books,  your_text_domain)    );    $args  =  array(        labels  =>  $labels,        public  =>  true,        publicly_queryable  =>  true,        show_ui  =>  true,          show_in_menu  =>  true,          query_var  =>  true,        rewrite  =>  array(  slug  =>  _x(  book,  URL  slug,  your_text_domain  )  ),        capability_type  =>  post,        has_archive  =>  true,          hierarchical  =>  false,        menu_position  =>  null,        supports  =>  array(  title,  editor,  author,  thumbnail,  excerpt,  comments  )    );      register_post_type(book,  $args);http://codex.wordpress.org/Function_Reference/register_post_type(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  6. 6. Custom Meta Boxes <?php add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args ); ?><?php/*  Define  the  custom  box  */add_action(  add_meta_boxes,  myplugin_add_custom_box  );/*  Do  something  with  the  data  entered  */add_action(  save_post,  myplugin_save_postdata  );/*  Adds  a  box  to  the  main  column  on  the  Post  and  Page  edit  screens  */function  myplugin_add_custom_box()  {        add_meta_box(                  myplugin_sectionid,                __(  My  Post  Section  Title,  myplugin_textdomain  ),                myplugin_inner_custom_box,                post          );}/*  Prints  the  box  content  */function  myplugin_inner_custom_box(  $post  )  {    //  Use  nonce  for  verification    wp_nonce_field(  plugin_basename(  __FILE__  ),  myplugin_noncename  );    //  The  actual  fields  for  data  entry    echo  <label  for="myplugin_new_field">;              _e("Description  for  this  field",  myplugin_textdomain  );    echo  </label>  ;    echo  <input  type="text"  id="myplugin_new_field"  name="myplugin_new_field"  value="whatever"  size="25"  />;}..........http://codex.wordpress.org/Function_Reference/add_meta_box(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  7. 7. Custom Meta Boxes (cont.)/*  When  the  post  is  saved,  saves  our  custom  data  */function  myplugin_save_postdata(  $post_id  )  {    //  verify  if  this  is  an  auto  save  routine.      //  If  it  is  our  form  has  not  been  submitted,  so  we  dont  want  to  do  anything    if  (  defined(  DOING_AUTOSAVE  )  &&  DOING_AUTOSAVE  )              return;    if  (  !wp_verify_nonce(  $_POST[myplugin_noncename],  plugin_basename(  __FILE__  )  )  )            return;        //if  saving  in  a  custom  table,  get  post_ID    $post_ID  =  $_POST[post_ID];    $mydata  =  $_POST[myplugin_new_field];    //  Do  something  with  $mydata      //  probably  using  add_post_meta(),  update_post_meta(),  or      //  a  custom  table  (see  Further  Reading  section  below)}?>(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  8. 8. Custom Taxonomies <?php register_taxonomy($taxonomy, $object_type, $args); ?>    //  Add  new  taxonomy,  make  it  hierarchical  (like  categories)    $labels  =  array(        name  =>  _x(  Genres,  taxonomy  general  name  ),        singular_name  =>  _x(  Genre,  taxonomy  singular  name  ),        search_items  =>    __(  Search  Genres  ),        all_items  =>  __(  All  Genres  ),        parent_item  =>  __(  Parent  Genre  ),        parent_item_colon  =>  __(  Parent  Genre:  ),        edit_item  =>  __(  Edit  Genre  ),          update_item  =>  __(  Update  Genre  ),        add_new_item  =>  __(  Add  New  Genre  ),        new_item_name  =>  __(  New  Genre  Name  ),        menu_name  =>  __(  Genre  ),    );        register_taxonomy(genre,array(book),  array(        hierarchical  =>  true,        labels  =>  $labels,        show_ui  =>  true,        query_var  =>  true,        rewrite  =>  array(  slug  =>  genre  ),    ));http://codex.wordpress.org/Taxonomies(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  9. 9. Custom Taxonomies <?php register_taxonomy($taxonomy, $object_type, $args); ?>    //  Add  new  taxonomy,  NOT  hierarchical  (like  tags)    $labels  =  array(        name  =>  _x(  Writers,  taxonomy  general  name  ),        singular_name  =>  _x(  Writer,  taxonomy  singular  name  ),        search_items  =>    __(  Search  Writers  ),        popular_items  =>  __(  Popular  Writers  ),        all_items  =>  __(  All  Writers  ),        parent_item  =>  null,        parent_item_colon  =>  null,        edit_item  =>  __(  Edit  Writer  ),          update_item  =>  __(  Update  Writer  ),        add_new_item  =>  __(  Add  New  Writer  ),        new_item_name  =>  __(  New  Writer  Name  ),        separate_items_with_commas  =>  __(  Separate  writers  with  commas  ),        add_or_remove_items  =>  __(  Add  or  remove  writers  ),        choose_from_most_used  =>  __(  Choose  from  the  most  used  writers  ),        menu_name  =>  __(  Writers  ),    );      register_taxonomy(writer,book,array(        hierarchical  =>  false,        labels  =>  $labels,        show_ui  =>  true,        update_count_callback  =>  _update_post_term_count,        query_var  =>  true,        rewrite  =>  array(  slug  =>  writer  ),    ));http://codex.wordpress.org/Taxonomies(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  10. 10. Advanced Queries<?php $the_query = new WP_Query( $args ); ?>WP_Query is a class defined in wp-includes/query.php that deals with the intricacies of a posts(or pages) request to a WordPress blog. The wp-blog-header.php (or the WP class in Version 2.0)gives the $wp_query object information defining the current request, and then $wp_querydetermines what type of query its dealing with (possibly a category archive, dated archive,feed, or search), and fetches the requested posts. It retains a lot of information on therequest, which can be pulled at a later date.<?php$args=  array(          .          .);$query=  new  WP_Query($args);//  Loopwhile($query-­‐>have_posts()):          $query-­‐>next_post();          $id  =  $query-­‐>post-­‐>ID;          echo  <li>;          echo  get_the_title($id);          echo  </li>;endwhile;?>http://codex.wordpress.org/Class_Reference/WP_Query(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  11. 11. Advanced Queries (cont.)<?php $the_query = new WP_Query( $args ); ?>Class Methods Parameters- init()- parse_query( $query )- parse_query_vars()- get( $query_var )- set( $query_var, $value )- &get_posts()- next_post()- the_post()- rewind_posts()- &query( $query )- get_queried_object()- get_queried_object_id()- WP_Query( $query = ) (constructor)http://codex.wordpress.org/Class_Reference/WP_Query(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  12. 12. Advanced Queries (cont.) <?php $wpdb->get_results( MYSQLQuery ); ?>The $wpdb object can be used to read data from any table in the WordPress database, not just the standardtables that WordPress creates.$wpdb-­‐>query(     $wpdb-­‐>prepare(       "                                DELETE  FROM  $wpdb-­‐>postmeta      WHERE  post_id  =  %d      AND  meta_key  =  %s     ",                  13,  gargle                  ));or  $wpdb-­‐>query(   "   UPDATE  $wpdb-­‐>posts     SET  post_parent  =  7   WHERE  ID  =  15       AND  post_status  =  static   ");http://codex.wordpress.org/Class_Reference/wpdb(C) 2012 Mohamed Mosaad. All Copyrights Reserved
  13. 13. Scan My vCard wpmonkeys.com fb.com/banhawi be.net/banhawi eg.linkedin.com/in/banhawi twitter.com/banhawi www. .com▼▼ http://bit.ly/Xh5EiB
  14. 14. Thank You§ Mohamed Mosaad UX Evangelist & WordPress Expert wpmonkeys.com

×