Showing posts with label wp theme. Show all posts
Showing posts with label wp theme. Show all posts

Saturday, March 16, 2013

How to Create a WordPress Theme from Scratch

Setting Up the Work Station
To get started with this tutorial we should set up a server on our computer using either XAMPP or WAMP (usually if employed on a PC), or MAMP if you are working on a Mac. All of these tools permit for a local checking natural natural natural environment for WordPress and can make it so that you don't have to certainly move documents through FTP while employed on a task.

In periods of cipher revising I would highly suggest Notepad++. With syntax highlighting, and an very simple and clean user interface for coding, I would have to state it is my personal favorite (plus, you can't trounce free), but Notepad or Notepad 2 furthermore work as well.

Getting the essential Folders and documents prepared

In the folder containing your WordPress setting up, proceed to wp-content/themes/ and conceive a folder entitled “New 3.0 Theme”. This is where we will contain all of our documents during this tutorial. Now create the following documents and folders:

/images
style.css
header.php
index.php
single.php
footer.php
archive.php
page.php
sidebar.php
functions.php

Style.css
The style.css will comprise all of the components that style our WordPress template. First though. we will use it to affirm the name of our template as well as the scribe name and link, and recount and type. Now remember when conceiving a WordPress topic, the style.css is one of the two files needed to make the theme work, and the other, which we will be conceiving subsequent, is the index.php.

/*
Theme Name: New WP Theme
Theme URI: http://wordpress.org
Description: A clean and minimal theme that is completely compatible with
Author: Hasibul Islam
Author URI: http://www.webdeveloperszone.com
Version: 1.0
*/

All of this information can be changed at anytime, but it is important that it is all contained within the comments so that it doesn't affect any of the definitions created.
Now we will create some basic definitions that we will later implement in some of the template's PHP files.
body{  
    font-family: Arial, Helvetica, Georgia, Sans-serif;
    font-size: 12px;
    background: #d9d9d9;
    color: #000000;
}

a:link, a:visited{
    text-decoration: none;
    color: #000000;
}

a:hover{
    color: #5f5f5f;
}

h1 {
    font-size: 54px;
}

h3 {
    font-size: 24px;
}

#wrapper{
    margin: 0 auto;
    width: 750px;
    text-align: left;
    background: #fff;
    padding: 20px;
     
}

#header{
    width: 750px;
    height: 100px;
}

#blog{
    float: left;
    width: 520px;
    padding: 0 10px 10px 10px;
}

.sidebar{
    float: left;
    width: 200px;
    margin: 0 0 0 10px;
    font-size: 14px;
    list-style: none;
}

#footer{
    clear: both;
    text-align: center;
    height: 50px;
    background: #ccc;
    padding: 10px;
}

The tag is just utilised to affirm the specifications for fonts utilised on the website, as well as the background color (this can be altered to your own liking). We then affirm the style attributes for connections as well as some of the headers that we will be utilising throughout our theme.

The #wrapper is going to be the full size of the web page, with #header obviously being the header, and #blog encompassing just the latest blog posts on the location. finally we have .sidebar and #footer which will both just comprise the basic delineations for those granted areas, which we will get into more deepness about later.

Header.php
Next we will create the header.php, which at the moment will contain our website logo, as well as our custom navigation.

<!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<title><?php wp_title ( '|', true,'right' ); ?></title>

<link rel="profile" href="http://gmpg.org/xfn/11" />
<link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" />
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />

<?php
    /*
     *  Add this to support sites with sites with threaded comments enabled.
     */
    if ( is_singular() && get_option( 'thread_comments' ) )
        wp_enqueue_script( 'comment-reply' );

    wp_head();
     
    wp_get_archives('type=monthly&format=link');
?>
</head>
<body>

<div id="wrapper">
    <div id="header">
        <h1><a href="<?php echo get_option('home'); ?>"><?php bloginfo('name'); ?></a></h1>
    </div>

All of this cipher doesn't actually need to be explained in much deepness, but just recall that the above code should be in the header.php of all of your themes. First we declare the doctype, as well as use the benchmark that will be utilised to show the name of your website as you kind it in your WordPress settings, and then your style.css and the PHP code that will endow WordPress 3.0's threaded comments.

supplementing Custom Navigation
Now that we have coded up our header.php with our rudimentary data and our blog's title, we can add our custom navigation list, a characteristic that was introduced in WordPress 3.0. Before we actually add the cipher to our header.php though, we have to first open up the functions.php, and add the essential code to endow the made-to-order menus.

<?php

//Add support for WordPress 3.0's custom menus
add_action( 'init', 'register_my_menu' );

//Register area for custom menu
function register_my_menu() {
    register_nav_menu( 'primary-menu', __( 'Primary Menu' ) );
}

?>

As you can see by the commented parts of the code, the first part, with add_action is utilised to add support for custom meal lists, and next we register a custom list and title it “Primary Menu”. Now, we will move on to implementing the list into our topic.

To do this, we will have to add this line of code below at the end of our header.php document.

<?php wp_nav_menu( array( 'sort_column' => 'menu_order', 'menu_class' => 'nav', 'theme_location' => 'primary-menu' ) ); ?>

Now on to comprehending precisely what this means. The primary function that is being utilised is wp_nav_menu, with sort_column, container_class, and theme_location as the contentions being used. What sort_column does is makes certain that the alignment you pick in your WordPress dashboard is followed. container_class will allow for you to select the CSS class that you have conceived to be utilised to method your list. Lastly, theme_location just assigns the list to while we select, which at the moment happens to be primary-menu.

Styling the Navigation
We have our made-to-order header navigation up and running, but at the moment it just looks like a dull old register of connections that regrettably, are aesthetically unappealing. To rectify this, we will conceive a class called nav in our style.css.

.nav{
    width:750px;
    background: #000;
    display:block;
    float:left;
    position:relative;
}

.nav ul{
    list-style:none;
}

.nav li{
    float:left;
    position:relative;
}

As you can glimpse in our .nav we have made some rudimentary affirmations, such as the breadth of the navigation, backdrop, where it will align, as well as the display worth. Next we method the rudimentary unordered register by just making certain that no projectiles are shown with our links. For our register we ride high the pieces to the left, as well as place it relative.

Now we will complete the styling of our navigation by supplementing styles to the links and dropdown menus.

.nav a{
    display:block;
    text-decoration:none;
    color:#fff;
    padding:0 15px 10px 0;
    font-size:13px;
    font-weight:bold;
}

.nav ul ul{
    display:none;
    position:absolute;
    top:100%;
    left:0;
    float:left;
    z-index:99999;
    background: #212121;
}

.nav ul ul ul{
    top: 30%;
    left:100%;
    background: #343434;
}

.nav ul ul a{
    height:auto;
    line-height:1em;
    padding:10px;
    width:130px;
}

.nav li:hover > a,.nav ul ul:hover > a{
    color:#ccc;
}

.nav ul li:hover > ul{
    display:block;
}

As you can glimpse we start by fashioning our links for the list, and now we get into fashioning our drop-down meal lists. In .nav ul ul we set the position to unconditional, and put the top house to 100%, so that it is exactly under it's parent link. We also altered the backdrop to make the drop-down connection stand out a little bit, as well as set our z-index to 99999 so that no issue what's underneath it or in the menu's way, it will habitually stay on top of all other components.

For that third drop-down list, we have changed the backdrop hue afresh just slightly so that it stands out, as well as made left 100% so that it is all the way right of our first drop-down, and set the peak to 30% so that it is still adhered to that second drop-down, but is divided from the entire list.

finally we method the links for our drop-down menus, as well as the what our navigation will gaze like when a user hovers over a granted connection and its drop-down.

Index.php
The index.php will be the home sheet of our website, and will comprise cipher to encompass our header, footer, and sidebar, which I will interpret underneath, as well as the cipher to encompass the most latest mails from our blog and take benefit of WordPress 3.0's mail thumbnails feature.

<?php get_header(); ?>

    <div id="blog">
        <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
         
        <div class="post">
        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
         
            <div class="entry">  
                <?php the_post_thumbnail(); ?>
                <?php the_content(); ?>

                <p class="postmetadata">
                <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
                <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
                </p>

            </div>
        </div>
<?php endwhile; ?>
         
        <div class="navigation">
        <?php posts_nav_link(); ?>
        </div>
         
        <?php endif; ?>
    </div>
<?php get_sidebar(); ?>  
<?php get_footer(); ?>

These lines of code are used to output all of the information in the header.php, sidebar.php, and footer.php wherever you place them in your theme files.

<?php get_header(); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

Other than that, the cipher here is attractive easy to realise. After we call the header.php, we use our #blog that we created just a little bit before, and we call the loop that will be utilised to bring up the newest posts on our WordPress blog. After that we cover the name of our posts in

, which we also styled earlier.

The one part of cipher here that displays how we're going to be taking advantage of WordPress 3.0's post-thumbnail feature is the . As it stands, this code won't do anything, until we cause the feature in our functions.php which we will do in the next step.

Enabling Post Thumbnails
We have supplemented our cipher to display the mail thumbnails on the homepage, but at the instant nothing happens as we have not really endowed the characteristic to work. Now open up the functions.php that we worked on before, and the underneath code should be supplemented after your list navigation code.

// Enable post thumbnails
add_theme_support('post-thumbnails');
set_post_thumbnail_size(520, 250, true);

The cipher overhead is pretty self-explanatory as it magic charms out nearly precisely what it does. The second line will add the support for mail thumbnails in our topic, while the third line characterises the exact dimensions of our thumbnail, which for this item, will be set at 520 pixels for breadth, and 250 pixels for height.

Sidebar.php
The sidebar.php is, as you estimated, the document that will brandish all of the information we desire in the sidebar. Since we have currently included the document in our index.php, all we have to do is put the code in this file and our sidebar will display up on the homepage.

<div class="sidebar">
<?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar() ) : else : ?>

<?php endif; ?>
</div>

Yup, that will be all of the cipher that's added to our sidebar.php to make it purposeful. We call the div that we created in our style.css, and the code underneath will make it so that we can add widgets to our sidebar in the alignment and way we want them by the WordPress backend. although, like numerous characteristics, we have to modify our functions.php document first to make this characteristic work properly.

//Some simple code for our widget-enabled sidebar
if ( function_exists('register_sidebar') )
    register_sidebar();
The code just notifies WordPress to list a sidebar which we called in our sidebar.php. WordPress can handle multiple sidebars attractive effortlessly if you want more than one, but for the sake of holding this already-long tutorial relatively short, we'll let Google answer the inquiry on how to do that for you.

Single.php
The single.php is what will be utilised for a single mail sheet, and most of the cipher should look pretty alike since we've already coded up our index.php. Really the only thing that's distinct is that we have added in our comments-template div, and the cipher to include the comments.php.

<?php get_header(); ?>

    <div id="blog">
        <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
         
        <div class="post">
        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
            <div class="entry">  
                <?php the_post_thumbnail(); ?>
                <?php the_content(); ?>

                <p class="postmetadata">
                <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
                <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
                </p>

            </div>

            <div class="comments-template">
                <?php comments_template(); ?>
            </div>
    </div>

<?php endwhile; ?>
     
    <div class="navigation"> 
        <?php previous_post_link('< %link') ?> <?php next_post_link(' %link >') ?>
    </div>

<?php endif; ?>
</div>

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

Comments.php
With the release of WordPress 3.0 has meant the standardizing of comments forms throughout all WordPress themes making it easier for theme authors to and plugin developers since the comments form can be modified via hooks.

Below will be the code you will want to put in your comments.php file in your theme template.
<?php comment_form(); ?>

This will brandish a remarks form that examines well on our theme, but if you would like to discover more about customization of the commentary pattern, you might desire to ascertain out WordPress 3.0 topic Tip the Comment pattern.

Page.php
When you conceive a sheet in WordPress, a distinct document is used to brandish the content of what you drafted into the page, and that is page.php. The cipher will gaze almost absolutely equal to what we typed up in our single.php, except since it is a sheet we are going to omit the remarks template, and change the post navigation slightly to handle a sheet rather than of a mail. Other than that, the code will be precisely the same.

<?php get_header(); ?>

    <div id="blog">
        <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
         
        <div class="post">
        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>


            <div class="entry">
            <?php the_content(); ?>

                <p class="postmetadata">
                <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
                <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
                </p>

            </div>

        </div>
         
<?php endwhile; ?>

    <div class="navigation">
        <?php posts_nav_link(); ?>
    </div>

<?php endif; ?>
</div>

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

Category.php
The category.php will assist as the document that, when a client examines at a specific post category, time for posts, or specific scribe, will be the document that serves up the data to display mails. As with our page.php, most of the code here is going to be the exact same as the single.php we created before, except for a chunk right at the beginning.

<?php get_header(); ?>

    <div id="blog">
        <?php if(have_posts()) : ?><?php while(have_posts()) : the_post(); ?>
         
    <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
      <?php /* If this is a category archive */ if (is_category()) { ?>
        <h2>Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Category:</h2>
      <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
        <h2>Posts Tagged &#8216;<?php single_tag_title(); ?>&#8217;</h2>
      <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
        <h2>Archive for <?php the_time('F jS, Y'); ?>:</h2>
      <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
        <h2>Archive for <?php the_time('F, Y'); ?>:</h2>
      <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
        <h2>Archive for <?php the_time('Y'); ?>:</h2>
      <?php /* If this is an author archive */ } elseif (is_author()) { ?>
        <h2>Author Archive</h2>
      <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
        <h2>Blog Archives</h2>
    <?php } ?>
         
        <div class="post">
        <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>

            <div class="entry">
            <?php the_content(); ?>

                <p class="postmetadata">
                <?php _e('Filed under&#58;'); ?> <?php the_category(', ') ?> <?php _e('by'); ?> <?php  the_author(); ?><br />
                <?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?> <?php edit_post_link('Edit', ' &#124; ', ''); ?>
                </p>

            </div>

        </div>
         
<?php endwhile; ?>

    <div class="navigation">
        <?php posts_nav_link(); ?>
    </div>

<?php endif; ?>

</div>

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

This piece of code right here will be the only thing that is added, and we have included it right after our WordPress loop.

<?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>
      <?php /* If this is a category archive */ if (is_category()) { ?>
        <h2>Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Category:</h2>
      <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
        <h2>Posts Tagged &#8216;<?php single_tag_title(); ?>&#8217;</h2>
      <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
        <h2>Archive for <?php the_time('F jS, Y'); ?>:</h2>
      <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
        <h2>Archive for <?php the_time('F, Y'); ?>:</h2>
      <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
        <h2>Archive for <?php the_time('Y'); ?>:</h2>
      <?php /* If this is an author archive */ } elseif (is_author()) { ?>
        <h2>Author Archive</h2>
      <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
        <h2>Blog Archives</h2>
    <?php } ?>

What this does is use a assortment of if/elseif statements in PHP to show what we are actually browsing on our blog. So if we're looking at a exact category called “Test class 1”, it will display in the h2 heading “Archive for the ‘Test Category 1’ Category:” before all mails, and it will do this for certain dates, authors, and so on.

made-to-order Backgrounds, Feed connections
As recounted before, one feature that has been applied in WordPress 3.0 is the ability to conceive or change the backdrop of your location, be it an likeness or rudimentary hue, just through the WordPress backend. All we need for this characteristic to work fully?

This one little line of code:
add_custom_background();

And like that, custom backgrounds are now enabled. Next, we are going to be adding some equally simple code to make it so that relevant feed links are available everywhere on the site. Be it the standard feed, comments, tags, categories, all of these will be added to the header without any extra code.
Let's add the following code to our functions.php, to make this feature work as it should.
add_theme_support( 'automatic-feed-links' );

Footer.php
To complete off our work here, we are going to conceive our footer.php file, which too will use the #footer that we announced in our style.css, and will just contain some rudimentary copyright data as well as a link to the tales and remarks RSS feed at the bottom.

<div id="footer">
    <p>
    <strong>Copyright 2011 <?php bloginfo('name'); ?> | All Rights Reserved.</strong> </a>
    Designed by <a href="http://slackrmedia.com">SlackrMedia</a>
    </p>
    <p><a href="<?php bloginfo('rss2_url'); ?>">Latest Stories RSS</a> | <a href="<?php comments_rss_link('comment feed'); ?>">Comments RSS</a></p>
    </div>
</div>

</body>
</html>




How To Create A Responsive, Mobile Support WordPress Theme

Let’s assess the position. WordPress is an exceedingly well liked, flexible, very simple to use and open-source blogging and CMS scheme. More and more mobile apparatus are flooding the market every day, altering the way persons use the Internet. And the need is growing for more attractively conceived and coded WordPress themes that work well over all of these apparatus. So, what are we waiting for? Let’s get to work!

How to create a responsive mobile first WordPress topic
at first, the idea of designing and evolving a fully responsive, mobile-ready WordPress theme might be swamping. You might be conceiving, “How do I handle a responsive conceive with all of this flexible content that a WordPress topic has? What should I consider when designing for feel apparatus? And do I actually have to get relieve of drop-down meal lists and other hover elements on mobile devices?”

But after doing some study and looking more nearly at some of the responsive WordPress topics and theme structures out there, you will likely cover your head round the idea attractive rapidly, and the developing world of WordPress topic design will sound like a huge opening that you can’t wait to get begun on.

(Seating’s note: If you relish reading our articles, you'll love the shattering eBook Library. Get direct access to all shattering eBooks with 70% discount and ballot on the topics you’d like to discover more about. We’ll prepare eBooks that fit your needs best! Subscribe now!)
It’s all about groundwork

having a comprehensive design notion is even more significant for a responsive WordPress theme than for a static-width topic. At this stage, you haven’t determined any thing, so not anything will get in your way of conceiving a quick-witted and functional layout that adapts smoothly to distinct screens.

First, address what you want to accomplish with your WordPress topic, which client assembly you are aiming at, and what their desires are. With these considerations, you can conceive a list of helpful components for your layout.
Creating the Theme’s notion

utilizing this register, you can design your theme by sketching the layout at various computer display dimensions.

Responsive WordPress topic layout sketches

when sketching are aware that the layout widths you choose are only rough quotation points to represent the widespread computer display dimensions of today’s smartphones, tablets and desktop computers. Your aim should habitually be to conceive a responsive design that adapts smoothly to a broad diversity of screen dimensions.

Ethan Marcotte, scribe of Responsive Web conceives, recounted his approach to responsive World Wide Web conceive in a latest interview, explaining:

I’m a large-scale, large-scale believer of matching breakpoints to the design, not to one-by-one apparatus. If we’re after more future-proof responsive designs, we should halt conceiving in periods of “320px,” “480px,” “768px,” or anything — the Web’s so much more flexible than that, and those pixels are a snapshot of the Web as we understand it today. Rather than, we should aim on breakpoints tailored to the conceive we’re employed on.

While employed on your concept sketches, furthermore believe about which layout options to offer in the theme (such as header and sidebar options or multiple widget localities) and how they will acclimatize to different computer display sizes as well.

Responsive Layout Sketches
an optional sidebar element in a responsive layout.
Devices for notion sketching

which device you use to evolve the theme’s concept is not significant. Just choose one that permits you to work rapidly and that doesn’t interrupt your workflow.

If you feel most snug sketching on a part of paper or in a notebook, proceed for it. You could furthermore try sketching on an iPad utilizing a well liked app such as Paper by FiftyThree or Bamboo Paper, simultaneously with a digital pen like Waco’s Bamboo Stylus. Working exactly on a tablet will make distributing your ideas later with the developer an alallotmentment simpler. One of my all-time favorite articles is microphone Rohde’s “Sketching: The Visual conceiving Power Tool,” which encourages sketching as a simple visual device for conceiving.

The iPad as a Sketching device
Use your tablet a simple very quick sketching device.
A Good notion keeps Time

If you evolve the notion accurately at the starting of the task, you will save an alallotmentment of time and effort subsequent in the conceive method. The layout will adapt to distinct screen sizes more intelligently if you have considered an alalallotmentmentment about the design’s demeanor before even unfastening Photoshop (or your programs of choice).
Theme-Specific trials to address

Because designing a WordPress topic with very flexible content is rather a distinct dispute than designing a static website, at this early stage of the method you should find answers to the following theme-specific difficulties:
1. WordPress’ Navigation list

Until responsive world wide web conceive found its way into WordPress theme concepts, most topics appeared to rely on good contemporary drop-down meal lists to give users multi-level navigation. But because drop-down meal lists rely on mouse hovering, they don’t work well on touch devices.

We currently have some intelligent solutions for developing responsive, touch device-ready navigation. Brad Frost has a very helpful asset comparing widespread answers for responsive menus in his mail “Responsive Navigation Patterns.”
2. Responsive Layout Options

Most themes offer users at least some layout options, such as left or right sidebar, header widget and footer components. To offer this kind of flexibility in a responsive topic, you will have to consider how all of the layout elements will act on different computer display sizes. For instance, if you want to offer a left sidebar choice, consider that the content of this sidebar would appear overhead the major content area on mobile apparatus. In most situations, this wouldn’t be the best solution because mobile users desire to read the most significant content first (such as the newest blog mail) without having to scroll down a sidebar.
3. Flexible Widget localities

Widget areas are another dispute for responsive designers. After all, conceiving one is not very simple if you don’t know what kind of content the client will put in it. So, you need to make certain that the conceive works no issue which and how numerous widgets are used in the widget localities.
Sufficient Headaches. Let’s Get To The joy.

Because you are conceiving a responsive website, conceiving the entire website pixel by pixel in Photoshop and then just handing it over to the developer would outcome in too static a conceive and too time-consuming a method.
Working with quotation Points

Instead, the conceive process should be utilized to number out the general gaze and feel of the topic. At this stage, you should furthermore work more intensively on the trials mentioned, such as responsive navigation, layout variations and flexible widget areas.

How you prepare the conceive for farther development will count partly on the nature of the project and how nearly you will work with the developer. In general, displaying your design in the three layout versions is a good starting point: smartphone, tablet and desktop. These “screenshots” can then be used as quotation points for development.

Responsive world wide world wide world wide world wide web design layouts
a responsive layout in three variations.
conceiving in the Browser

conceive details such as font dimensions, white space and button methods can be characterized later exactly in the browser. Because browsers often heal these elements differently, designing and checking them exactly in their last environments is way more effective.
Conceiving for feel apparatus

because your conceive will furthermore be utilized on touch apparatus, you have to consider the exceptional obligations of these apparatus. Using a finger to navigate a website is solely distinct than using a precise mouse cursor.

This is why buttons and pattern input fields need to be at the right dimensions. Font dimensions and white space should furthermore be directed more generously, so that users can navigate easily and read content comfortably.
Workout Your Communication abilities

staying in unchanging connection with the developer during the whole process is very important (i.e. if you are not the developer yourself). Particularly in a responsive conceive method, incorporating the developer’s information into your conclusions will keep you from having to change things subsequent on.
Development

After covering up the design process, the first conclusion to make is whether to cipher the theme from rub or to use a bare or starter theme (such as Automatic’s Toolbox or the newer _s theme).

If you desire to work with one of the well liked responsive frameworks such as Twitter’s Bootstrap or Curb’s base, then you could use a starter topic that already encompasses the framework, such as BootstrapWP or WordPress base. Another well liked starter topic is skeletal parts, which utilizes 320 and Up as a mobile-first boilerplate.

Of course, the way you start a topic will habitually depend on the task and your individual preferences. But if you’re still discovering, then a bare theme would assist as a solid base for development.
Proceed Mobile First

an intelligent approach is to conceive and evolve for the least significant layout first (i.e. smartphones) and then work your way up to tablet and desktop computer display sizes. To get farther insight into the mobile-first approach to Web conceive, read the publication Mobile First by Luke Wroblewski.

Mobile First World Wide Web conceives
conceive and evolve your WordPress theme starting with the least significant dimensions first.
Carrying Media Queries in vintage Browsers

With the smartphone layout as your default, you will need to rely on a JavaScript answer such as Respond.js to support newspapers queries in old browsers (such as Internet Explorer 7 and 8).

On the other hand, you could add CSS categories for old IE browsers through dependent comments, and then add CSS styles to set a greatest width for old IE browsers outside of your media queries. You can find a comprehensive explanation of this procedure in the item “Leaving vintage Internet Explorer Behind.”
Images in a Responsive topic

with the issue of high-pixel-density apparatus such as the new iPad and new MacBook Pro, you will furthermore need to reassess the images in your topic.

Alternatives to images would be to use a CSS answer or use icon fonts. Fewer images will furthermore outcome in a much more lightweight topic, which will speed up performance on slow mobile Internet attachments. Trent Walton portions his reflections on the Retina-optimization of World Wide Web conceive in his item “In Flux.”
Test, Test, check

particularly when evolving a responsive theme, checking your work live as soon and as often as likely is critical. This way, you can rapidly correct methods throughout development as necessary. Also, test if fonts are very simple to read and if images, gallery sliders and embedded components such as video work correctly on distinct apparatus.
How to Test on mobile apparatus

of course, checking your theme on one of the numerous screen-resolution-testing tools, such as Screenfly, during development is very cooperative, too.

Testing a world wide world wide web conceive with Screenfly
The mobile type of United Pixelworkers’s world wide world wide website checked with Screenfly.

But because of the different demeanour of mobile browsers, touchscreens and high-density partitions, certainly testing your topic on genuine apparatus is significant.

Except you work for a large-scale company, finding ways to check your topic throughout the development process can be rather a dispute. Of course, you won’t be adept to check on all of the apparatus out there, but in addition to the apparatus that you own, you could ask friends, family, other freelancers and coworkers to help you test. You can furthermore visit your local electronics shop to test on the apparatus there.

Check your WordPress theme on multiple apparatus
check your WordPress topic on various devices as often as you can.

A cooperative mail with an allotment of testing recommendations is part 5 of the latest “Build a Responsive Site in a Week” tutorial sequence on .NET publication.


A mobile theme plug-in such as the popular WPtouch plug-in can be a great provisional answer to give mobile users a better know-how on a living website. In most cases, proposing visitors an optimized mobile know-how with the help of a plug-in is probably better than not optimizing at all.

But in the long period, a completely responsive topic has many benefits to a plug-in:

The website can sustain its unique branding across all apparatus.
Users will get the same experience on all devices and thus have fewer problems navigating the website.
The website will be simpler to sustain (the administrator won’t need to establish and update the plug-in).

Responsive topic vs. mobile topic plug-in
a responsive WordPress topic on the left, and a mobile plug-in at work on the right.
Deduction

Responsive world wide web design is often still recounted as a tendency. And some might quietly wish that the tendency will overtake sooner or later. But responsive Web conceives is so much more than a tendency: it’s a new mindset, as has been said:

It’s such a disgrace that Responsive design is often degraded to being a ‘Web conceive trend’. It isn’t. It’s a new mindset.

In a multiple-device world, where the Internet appears to be accessible universal, responsive Web conceive feels so much more like a natural method that is just starting to display its potential.

So, what should our job as topic designers and developers be? Because responsive WordPress topics are still so new and in unchanging development, we must not be afraid to start from scratch, search for improvements and extend discovering. And let’s share our knowledge and know-how with each other along the way.

Thursday, March 14, 2013

Basics Of WordPress Theme Design

A WordPress topic is made up of a number of different files, and they all comprise a seperate part of the sheet; the header will comprise the title and navigation, then the catalogue will comprise the major content area (or on a post, the lone document does the job).

The sidebar, conspicuously comprises the sidebar and the footer comprises the footer and closes off the HTML. This all noise very straightforward, but the significant bit is how you can just have a lone document, change it one time and you will change your whole location. Change your footer and that change will be reflected sitewise, not just on a lone sheet.

desire to conceive a WordPress driven internet message newsletter? No difficulty; just pop it in the sidebar document.

Expanding on this, a post page is made up of four documents (usually): the header.php file for the header, the single.php document for the mail content, the sidebar.php document for the sidebar and the footer.php document for the footer. You can have the same header.php, sidebar.php and footer.php files for the entire site, and so when you make a change, this change arrives directly sitewide.

The admin stuff
Getting started with WordPress theming can be a daunting prospect, and before we start, I’ll say this now; I’m going to suppose a good solid comprehending of both CSS and HTML. Good places to gain this knowledge are CSS-Tricks and Nettuts+.

A twosome of things to sort out first – you’ll need to get yourself a cipher reviewer. If you’re using Windows, the free Notepad++ is an very good device to have and if you’re on a Mac then I’m sure there are abounding of large free reviewers, but the one that every person talks wildly about is called Coda(and it’s not free). If you’re grave about conceive then Coda will be worth it in the long period. The only other fast thing we need to do is install WordPress in the local area. You can find how to do that here.

Conceiving a basic topic
First off, the style.css. This is our stylesheet. This isn’t a conceive series, so I’m not going to dwell on it too much, but there are some significant components of a stylesheet which WordPress desires that notify it some info about the theme. The topic we’ll be creating this week is called Champion. It’s founded on the Default WordPress theme for alleviate of use. Download the topic and unzip it. Open up the style.css file and you’ll glimpse something like this:

/* Theme Name: Designimo
Theme URI: http://wordpress.org
Description: A basic wordpress theme
Author: Hasibul Islam
Author URI: http://webdeveloperszone.com
Version: 1.0
*/

And that’s all you need to make a stylesheet WordPress-ified. After you’ve got that in a stylesheet, you can style as you would commonly.
The index

WordPress has allotments of different template files. They’re all utilised to develop distinct types of post, page, archive etc. A preceding post interprets all, but to give you an idea

For posts, first, WordPress will look for the single.php document, but if it isn’t discovered then it will use the index.php to display the mail.

For scribe archives, first WordPress will look for the author.php document, then the archive.php document and if it can’t find that it’ll use the index.php document to display the scribe archive. It’s the identical with all kinds of mail, sheet or archive; they all revert to the index.php. This is why it is the most significant document of them all.

So let’s get started. Open up the topic files afresh and open the index.php document. We don’t need any other files because as I’ve just sharp out, all kinds of page revert back to the index.php file so to verify the issue, in this part it is the only document we’re going to use. As the week moves on we’ll be supplementing more files back in, don’t concern! Open up the index.php file and gaze for line 49, which starts with:

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

This is the WordPress Loop, and the most important part of any WordPress theme. This part is exciting; we’re using the most important template file and the most important part of any template file!

The loop explained
So what is this Loop? It’s the thing that goes and fetches posts. With the loop started, look at the next couple of lines, ignoring the opening <div>s. They read:

<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2> <?php the_content(); ?>

These are your actual aboriginal arrangement tags. Arrangement tags are pieces of PHP (which consistently alpha and end ) which acquaint WordPress for the accepted post, get this section of information. For example, the aboriginal arrangement tag acclimated here, the_permalink, tells WordPress for the accepted post, get the column permalink. Acclimated central an ballast and you’ve got yourself a hotlink to accepted post. The next arrangement tag, the_title, as you ability accept guessed, outputs the appellation of the post. Add that all together, central an H2 tag and you’ve got yourself a appellation which if clicks goes to the post’s column page.
The final arrangement tag aloft is the_content. This is tells WordPress for the accepted post, go and acquisition the capacity of it and affectation it.
The next part of the file reads (again, ignoring the divs):

<?php endwhile; ?> <php next_posts_link('' Older Entries') ?> <?php previous_posts_link('Newer Entries &raquo;') ?> <?php else : ?> <h2>Not Found</h2> <p>Sorry, but you are looking for something that isn't here.</p> <?php endif; ?>

The first part, endwhile tells WordPress when you’ve completed displaying all the posts, brandish this:. What is brandished are links to older and newer applications utilising the template tags next_posts_link and previous_posts_link.

The next part, additional notifies WordPress if you can’t find any mails, display this:. You’ll glimpse that if no posts are discovered then a ‘Not discovered’ exhibitions. Finally, endif finishes the loop.

So there we have it; the most important part of any WordPress topic; the loop. What we’ve also finished is get presented to template tags. There are quite a couple of to get yourself well known with, and you can find them recorded on the codex.

With the deciphering finished, load up the topic to your WordPress establish and cause it. You’ll see that regardless of only having a stylesheet and a lone index.php file, the topic burdens fine. bang on a mail and you’ll glimpse that gets displayed too. sheets, mail archives, class archives and any page you like work fine too. Going back to what I said previous – all template document hierarchies drop back on the index.php document – this proves it.

This furthermore arises the inquiry – “if I can do all this with a single document, why have more template files?” The answer is customisation. A change to the index.php document will be reflected all through the whole site, so if you just desire to change mail pages then you wouldn’t be (easily, see à) adept to do this, which is why we have distinct template documents (the pedantic might point out you could get aaround this with if declarations, which is factual, but it wouldn’t be especially practical at the end of the day).

Dividing the files
Download the latest exact replicate of our topic and open up the index.php file. First thing that you should observe is that the header has been restored with a part of PHP –

<?php get_header(); ?>.

This is another of WordPress’ template tags, and it’s telling WordPress proceed into the theme documents, find the header.php file and brandish the contents here. As your theme becomes more and more perplexing, this permits you to conceive a single header and use it throughout your topic. At this point, you’re likely opening up the header.php file. Good idea! Upon opening it, you’ll glimpse it’s the identical thing we had beginning off our index.php document. All that has altered is now it has a whole document to itself.
 
Deciphering the header
Before we move on, a twosome of important header points. You’ll observe that the header doesn’t brandish things like your content type, it values template tags (I did state there were lots!) such as:

<?php bloginfo('html_type'); ?>

When this loads, what is displayed is your HTML type – have a look at the source code yourself – text/html gets shown. Template tags such as this one are used throughout the header to get the stylesheet url, title, pingback url etc etc. The reason for this is because every WordPress installation is different and so by using dynamic template tags, you can cater for all of these different installations at once.

The sidebar
Look back in the index file and you’ll see that the sidebar has gone too, and its place <?php get_sidebar(); ?>. Like the header, this tells WordPress go into the theme files, find the sidebar.php file and display the contents here. There’s not much to decipher here; a couple of new template tags and only one completely new thing: widgets, which we’ll discuss further in the last part as it requires the functions.php file.

The footer
The final part of this part’s instalment is going to look at the footer. Like the header and sidebar, it has been removed from the index.php file and now resides in the footer.php file. Again, it is referenced with the <?php get_footer(); ?> function. Nothing much new here; again some more new template tags, but other than that it’s much the same as the index.php file’s footer we had before.
Developing the single.php file

Upon opening the single.php file, it should look pretty familiar; the first line is <?php get_header(); ?> which, as we learnt in the previous part, tells WordPress find the header.php file and display the contents here. Skip a line and you’ll see:

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

That too should look familiar; it’s the loop! Scroll down further and you’ll see a couple of template tags -

<?php the_title(); ?>

and

<?php the_content(); ?>

. After that, scroll down to line 35 and you’ll meet a new template tag:

<?php comments_template(); ?>

Just like get_header, get_sidebar and get_footer, this tells WordPress go and find the comments.php file and display the contents here.  You can probably guess where this is going – get the comments.php file open.
Getting to grips with WordPress’ comments

Open it up and… eek! It’s complicated. The comments file is notorious for being the thing that must be done but no-one really likes doing. But that isn’t going to stop us, is it? No. Let’s get going. The first part of the code just checks to see if the comments file has been loaded directly, and if it has an error message gets displayed. Next, it checks to see if the current post is password protected, and if it is then the user is asked to enter a password to see the page. Leave this bit of code alone; it’s important it is kept and, well, what has it ever done to you?

Next is the bit we’re interested in: the comments loop. It starts by checking if comments are open:

<?php if ( have_comments() ) : ?>

And if they are then some text is displayed, showing the number of comments a post has. Skip a couple of lines to line 28 where an ordered list is opened and inside that ordered list is <?php wp_list_comments(); ?>. This is another of WordPress’ template tags, and it spits out all of a post’s comments. There are other ways of displaying comments (that offer more customisation), but that is a post for another day; as I said, it’s quite a complicated subject.

Gloss over the next part (which is pretty self explanatory) to line 49. Here starts the form that you see on most blogs – this is the part where you fill out your name, email, website and comment. There isn’t really much need to customise this or change it in any way, so we won’t. Instead, we’ll go back to the single.php file and finish up with that.
Finishing off posts

Open up the single.php file again and scroll down to line 37, just after where we left off. Here is something that again should look fairly familiar; it’s the loop finishing off and saying if no posts are found then display this:. The

<?php endif(); ?>

closes off the loop and then we get to the familiar looking get_sidebar and get_footer, which we learnt about in the previous installment of the series.
Creating a page

This tutorial has focused heavily on posts, without a mention of pages. The good news is that pages run identically to posts and so to create a post page, all you have to do is save another copy of your single.php file as page.php. And you’re done. I did say it was simple!
Creating an awesome archive

According to the WordPress file hierarchy (which we discussed earlier), all archives – date, category, author and tag each have their own template file, but they also all fall back on a single file – the archive.php file. The idea here is that if you’re clever, you can save yourself creating a couple of additional files.

Upon opening the file, you’ll be greeted with the familiar get_header and the loop. Then, on line 14 starts a whole load of PHP if statements – if this is a category archive, display this, if this is a tag archive, display this etc etc. After that, on line 37 the loop swings into action and we have the familiar template tags we learnt in part two. Finally, on line 56 the standard “no posts were found” gets replaced with another if statement, changing it to “no posts were found under this category/tag etc etc”. After that, the familiar get_sidebar and get_footer and the archive page ends.

It’s pretty similar to the index.php page, all that is happening is that there are a couple of ifstatements to change the titles according to the archive.
Creating an equally awesome homepage

Something you might have noticed is that so far we haven’t created a specific homepage. Whilst there is a homepage, that’s just the contents of the index.php file. At this point, it’d be appropriate to introduce a new template file: the home.php file. It’s highest in the hierarchy for the homepage, so WordPress first looks for the home.php file and if that doesn’t exist then it uses the index.php, which is why so far we’ve so far been creating a homepage with just the index.php.

Why can’t I just use the index?
Good question. You can’t because the index file is at the bottom of all template hierarchies – if you don’t have a specific template file for a certain type of page then WordPress displays the page using the index.php file. For that reason it is best to leave the index file as it is and create an additional page, home.php for generating a homepage. It’s also one of those useful little tricks that are good to know as it allows you to stop using WordPress as a blogging platform and start using it as a CMS. You can also try out fancy tricks using functions like WordPress’ body_class.

In our example, we’re not going to do anything with our home.php file, other than make it and copy and paste the contents of the index.php file into it, but as someone who is getting started with WordPress theme development, it is something that you should know exists and you’ve always got the option of customising the homepage further yourself.
The functions.php file

This is probably the most powerful template file there is. Effectively, it lets you run plugins from within your theme. It’s not a page that gets displayed, it’s a file that lets you run functions that you can display in other files. Common uses include:

    Widgets! Whilst you put where you want widgets to display in the theme files, but they’re powered from the functions.php file.
    Theme options. Theme options pages are too created from the functions.php file. WPShout has a whole tutorial written on the topic here.
    Language – the functions.php file lets you set up the option for multi-lingual theming.

As the functions file is just so complex, I’ll just cover some basics. The code below will create a widget area ‘Widget area 1’ with an opening div before (which closes after) and the widget title gets an H3 tag:

<?php if ( function_exists('register_sidebar') ) register_sidebar(array( 'name' => ' Widget area 1', 'before_widget' => '<div>', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>', )); ?>

To insert the widget in your sidebar you’ll need to add the following to your sidebar.php file (or wherever you want to widgetise):

<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Widget area 1') ) : ?> <p>This area is widgetised! To make use of this area, put some widgets in the 'Widget area 1' section.</p> <?php endif; ?>

This is just the start though; take a read of thisto find out how to build your own theme options page.