54
WORDPRESS THEME Development From Scratch ICT MeetUp 2013 By : Chandra Prakash Thapa

WordPress theme development from scratch : ICT MeetUp 2013 Nepal

  • Upload
    cp-thapa

  • View
    11.350

  • Download
    1

Embed Size (px)

DESCRIPTION

WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Citation preview

Page 1: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

WORDPRESS THEMEDevelopmentFrom Scratch

ICT MeetUp 2013

By : Chandra Prakash Thapa

Page 2: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

What is a WordPress theme?

A group of templates and a stylesheet that displays content entered into the database via the WordPress admin.

At a minimum, you need: index.php style.css

Page 3: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Let’s Start [ Get Free Responsive Template ]

Download the brownie template from: http://www.html5xcss3.com/2012/06/html5-template-responsive-brownie.html

Copy and paste the HTML design file to WordPress theme directory.[ wp-content/themes/brownie ]

Rename the index.html to index.php Create a style.css file in brownie. [ wp-content/themes/brownie/style.css ]

Page 4: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

style.css[ Template Settings ]/* Theme Name: Brownie. Theme URI: http://merobox.com/ Description: This is my first WordPress template.Author: Chandra Prakash Thapa.Author URI: http://cpthapa.com.np/ Version: 1.0 Tags: brown, two-columns, custom-background, License: License URI:

General comments (optional). */

Page 5: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Go to Appearance->Themes?

Page 6: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Add screenshot image inside theme folder[ wp-content/themes/brownie/screenshot.png ]

Page 7: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Visit the site[ demo ]

Page 8: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Static Link1. CSS : <link rel="stylesheet" href=“css/style.css" type="text/css" />2. Script : <script type="text/javascript" src=“js/jquery.min.js"></script>3. Images : <img src=“images/facebook.png" alt="Facebook">

1. CSS : <link rel="stylesheet" href="<?php bloginfo('template_url'); ?>/css/style.css" type="text/css" />

2. Script : <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.min.js"></script>

3. Images : <img src="<?php bloginfo('template_url'); ?>/images/facebook.png" alt="Facebook">

To Dynamic Link

Page 9: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Visit the site[ again ]

Page 10: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

A Basic Theme Requirement 404.php - Custom “not found” page footer.php - The template called with get_footer() functions.php - A place to create custom functions, register sidebars, and other settings header.php - The template called with get_header() index.php - The default template home.php - The basic home template page.php - Overall template for pages search.php - Search results template searchform.php - The template called with get_search_form() sidebar.php - The template called with get_sidebar() single.php - Overall template for single posts style.css - The main stylesheet

Page 11: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

home.phpindex.php

Create home.php file. Copy all code from index.php to home.php

Page 12: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Break Code Into segments [home.php]

Page 13: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Header.php

// Add wp_head() function before end of </head> tag.<?php wp_head (); ?></head><body>

<header class="header_bg clearfix">

Page 14: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Header.php

// Add title to your website<title>

<?php bloginfo('name'); // Title of the website ?> <?php wp_title(); // Title of the single page or post

?></title>

Page 15: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Footer.php

// Add wp_footer() function before end of </body> tag.

<?php wp_footer(); ?></body>

</html>

Page 16: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Footer Copyright.[ footer.php ] <p> &copy; <?php echo date('Y'); ?> <?php bloginfo('name'); ?>. </p>

Page 17: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Home.php <?php get_header(); ?> Remaining code part.(after excluding header / footer) <?php get_footer(); ?>

Page 18: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

functions.php File is place inside theme folder. wp-content/themes/yourtheme/functions.php Changes default behavior of WordPress. Behaves like WordPress Plugin. Use it to call PHP or built-in WordPress functions. Use to define your own functions. Register menu, sidebar and widgets.

Page 19: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Registering Menu// registering header and footer menu in functions.php filefunction merobox_addmenus() {

register_nav_menus(array(

'header_nav' => 'Header Menu','footer_nav' => 'Footer Menu'

));

}

add_action('init', 'merobox_addmenus');

Page 20: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

A look into menu (3.6 version)

Page 21: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Displaying menu (footer menu)

<div class="menu"><?php if (has_nav_menu('footer_nav')) {

wp_nav_menu( array('theme_location' => 'footer_nav') );

} ?>

</div>

Page 22: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Displaying menu [ header menu ]<?php

if (has_nav_menu('header_nav')) { wp_nav_menu(

array('theme_location' => 'header_nav','container' => 'nav','container_class' => 'main-menu')

); }

?>

Page 23: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Theme options

Option Framework add theme options panel. http://wordpress.org/plugins/options-framework/ Download -> Install -> Activate.

Page 24: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Add Options.php Download optons.php file from link below : https://github.com/devinsays/options-framework-plugin/blob/master/

options-check/options.php Add options.php file in the theme folder brownie.

Page 25: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Dynamic text content

Page 26: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Dynamic text [ option.php ] $options[] = array( 'name' => __('Why Line one', 'options_check'), 'desc' => __(' Why to choose your business line one.', 'options_check'), 'id' => 'why_line_one', 'std' => 'Default Text', 'type' => 'text‘ );

Page 27: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Dynamic text display [ home.php] Add the following code to display previously added content.<p>

<?php echo of_get_option('why_line_one'); ?></p>

Page 28: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Dynamic Image Slider[home.php]

The Query The Loop Reset Query

Page 29: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Dynamic Image Slider [ Post Thumbnail Support]// Add post thumbnails support in functions.php fileadd_theme_support( 'post-thumbnails' );

// default thumbnail size for photo galleryset_post_thumbnail_size( 281, 140, true );

//thumbnail size for image slideradd_image_size( 'image_slide_thumb', 940, 360, true );

Page 30: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Dynamic Image Slider<ul class="slides"> <?php $slider_cat = of_get_option('image_slider');

// The Query query_posts( 'posts_per_page=5&cat='.$slider_cat );

// The Loop while ( have_posts() ) : the_post();?> <li> <?php the_post_thumbnail('image_slide_thumb',true); ?> <p class="flex-caption"><?php the_title(); ?></p> </li> <?php endwhile;

// Reset Query wp_reset_query();

?> </ul>

Page 31: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Dynamic Image Slider[ The Query ]

<ul class="slides"> <?php

// The Query $slider_cat = of_get_option('image_slider');

query_posts( 'posts_per_page=5&cat='.$slider_cat );

[ The Option Panel ]

$options[] = array('name' => __('Image Slider', 'options_check'),'desc' => __('Catgory to use for image slider', 'options_check'),'id' => 'image_slider','type' => 'select','options' => $options_categories);

Page 32: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Dynamic Image Slider[ The Loop ]

// The Loop while ( have_posts() ) : the_post();?> <li>

<?php the_post_thumbnail('image_slide_thumb',true); ?> <p class="flex-caption"><?php the_title(); ?></p>

</li><?phpendwhile;

Page 33: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Dynamic Image Slider[ Reset Query ]

// Reset Query wp_reset_query();

?> </ul>

Page 34: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Featured Content [home.php]

Page 35: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Featured Content Settings[ The Option Panel : options.php]

$options[] = array('name' => __('Featured Page one', 'options_check'),'desc' => __('Select the pages to be featured on home page one', 'options_check'),'id' => 'featured_page_one','type' => 'select','options' => $options_pages);

Page 36: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Featured Content Display[ get_post() : home.php] <?php $pageID = of_get_option('featured_page_one'); $pageObj = get_post($pageID); $pageContent = $pageObj->post_content; ?> <h3><?php echo $pageObj->post_title; ?></h3> </div> <p>

<?php echo substr(strip_tags($pageContent),0,500)."...."; ?> <br />

<a href="<?php echo get_permalink($pageID); ?>">more info</a> </p>

Page 37: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Content Type Post

- blog, news style content. - single.php

Page - static content like contact us, about us page. - page.php

Page 38: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

single.phpblog_single.html

Create single.php file. Copy all code from blog_single.html to single.php

Page 39: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Post : Single.php[ blog, news post ]

Page 40: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

sidebar.php

header.php - get_header(); footer.php - get_footer();

Page 41: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Post : Single.php [Demo Post ]

https://developers.facebook.com/docs/reference/plugins/comments/

Page 42: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Post : single.php[ The Loop ]<?php get_header(); ?><?php if (have_posts()) :

while(have_posts()) : the_post(); ?>

Title: <?php the_title(); ?>Published date: <?php the_date('F j, Y'); ?>Author: <?php the_author_posts_link() ?>Category: <?php the_category(', '); ?>Tag: <?php the_tags(','); ?>Content: <?php the_content(); ?>

<?php endwhile; endif; ?><?php get_sidebar(); ?><?php get_footer(); ?>

Page 43: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Page : page.php[ Demo ]

Page 44: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Page : page.php[ The Loop ]

<?php get_header(); ?><?php if (have_posts()) :

while(have_posts()) : the_post(); ?>

Title: <?php the_title(); ?>Content: <?php the_content(); ?>

<?php endwhile; endif; ?><?php get_sidebar(); ?><?php get_footer(); ?>

No Published date:No Author: No Category:

No Tag:No Comment

Page 45: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Custom Page : mycontact.php<?php /* Template Name: My Contact Page */

?>

Page 46: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

index.phpsingle.php

Copy all code from single.php to index.php Just remove the_content( ) with the_excerpt( ) And add read more link using the_permalink( );

Index.php [ default template ]

Page 47: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Sidebars : Dynamic Widget Ready [Demo : page, post]

<div class="widget"><h2><span>Categories</span></h2><!– Content Goes here -->

</div>

Page 48: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Sidebars : Dynamic Widget Ready [ Registering : functions.php]

register_sidebar(array(

'name' => 'Sidebar','id' => 'right-sidebar','before_widget' => '<div

class="widget">','after_widget' => '</div>','before_title' => '<h2><span>','after_title' => '</span></h2>',

));

Page 49: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Sidebars : Dynamic Widget Ready [ Displaying : sidebar.php]

<div class="sidebar">

<?php if ( !function_exists('dynamic_sidebar')

|| !dynamic_sidebar('right-sidebar') ) :

endif; ?>

</div>

Page 50: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Extra : Plugin [ Next Gen Gallery ]

http://wordpress.org/plugins/nextgen-gallery/

Page 51: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Extra : Plugin [ Contact Form 7 ]

http://wordpress.org/plugins/contact-form-7/

Page 52: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Extra : Plugin [ WP-PageNavi ]

http://wordpress.org/plugins/wp-pagenavi/

Page 53: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Reference[ For more ] http://codex.wordpress.org http://www.youtube.com/watch?v=uwecNcdAUaY http://line25.com/tutorials/how-to-create-a-simple-wordpress-blog-theme http://blog.teamtreehouse.com/responsive-wordpress-bootstrap-theme-tutorial http://www.onextrapixel.com/2011/03/08/how-to-code-a-wordpress-3-0-theme-

from-scratch/ Google.com

Page 54: WordPress theme development from scratch : ICT MeetUp 2013 Nepal

Thank You! QUESTIONS?

Chandra Prakash Thapa

@cpthapa

[email protected]