How to create simple wordpress theme

If you are new to develop wordpress theme then just use following steps to create the theme. Here we given very simple steps to create simple wordpress theme. Just follow our steps and create basic and simple wordpress theme.

How to create simple wordpress theme

For wordpress theme only two files are required.

  1. style.css
  2. index.php

Only with these two files you are able to create the basic theme of wordpress

How above file should be written. Following necessary code you need to put in that file.

Style.css

/*
Theme Name: WordPressapi
Theme URI: wordpressapi-homepage
Description: a-brief-description of theme
Author: your-name
Author URI: your-URI
Template: use-this-to-define-a-parent-theme--optional
Version: a-number--optional
.
General comments/License Statement if any.
.
*/
Under this you can put your css code.

Index.php

<?php

if (have_posts()) : while (have_posts()) : the_post();

//following line will fetch the post and page code.
the_content();
endwhile; endif;

?>

how to use conditional tags in wordpress

In this tutorial we are going to show you, how to use conditional tags in wordpress. We given code sample for wordpress theme. How to check page is subpage or parent page.

We got this particular requirement of wordpress menus. For that we need many times parent page menu and sub pages as submenu.

how to use conditional tags in wordpress

Using following code we can able to find the parent page and sub pages from wordpress themes. Following code we can put any where in page or code. We can put this code in header.php or index.php or footer.php or anywhere, as per our requirement.


<?php

global $post;&nbsp;&nbsp;&nbsp;&nbsp; // if outside the loop

if ( is_page() && $post->post_parent ) {

// This is a subpage

} else {

// This is not a subpage

}

?>

If you want use or add the is_subpage() method then you need to add the following code in functions.php file.


<?php

function is_subpage() {

global $post;&nbsp;// load details about this page

if ( is_page() && $post->post_parent ) {&nbsp; // test to see if the page has a parent

$parentID = $post->post_parent;&nbsp;// the ID of the parent is this

return $parentID;&nbsp;// return the ID

} else {&nbsp;// there is no parent so...

return false; // ...the answer to the question is false

};

};

?>

how to use of conditional tags in wordpress

The Conditional Tags  are most useful in creating the wordpress themes and plugins. use of conditional tags in wordpress is necessary in custom themes. The Conditional Tags can be used in your Template files to change what content is displayed and how that content is displayed on a particular page depending on what conditions that page matches.

how to use of conditional tags in wordpress

Conditional tag will return the TRUE OR FALSE. Based on return value we can set the conditions. Some useful and most important conditional tags as follows:

is_home()

When the main blog page is being displayed.

is_front_page()

When it is the front of the site displayed, whether it is posts or a Page. Returns true when the main blog page is being displayed

is_admin()

When the Dashboard or the administration panels are being displayed.

is_single()

When any single Post page is being displayed.

is_single('17')

When Post 17 is being displayed as a single Post.

is_single('Irish Stew')

When the Post with Title “Irish Stew” is being displayed as a single Post.

is_single('beef-stew')

When the Post with Post Slug “beef-stew” is being displayed as a single Post.

is_single(array(17,'beef-stew','Irish Stew'))

Returns true when the single post being displayed is either post ID 17, or the post_name is “beef-stew”, or the post_title is “Irish Stew”.

is_page()

When any Page is being displayed.

is_page('42')

When Page 42 (ID) is being displayed.

is_page('About Me And Joe')

When the Page with a post_title of “About Me And Joe” is being displayed.

is_page('about-me')

When the Page with a post_name (slug) of “about-me” is being displayed.

is_page(array(42,'about-me','About Me And Joe'))

Returns true when the Pages displayed is either post ID 42, or post_name “about-me”, or post_title “About Me And Joe”.

How To Use Template Tags In WordPress Theme

What is meaning of a Template Tag in WordPress

A template tag is code that instructs WordPress to “do” or “get” something. In the case of the header.php template tag for your WordPress site’s name, it looks like this:

php bloginfo(‘name’); ?> // this will print the blog name

Following are the more public methods.

name php bloginfo('name'); ?>

As mentioned, this displays the name of the site and is set by the administrator in the Options > General SubPanel by default.

description php bloginfo('description'); ?>

This is called the “Tagline” for your blog which is usually some kind of descriptive sentence that says “My blog is about….”. It is set by the administrator in the Options > General SubPanel.

url php bloginfo('url'); ?>

When you want to display the URL or website address for your WordPress site, you can use URL and it will show up. This also comes from the Options > General SubPanel.

admin_email php bloginfo('admin_email'); ?>

If you want to display the email of the administrator, you don’t have to type it into the template files. By doing so, it may be open to email harvesters who use sophisticated software to come in and grab email addresses to use for spam. By using bloginfo('admin_email'), the email is displayed on the page for the viewers, but the actual email address is disguised from the harvesters. Nice, huh? The administrator’s email address is set in the Options > General SubPanel.

version bloginfo('version'); ?>

Sometimes you’d like to show off which version of WordPress you are using. The Themes that come with WordPress by default include this information in the footer template. It simply displays the version of WordPress your blog uses.

Basic CSS rules for development of WordPress themes

Whenever you are developing the new wordpress theme, you need to put some css in your style.css file. If you are not adding that css in your theme then there is a lot of changes to break your theme view.

Some classes which are needful for image and alignment purpose. You need to just copy paste following CSS code in your style.css file.

.aligncenter,

div.aligncenter {

display: block;

margin-left: auto;

margin-right: auto;

}

.alignleft {

float: left;

}

.alignright {

float: right;

}

.wp-caption {

border: 1px solid #ddd;

text-align: center;

background-color: #f3f3f3;

padding-top: 4px;

margin: 10px;

/* optional rounded corners for browsers that support it */

-moz-border-radius: 3px;

-khtml-border-radius: 3px;

-webkit-border-radius: 3px;

border-radius: 3px;

}

.wp-caption img {

margin: 0;

padding: 0;

border: 0 none;

}

.wp-caption p.wp-caption-text {

font-size: 11px;

line-height: 17px;

padding: 0 4px 5px;

margin: 0;

}

You can edit some CSS as per theme requirement also.

Following CSS classes are also useful for creating the WordPress theme. You can create these CSS classes as per your theme requirement.

.categories {…}

.cat-item {…}

.current-cat {…}

.current-cat-parent {…}

.children {…}

.pagenav {…}

.page_item {…}

.current_page_item {…}

.current_page_parent {…}

.current_page_ancestor {…}

.widget {…}

.widget_text {…}

.blogroll {…}

.linkcat{…}

How to display recent posts from category

In custom themes, we choose category to show the posts from which will be a good trick. In this article we given code for display recent posts from category.

How to display recent posts from category

Use following code for showing the recent post from category:


<?php
query_posts('showposts=1&cat= get_cat_id('category_name')');
while(have_posts()) : the_post();
?>
<h3>php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></h3>
<pre>
<?php the_content(); ?>
<?php endwhile; ?>

You can replace the category_name to your category name