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.

functions file is important in wordpress theme

WordPress is most powerful tool for SEO and bloggers. We all need the custom theme for our projects. When we create custom wordpress theme than functions file important. functions file is important in wordpress theme. Here is information about functions file.

Here is the detailed information about functions.php file. Using this file we can override the wordpress functions or methods and create custom method for our theme requirement.

functions file is important in wordpress theme

A theme can optionally use a functions file, which resides in the theme subdirectory and is named functions.php. This file basically acts like a plugin, and if it is present in the theme you are using, it is automatically loaded during WordPress initialization (both for admin pages and external pages). Suggested uses for this file:

  • Define functions used in several template files of your theme
  • Set up an admin screen, giving users options for colors, styles, and other aspects of your theme

The “Default” WordPress theme contains a functions.php file that defines functions and an admin screen, so you might want to use it as a model. Since functions.php basically functions as a plugin, the Function_Reference list is the best place to go for more information on what you can do with this file.

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 set Media Icons in wordpress theme

Just put some jpg, png or gif files in your theme images folder. In this article we shown to set Media Icons in wordpress theme.

set Media Icons in wordpress theme

  1. your_theme/images/audio.jpg
  2. your_theme/images/audio.gif
  3. your_theme/images/audio.png
  4. your_theme/images/mpeg.jpg
  5. your_theme/images/mpeg.gif
  6. your_theme/images/mpeg.png
  7. your_theme/images/audio_mpeg.jpg
  8. your_theme/images/audio_mpeg.gif
  9. your_theme/images/audio_mpeg.png

Whenever you are putting the media files in post above icons will appear in your theme.

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

How to remove category word from your WordPress URL

This pretty much old article and trick, shown, How to remove category word from your WordPress URL. Now these days many wordpress plugins aviable which will remove cateogry word from wordpress url.

How to remove category word from your WordPress URL

Open your .htaccess file. This file you will find in your root directory.

Just copy and past following code in that file.

RewriteRule ^category/(.+)$ http://images.purabtech.in/$1 [R=301,L]

Don’t forget to replace the purabtech.in/files/ to your site name.

Have fun!

Refer this Remove category slug wordpress from URL and Remove short words from wordpress permalink URL

My Suggestions for Google Top ranking

My Suggestions for Google Top ranking

 

Create City wise Sub domains

like pune.yourdomain.com, Mumbai.yourdomain.com

 

in pune.yourdomain.com upload whole website or redirect to our yourdomain.com site

Another way upload whole website but disable only selected means pune city in search criteria.

 

Google collect all website data every week on Sunday. He catches many types of data like meta description, meta keywords, page information, page name, page content. But Google give First preference to website name than WebPages name (page title).

 

That’s why suggested to create simple city wise and favorite category wise sub domains. This is very powerful system which we have implement and improve.

 

Google can catch our sub domains and there different types of data means specialize (city wise and favorite category wise) information of rental activity in that city or that category.

 

This is technically possible anytime. Not so much hard work. No database mismatch or No additional database required. no additional mail required ( but if we create mail like pune@yourdomain.com, Mumbai@yourdomain.com ) this is very better for Google top ranking. Pune rental requirement come on only pune@yourdomain.com

 

Now we hosted our website in Godaddy.com. We can create 10 sub domain in our hosting plan.

 

This is very simple and achieving idea for Google top ranking.

 

Pl read my Search engine Report because we use Php and Mysql Technology in our Web portal. What Google did for data collection and what criteria they use for ranking or listing of website? I read many articles and used many soft wares and programs for Google ranking.

 

I am pretty glad to tell you. I suggested techniques are very helpful for our achievement.

 

This techniques used by many website like

 

(pune.magicbricks.com, pune.indiaproperty.com, realestate.virtualpune.com, apartment. magicbricks.com, pune.click.in, Bharatmatrimonial.com and many more)

 

Search Engine Optimizing PHP Report

 

PHP pages have a reputation of being more difficult (or at least different) to SEO than static HTML pages. Here?s an overview of the major issues encountered when trying to optimize PHP script for search engines. While this focuses on PHP much of it is still relevant to SEO’ing dynamic pages in general.

PHP Speed

While page size does affect load time, spiders run on servers connected to high bandwidth networks, so download time is less important than the latency of the PHP script?s execution time. If a search engine spider follows a link on a site and is forced to wait too long for the server to process the PHP code behind that page, it may label your page as unresponsive.

The biggest delays in a PHP script typically are the database and loop code. Avoid making SELECT * calls, instead explicitly name all the columns you want to retrieve, and if you are using MySQL, test your queries using the EXPLAIN statement. To optimize loops consider using duplicated code instead of loops that don’t repeat very many times, also use as many static values, such as count($array) values inside the loop as you can, generating their values before the loop once.

URL Cleanliness

A major goal in SEO’ing your PHP pages, is to make them look and act like static pages. If you have a large site you can use Apache to fake static looking URLs, or, with a smaller site, you can simply keep your GET variables to a useful minimum. In either case, however, never allow a spider to see links with different URL?s to the same content. If the URL is different, the page should be too.

One of the major problems most webmasters have with getting their dynamic pages to index is URL cleanliness. Since many dynamic pages are created with GET variables, lots of pages have URLs that look like:

Page.php?var=lkdjdfhv&var2=345&var3=kfjdks

Most of the search engines will be able to follow this link, because it has 3 or under get variables (a good rule of thumb is to keep the number of GET variables passed in the URL to under 3), but any more than 3 variables and you will run into problems. Try using less GET variables, and make them more relevant, rather that useless id numbers use titles, and other keyword rich bits of text. This is an example of a better URL:

Page.php?var=category&var2=topic

If the page requires more variables you may want to consider combining the variables by delimiting them with a hyphen or another unused character, and then splitting the variable in the target page.

Disabling Trans_sid

Possibly the biggest cause of webmaster frustration when SEO?ing php pages is PHP?s tendency to add session id numbers to links if cookies are rejected by the browser (Search engine spiders reject cookies). This will happen by default if your PHP installation was compiled with the ?enable-trans-sid option (and this is the default from version 4.2 onward), and it creates links with an additional, long nonsense looking GET variable. In addition to making the links clunky this gives spiders different URLs with the same content, which makes them less likely to treat the pages individually, and possibly not even index them at all. A quick way to fix this is to disable the trans-id feature, if you have access, in php.ini by setting ?session.use_trans_sid? to false. If you don?t have access to change php.ini you can add this line to the .htaccess file in your root directory:

<IfModule mod_php4.c> php_flag session.use_trans_sid off </IfModule>

Masking dymamic URLs

However the mere presence of a question mark in the URL will introduce a delay in google?s indexing of the page. This from Mike Grehan?s Interview with Daniel Dulitz of Google:

?So the mere presence of a question mark in the URL doesn’t throw us for a loop at all. We will crawl those pages more slowly than we do with pages without question marks in the URL. Purely because they’ve identified themselves as being dynamic and we certainly don’t want to bring anyone’s site down because we’re hitting the database too hard.?

Small sites will not need to worry much about this delay as it means your server is hit every few minutes, not a few times a second, but for larger sites this can slow down your site?s inclusion into the index.

Making dynamic pages look static without mod_rewrite

A way to mask bulky dynamic page URLs (and avoid the question mark delay) is Apache?s ForceType in combination with a PHP command to interpret URLs like: www.example.com/books/computers.html as referring to a page called ?books? which is executed as a PHP script (I usually make a link on the linux server from ?books.php? to ?book? to make editing the script easier). The function will return an array of the additional values, including the category ?computers?. This can be accomplished by inserting a line like this into the .htaccess file in the root of your web documents directory:

<Files *Directory Handle Name Here*> ForceType application/x-httpd-php </Files>

*Directory Handle Name Here* should be replaced with the alias name you are giving to the fake directory you are creating. In this example:

www.example.com/books/computers.html

your .htaccess line would look like this:

<Files books>ForceType application/x-httpd-php</Files>

You can then log into your server and create a link to the file ?books? or whatever directory alias you have choosen. This is done with the linux command “ln”, or link, like this:

$ Ln books.php books

This creates a link between the existing PHP script books.php and the non-existant ?books?. This way all requests for the directory “books” will be given to books.php, ie www.example.com/books/computers.html would be handled by books.php

Inside books.php you can use this function (available here) to extract values from the static-looking request URI?s:


<?php
function processURI() {
    $request = explode(“/”,$_SERVER[“REQUEST_URI”]);
    $count = count($request);     
    for ($i = 1 ; $i < $count ; $i++) {              
        $values[“arg”.$i] = $request[$i];   
    }
    return $values;   
}
?>
1

So the above example of: www.example.com/books/computer.html would be processed like this:


<?php
$vals = processURI();
$_GET[$vals[1]] = str_replace(“.html”, “”, $vals[2]);
?>
1

With this, $_GET[‘books’] would equal “computer” similar to www.example.com/index.php?books=computer

PHP?s SEO Advantages

A great advantage to using dynamic pages as opposed to static pages is the ability to create content that is constantly changing and updated in real time. RSS headlines, randomly circulating content and other automatically ?fresh? content can boost your ranks in Google, and many other engines.

Another advantage to using PHP is that you can make simple modifications to many scripts to create relevant and fresh page titles. Since this is the most important on page factor in SEO special attention should be given to creating title tags that accurately reflect the page?s current content. Any html templates or used in PHP pages can be altered to contain this line:

<title><?=$page_title?></title>

With this, $page_title can be set to a keyword rich test describing the page. Title text is also important in improving the click-through from SERP?s, so be sure that the title tags doesn?t read like spam, but more like a human created title.

 

Create breadcrumb in php – PHP Breadcrumb

breadcrumb is useful for every site. here I explained code about Create breadcrumb in php – PHP Breadcrumb. This code will be helpful for website developers.

Create breadcrumb in php – PHP Breadcrumb

What are breadcrumbs?

How to create the breadcrumbs in wordpress
How to create the breadcrumbs in wordpress

Well quite simply, in web page terms this refers to a list of links (usually at the top) that appear on a web page to tell the user where they are in the structure of the website they are viewing. This makes navigating backward and forward so much easier as they have the ability to skip directly back through whole categories, rather than just using the browser’s back button.

Example

The breadcrumbs.php include file:

Copy the code below, save it in a file called breadcrumbs.php and upload it to your site. This will print out a simple unordered list (<ul>) of the parent directories by directory name. The only edits you may wish to make to this file is to change the $ul_id='crumbs'; line if you wish to change the id of the <ul>. If you wish to add a background image or border etc to the <li> simply select it as #crumbs li{} and style. Script for Create breadcrumb in php:

<?
$ul_id='crumbs';
$bc=explode("/",$_SERVER["PHP_SELF"]);
echo '<ul id="'.$ul_id.'"><li><a href="/">Home</a></li>';
while(list($key,$val)=each($bc)){
$dir='';
if($key > 1){
$n=1;
while($n < $key){
$dir.='/'.$bc[$n];
$val=$bc[$n];
$n++;
}
if($key < count($bc)-1) echo '<li><a href="'.$dir.'">'.$val.'</a></li>';
}
}
echo '<li>'.$pagetitle.'</li>';
echo '</ul>';</pre>
?> This is some more usefull code
<pre><?
$url = $_SERVER['REQUEST_URI'];
echo $url;
echo "<br>";
$array = explode("/",$url);
echo $array[2]; ///which folder would you want to access ?
echo "size of array = ".sizeof($array)."<br>";
?>

Use above script for Create breadcrumb in php.

A script to insert in the HTML where you want the breadcrumbs to appear:

Edit the URI to point to where you saved the include file (once this is done it never needs to be changed again). Edit, ‘Insert Page Title’ to add the page title to the end of the breadcrumbs.

<?
$pagetitle="Insert Page Title";
include("http://www.yourdomain.com/breadcrumbs.php");
?>

Note: It would be useful to automatically print the page <title> as the last crumb but PHP cannot interrogate the DOM. Javascript would be required which we didn’t think appropriate as nothing would be returned if Javascript was turned off.

If you are looking for wordpress breadcrumbs then visit this link

wordpress breadcrumbs without any wp plugin