Sometimes you may want to add browser specific stylesheet in WordPress. For example, you want to load a stylesheet when a user visits your site using Internet Explorer ( I know you hate IE ;) ).

You need to detect the browser. WordPress is very handy for detecting browsers using global variables.

To detect if the user is on Internet Explorer, use $is_IE global variable. You may use it like bellow:

Select Code
1
2
3
4
global $is_IE;
if( $is_IE ) {
// do something for IE
}

You may add the condition just before the link tag in header.php file to add a stylesheet in your theme. Like bellow:

Select Code
1
2
3
If( $is_IE ) {
echo<link rel=”stylesheet” media=”all” href=”http://path-to-style.css”/>’;
}

But adding the stylesheet in header.php is not ideal. If you’re developing a theme for personal use, then this is okay but if you are developing the theme for WordPress community, you have to think bit more!

[Read more...]

You have a WordPress blog, you’ve too many posts and you’ve set ‘Posts per Page’ limit for your blog home page. Now you want to add a post pagination for to your blog to make this easier to navigate. Right? If so, I have come up with a solution for you!

WordPress Pagination

WordPress Pagination

“Previous/Next” Pagination Style

If you want to have pagination like “Previous” posts link and “Next” post link, here it is:
Use ‘previous_posts_link()‘ function to output previous posts link and use ‘next_posts_link()‘ function to output next posts link.

It looks like:

Select Code
1
2
3
4
<ul class="post-navigation">
    <li class="prev-link">< ?php previous_posts_link('« Previous' ); // for previous posts ?></li>
    <li class="next-link">< ?php next_posts_link('Next »'); // for next posts ?></li>
</ul>

If you need to use the code in PHP you’ve to use: get_previous_posts_link(). If you use get_previous_posts_link() you’ll need to echo it like bellow:

Select Code
1
2
3
4
<ul class="post-navigation">
    <li class="prev-link">< ?php echo get_previous_posts_link('« Previous' ); // for previous posts ?></li>
    <li class="next-link">< ?php echo get_next_posts_link('Next »'); // for next posts ?></li>
</ul>

[Read more...]