WordPress Theme Template Files List

Here is the list of files which are required in wordpress theme. Whenever you are creating the new theme for wordpress, make sure that following files are present in your theme.

WordPress Theme Template Files List

  • style.css

The main stylesheet. This must be included with your Theme, and it must contain the information header for your Theme.

  • index.php

The main template. If your Theme provides its own templates, index.php must be present.

  • comments.php

The comments template. If not present, comments.php from the “default” Theme is used.

  • comments-popup.php

The popup comments template. If not present, comments-popup.php from the “default” Theme is used.

  • home.php

The home page template.

  • single.php

The single post template. Used when a single post is queried. For this and all other query templates, index.php is used if the query template is not present.

  • page.php

The page template. Used when an individual Page is queried.

  • category.php

The category template. Used when a category is queried.

  • tag.php

The tag template. Used when a tag is queried.

  • taxonomy.php

The term template. Used when a term in a custom taxonomy is queried.

  • author.php

The author template. Used when an author is queried.

  • date.php

The date/time template. Used when a date or time is queried. Year, month, day, hour, minute, second.

  • archive.php

The archive template. Used when a category, author, or date is queried. Note that this template will be overridden by category.php, author.php, and date.php for their respective query types.

  • search.php

The search results template. Used when a search is performed.

  • 404.php

The 404 Not Found template. Used when WordPress cannot find a post or page that matches the query.

How to show or exclude Certain Categories in a Menu – WordPress

If you want show only some categories in wordpress menu than use following command in header.php.

<ul style=”float:left; width:840px;”>
php wp_list_categories(‘orderby=name&include=5,4,8,9,52,65,35’); ?>
ul>

If you want exclude some categories in wordpress menu than use following command in header.php.

840px;”>
php wp_list_categories(‘orderby=name&exclude=5,4,8,9,52,65,35’); ?>
</ul>

Following Options we can use with “wp_list_categories” method.

<?php wp_list_categories( $args ); ?>

args = array(
'show_option_all' => ,
'orderby' => 'name',
'order' => 'ASC',
'show_last_update' => 0,
'style' => 'list',
'show_count' => 0,
'hide_empty' => 1,
'use_desc_for_title' => 1,
'child_of' => 0,
'feed' => ,
'feed_type' => ,
'feed_image' => ,
'exclude' => ,
'exclude_tree' => ,
'include' => ,
'current_category' => 0,
'hierarchical' => true,
'title_li' => __( 'Categories' ),
'number' => NULL,
'echo' => 1,
'depth' => 0 ); ?>

 

By default, the usage shows:

  • No link to all categories
  • Sorts the list of Categories by the Category name in ascending order
  • Does not show the last update (last updated post in each Category)
  • Displayed in an unordered list style
  • Does not show the post count
  • Displays only Categories with posts
  • Sets the title attribute to the Category Description
  • Is not restricted to the child_of any Category
  • No feed or feed image used
  • Does not exclude any Category and includes all Categories
  • Displays the active Category with the CSS Class-Suffix ‘ current-cat’
  • Shows the Categories in hierarchical indented fashion
  • Display Category as the heading over the list
  • No SQL LIMIT is imposed (‘number’ => 0 is not shown above)
  • Displays (echos) the categories
  • No limit to depth
  • All categories.

Show Random Posts on page with WordPress

If you want to show random posts each time a client visits. There are many wordpress plugins which will give similar functionality. We have simple code for showing random posts which you need add in your wordpress theme.

Show Random Posts on page with WordPress

You need to create random.php page in your template.  In that page just copy paste the following code:


<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
query_posts(array('orderby' => 'rand', 'showposts' => 1));
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<h1>php the_permalink() ?>"><!--?php the_title(); ?--></h1>
<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php the_content(); ?>

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php endwhile;
endif; ?>

Than create page through wordpress admin panel and select the random page template.

random-wordpress-posts
Show Random Posts on page with WordPress

How to add flash intro in sites and flash with wordpress

If want to ingrate flex or flash with wordpress. Using following steps and code you can add the flash player or flex in your wordpress theme.

 

Many wp developer are looking for wordpress flash header, wordpress flash gallery, wordpress flash player, wordpress flash intro. They want to integrate flex or flash with wordpress. Using following steps and code you can add the flash player or flex in your wordpress theme.

flash with wordpress

 

Follow my steps to create flash intro in wordpress sites.

1. Create file named intro.php and just copy paste following code:

[viral-lock message=”Solution code is Hidden! It’s Visible for Users who Liked/Shared This article on Facebook or Twitter or Google+. Like or Tweet this article to reveal the content.”]

<?php

/*

Template Name: intro

*/

if (have_posts()) : while (have_posts()) : the_post();
the_content();
endwhile; endif;

?>

[/viral-lock]

2. Upload intro.php file in your active theme folder.

3. Login to wordpress admin area. Click on Pages- >Add new button

4. Page title shoule be “intro” and use html mode and copy paste the your flash intro code in that page.

flash with wordpress
flash with wordpress

5. In attribute section you will find the Template option. Choose the intro option and publish the page.

flash with wordpress
How to add the flash intro in wordpress sites, flash with wordpress

 

6. Go to Setting->Reading tab and Choose the Static page check box and select the “intro” option for “Front page” and click on save changes button. That sit

Here is some useful articles link from wordpress. If you want to show pdf in post on wordpress  and  add feedburner subscribe popup to wordpress. There all types of wordpress tutorial can be found in this site.

 

Php Mysql Question and Answers for Interview

What is the difference between PHP4 and PHP5?
PHP4 cannot support oops concepts and Zend engine 1 is used.
PHP5 supports oops concepts and Zend engine 2 is used.
Error supporting is increased in PHP5.
XML and SQLLite will is increased in PHP5.Can we use include(abc.PHP) two times in a PHP page makeit.PHP”?
Yes we can include that many times we want, but here are some things to make sure of:
(including abc.PHP, the file names are case-sensitive)
there shouldn’t be any duplicate function names, means there should not be functions or classes or variables with the same name in abc.PHP and makeit.php

How i can get ip address – REMOTE_ADDR – the IP address of the client
REMOTE_HOST – the host address of the client, if available

What is the difference between echo and print statement? – echo() can take multiple expressions,Print cannot take multiple expressions.
echo has the slight performance advantage because it doesn’t have a return value.
True, echo is a little bit faster.

How we know browser properties -echo $_SERVER[‘HTTP_USER_AGENT’] . “<hr /> “;
$browser = get_browser();
foreach ($browser as $name => $value) {
echo “<b>$name</b> $value <br /> “;
}

How i will check that user is, logged in or not. i want to make it a function and i want to use in each page and after login i want to go in current page(same page. where i was working)

What is difference between require_once(), require(), include(). Becouse above three function usely use to call a file in another file.
Difference between require() and require_once(): require() includes and evaluates a specific file, while require_once() does that only if it has not been included before (on the same page).
So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don’t include the file more times and you will not get the “function re-declared” error.
Difference between require() and include() is that require() produces a FATAL ERROR if the file you want to include is not found, while include() only produces a WARNING.
There is also include_once() which is the same as include(), but the difference between them is the same as the difference between require() and require_once().

How do I generate a random number from-php?
srand((double)microtime()*1000000);
echo rand(0,100);

How do I set the browser timeout?
set_time_limit(900);
this sets the timeout too 900 seconds / 15 minutes.

How can I do error handling in php?

Is it possible to connect to a ftp server with php?
Yes it is possible, you can use the ftp_connect function. (PHP 3>= 3.0.13, PHP 4 >= 4.0b4)

How do I find out how a user came to my page?
You have the variable $HTTP_REFERER which holds the page that refered to you page, if there are any referer, ie if the user enters your url directly the referer variable will be empty.

How can I add text to an image?
array imagettftext ( resource $image, float $size, float $angle, int $x, int $y, int $color, string $fontfile, string $text )
how to rotate an image using php code?
$move90 = imagerotate($myimage,90);
//$myimage is the reference to the loaded image, eg through imagecreatefromjpeg

How do I find the size of an array? –use Count function
$values = range(“A”,”Z”);
echo count($values);

How do I remove escape characters from data?
$data = “I\’m the king of the castle”;
echo stripslashes($data); //I’m the king of the castle

What are magic quotes?
Magic quotes is a configuration setting within PHP that means that all data containing a single or double quote, or NUL, will automatically be escaped with a backslash before being entered into a database.

How can we encrypt the username and password using PHP?

What is the difference between $message and $$message?
$message is a simple variable whereas $$message is a reference variable.

What are the differences between DROP a table and TRUNCATE a table?

What’s the difference between md5(), crc32() and sha1() crypto on PHP?
The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.

How to set cookies?
setcookie(’variable’,’value’,’time’)
;

Important mysql queries

I written article for my personal purpose. I am using some mysql query on daily. I created the list of my Important mysql queries.

Important mysql queries

Taking backup of all mysql databases

>mysqldump -uroot -p --all-databases >> all_database_dump.sql;

for single database

mysqldump -uroot -p public_wordpressmu wp_1_posts > one.sql

database import from sql file

mysql –verbose -uroot -p public_wordpressmu wp_1_posts < one.sql

Creating Trigger

create trigger
DROP TRIGGER wordpress.after_wp_1_post_update;

delimiter //

CREATE TRIGGER wordpressmu.after_wp_1_post_update

AFTER UPDATE ON wordpressmu.wp_1_posts

FOR EACH ROW

IF new.post_status = ‘publish’ THEN

INSERT INTO .article_posts (id,ref_id, title, status,
comments_on, created_at, updated_at) values (new.id,new.id,
new.post_title, new.post_status, 1, new.post_date, new.post_date);

END IF;

//

delimiter ;

Insert from different table (migration)

INSERT INTO database_anme.TableName(id, ref_id, title, status, comments_on, created_at, updated_at) select id, id, post_title, post_status, 1, post_date,post_date from wordpress.wp_1_posts

Update multiple rows in through Sql query

Update user set status=”ok” where id in (2 ,3 ,4 ,5,6)

changing all post path and image path
UPDATE wp_1_posts SET post_content = REPLACE(post_content, ‘test.siwan.com’, ‘www.siwan.com’);

WordPress -fetching category through sql queryfrom post

SELECT wp_1_term_taxonomy.taxonomy, wp_1_term_relationships.object_id, wp_1_terms.name, wp_1_posts.post_title
FROM wp_1_posts INNER JOIN ((wp_1_terms INNER JOIN wp_1_term_taxonomy ON wp_1_terms.term_id = wp_1_term_taxonomy.term_id) INNER JOIN wp_1_term_relationships ON wp_1_term_taxonomy.term_taxonomy_id = wp_1_term_relationships.term_taxonomy_id) ON wp_1_posts.ID = wp_1_term_relationships.object_id
WHERE wp_1_term_taxonomy.taxonomy=’category’ and wp_1_term_relationships.object_id=’217′
ORDER BY wp_1_term_relationships.object_id ;

CREATE DATABASE DB-NAME;
CREATE USER ‘DB-NAME’@’localhost’ IDENTIFIED BY ‘DB-NAME@123’;
grant all on USER-NAME.* to ‘DB-NAME’@’%’ identified by ‘DB-NAME@123’;
grant all on USER-NAME.* to ‘DB-NAME’@’localhost’ identified by ‘DB-NAME@123’;
FLUSH PRIVILEGES;

solution for plugins are not working on wordpress theme

solution for plugins are not working on wordpress theme. Whenever you developing the new theme. You need to add following code in your theme file.

solution for plugins are not working on wordpress theme

</p>
wp_head();

Goes in the HTML <head> element of a theme; header.php template. Example plugin use: add javascript code.

Usage: <?php do_action('wp_head'); ?>

-or- <?php wp_head(); ?>

wp_footer

Goes in the “footer” of a theme; footer.php template. Example plugin use: insert PHP code that needs to run after everything else, at the bottom of the footer.

Usage:


<tt><?php do_action('wp_footer'); ?></tt>

-or-

</tt>

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

wp_meta();

 

Typically goes in the <li>Meta</li> section of a theme's menu or sidebar; sidebar.php template. Example plugin use: include a rotating advertisement or a tag cloud.

Usage:


<tt><?php do_action('wp_meta'); ?></tt>

-or-

</tt>

<tt><?php wp_meta(); ?></tt>

comment_form

Goes in comments.php and comments-popup.php, directly before the comment form's closing tag (</form>). Example plugin use: display a comment preview.

Usage:

</tt>

<tt><?php do_action('comment_form', $post->ID); ?></tt>

Note: don’t forget to add wp_head, wp-footer and wp_meta methods in you theme.

How to set different layout for each category in WordPress

In this article we given full steps and code for How to set different layout for each category in WordPress. Which you need to use in your wordpress theme.

How to set different layout for each category in WordPress

Using following code you can able to set different layout for each category.

Just create the category.php file or already existed then open that file and use following code in that file.


<?php

if (is_category(10)) {

// looking for category 10 posts

include(TEMPLATEPATH . '/layout2.php');

// or you can use “get_cat_id(’category_name’)” instead of category id

} else {

// put this on every other category post

include(TEMPLATEPATH . '/layout1.php');

}

?>

Here we are calling the layout 2 for category 10.

Have fun!

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;

?>

Where to find wordpress API

WordPress is widely used CMS in the world. There are many developers who are looking for wordpress api. Where to find wordpress API. We have list is here

Where to find wordpress API

Plugin API
http://codex.wordpress.org/Plugin_API
XML-RPC Support
http://codex.wordpress.org/XML-RPC_Support
API Keys for dashboard
http://en.wordpress.com/api-keys/
This is api site of wordpress- uncomplete
http://api.wordpress.org/