Theme Development and Customization

30
THEME DEVELOPMENT AND CUSTOMIZATION By / Aniket Pant @aniket_pant

description

Slides from my talk at WordCamp Jabalpur 2011. Note: All slides redone from deck.js to reveal.js

Transcript of Theme Development and Customization

Page 1: Theme Development and Customization

THEME DEVELOPMENTAND CUSTOMIZATION

By / Aniket Pant @aniket_pant

Page 2: Theme Development and Customization

PREVIEW1. Basic Concepts2. Stylesheets3. Functions4. Templates5. Child Themes6. Bones

Page 3: Theme Development and Customization

WHAT IS WORDPRESS?

Page 4: Theme Development and Customization

CONTENTMANAGEMENT

SYSTEM

Page 5: Theme Development and Customization

WHAT IS A THEME?As per the codex —

“ Fundamentally, the WordPress Themesystem is a way to “skin” your weblog. Yet,it is more than just a “skin.” Skinning your

site implies that only the design is changed.WordPress Themes can provide much

more control over the look andpresentation of the material on your

website. ”

Page 6: Theme Development and Customization

By at #frontend2011

“ In Web design, we should all becraftsmen or craftswomen. We should

break the frame and explore the unknown.”

Simon Collison

Page 7: Theme Development and Customization

WHAT MAKES A THEME?Theme StylesheetsFunction FilesTemplate Files

Page 8: Theme Development and Customization

THEME STYLESHEETSThis is the theme information of Bones

/****************************************************************** Theme Name: Bones Theme URI: http://www.themble.com/bones Description: An incredibly simple starter theme for developers. Author: Eddie Machado Author URI: http://www.themble.com/bones/ Version: 1.07 Tags: html5, framework, css3, development

License: GPL or whatever License URI: ? All Default Styles are in library/css/default.css I recommend not editing those files and making all changes here. That way if something goes awry, you can easily revert back to the original, but that's totally up to you. Happy Developing! ******************************************************************/

Page 9: Theme Development and Customization

FUNCTIONS FILEYou can put in your custom PHP codes in this file to

modify some core functions of your theme.

It is often used to insert 2 sidebars, change the number ofcharacters in the excerpt, add custom admin panels or a

new type of post.

“Put in your entire hand coded functions, tailor made for yourtheme.”

Page 10: Theme Development and Customization

EXAMPLE #1function bones_excerpt() { the_excerpt(); echo '<br />'; echo '<p><a href='".get_permalink()."'> Read More...</a></p>';}

Page 11: Theme Development and Customization

EXAMPLE #2function bones_register_sidebars() { register_sidebar(array( 'id' => 'sidebar1', 'name' => 'Sidebar 1', 'description' => 'The first (primary) sidebar.', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<h4 class="widgettitle">', 'after_title' => '</h4>', )); }

Page 12: Theme Development and Customization

TEMPLATE FILESstyle.css index.php comments.php home.phpsingle.php single-.php search.php attachment.phpimage.php 404.php page.php category.phptag.php taxonomy.php author.php date.php

Page 13: Theme Development and Customization

THE HEADER<!doctype html> <head> <meta charset="utf-8"> <title><?php wp_title( '-', true, 'right' ); bloginfo( 'name' ); ?></title> <link rel="shortcut icon" href="/favicon.ico"> <link rel="pingback" href=""> <?php wp_head(); ?> <link rel="stylesheet" href=""> </head> <body <?php body_class(); ?>> <div id="container"> <header role="banner"> ... </header>

Page 14: Theme Development and Customization

THE CONTENT<?php get_header(); ?> <div id="content" class="clearfix"> <div id="main" class="col700 left clearfix" role="main"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <article id="post-"> <header> <h1 class="h2"><?php the_title(); ?></h1> </header> <section class="post_content clearfix"> Read more on "'.the_title('', '', false).'" »', "bonestheme")); ?> </section> <footer> ... </footer> <?php comments_template(); ?> <?php endwhile; ?> <?php else : ?> <article id="post-not-found"> <header> <h1>Not Found</h1> </header> <section class="post_content"> <p>Sorry, but the requested resource was not found on t

Page 15: Theme Development and Customization

THE MIGHTY LOOP

Page 16: Theme Development and Customization

THE LOOPThis is what you see.

It will contain The Loop.The Loop is the key to printing all your posts.

This is how it starts:

And this is the end:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?>

<?php endif; ?>

Page 17: Theme Development and Customization
Page 18: Theme Development and Customization

SINGLE POST TYPE

Page 19: Theme Development and Customization

SINGLE-<POST-TYPE>.PHPAnother important feature in WordPress 3.0 is that you

can add your own Custom Post Type Boxes.

The default list –Post, Page, Attachment, Revisions, Nav Menus

Page 20: Theme Development and Customization

REGISTER A POST TYPEAdd this to your function.php

register_post_type('movies', array( 'label' => 'Movies', 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array('slug' => 'movies'), 'query_var' => true, 'supports' => array( 'title', 'editor', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'thumbnail', 'author', 'page-attributes',) ) );

Page 21: Theme Development and Customization

By at #frontend2011

“ The content is like water. And design islike a flavour sprinkled on content. ”

@standardistas

Page 22: Theme Development and Customization

“ People say Web Design is not coding, Icall that bullshit.

We design the web by coding. ”

Page 23: Theme Development and Customization

CHILD THEMES

Page 24: Theme Development and Customization

CHILD THEMESDerive something from another theme and what you get

is a Child Theme.

You can do absolutely anything with a Child Theme, butthe only difference between a new theme and a child

theme is that.It would be residing in the parent theme's directory.

Page 25: Theme Development and Customization

BUILD A CHILD THEMEJust make a directory in your parent theme directory.You

can name it anything.

You can put anything in this directory.So, if it's just astyling change you wish to make, make a style.css

There are some required information that you need tomention in the child theme's CSS like –

Theme Name & Template.You can refer to the Codex regarding this.

Page 26: Theme Development and Customization

WHAT WE HAVE COVEREDThe basic concepts of WordPressLittle on StylesheetsSome snippets on functionsMaking TemplatesBuilding Child ThemesMy favorite theme bones

Page 27: Theme Development and Customization

“ We are the architects of the Web, andthis is our playground. ”

Page 28: Theme Development and Customization

WHAT DO I DO?Read regularly.

Visit daily.

Read about typography.

Read anything and everything about CSS.

Smashing Magazine

Hacker News

Page 29: Theme Development and Customization

QUESTIONS?

Page 30: Theme Development and Customization

THE ENDBY ANIKET PANT / @ANIKET_PANT