wordpress pagination style without wordpress plugin

wp-pagenavi is most popular. wordpress pagination style without wordpress plugin, We need to install wp-pagenavi wordpress plugin for pagination styling.  When we think wordpress pagination style then first thing came in mind which is. We need to install wp-pagenavi wordpress plugin for pagination styling. There are multiple pagination plugins available for pagination styling but wp-pagenavi is most popular.

wordpress pagination style without wordpress plugin

I always recommend wordpress theme developers to not to use the wordpress plugins as much possible because any wordpress plugin will install the extra unuseful code also.

wordpress pagination style without wordpress plugin
wordpress pagination style without wordpress plugin

Here in this article I am giving you the example about wordpress pagination without using any wordpress plugin.

Just open your functions.php file and put following code.


function wpapi_pagination($pages = '', $range = 4)
{
 $showitems = ($range * 2)+1;

 global $paged;
 if(empty($paged)) $paged = 1;

 if($pages == '')
 {
 global $wp_query;
 $pages = $wp_query->max_num_pages;
 if(!$pages)
 {
 $pages = 1;
 }
 }

 if(1 != $pages)
 {
 echo "</pre>
<div class="\&quot;wpapi_pagination\&quot;">Page ".$paged." of ".$pages."";
 if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href="&quot;.get_pagenum_link(1).&quot;">« First</a>";
 if($paged > 1 && $showitems < $pages) echo "<a href="&quot;.get_pagenum_link($paged - 1).&quot;">‹ Previous</a>";

 for ($i=1; $i <= $pages; $i++)
 {
 if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
 {
 echo ($paged == $i)? "<span class="\&quot;current\&quot;">".$i."</span>":"<a class="\&quot;inactive\&quot;" href="&quot;.get_pagenum_link($i).&quot;">".$i."</a>";
 }
 }

 if ($paged < $pages && $showitems < $pages) echo "<a href="\&quot;&quot;.get_pagenum_link($paged">Next ›</a>";
 if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a href="&quot;.get_pagenum_link($pages).&quot;">Last »</a>";
 echo "</div>
<pre>\n";
 }
}

Above function will give the wordpress pagination style like google search engine.

Then open style.css file from your wordpress theme file and put following code in that file.


.wpapi_pagination {
clear:both;
padding:20px 0;
position:relative;
font-size:11px;
line-height:13px;
}

.wpapi_pagination span, .wpapi_pagination a {
display:block;
float:left;
margin: 2px 2px 2px 0;
padding:6px 9px 5px 9px;
text-decoration:none;
width:auto;
color:#fff;
background: #555;
}

.wpapi_pagination a:hover{
color:#fff;
background: #3279BB;
}

.wpapi_pagination .current{
padding:6px 9px 5px 9px;
background: #3279BB;
color:#fff;
}

Then finally where you want to show the wordpress pagination there in area put following code (index.php, etc..)


if (function_exists("wpapi_pagination")) {
 wpapi_pagination($additional_loop->max_num_pages);

 

wordpress pagination style without wordpress plugin
wordpress pagination style without wordpress plugin

If you are having any issues or question about adding the wordpress pagination without plugin then please write me.

 

 

convert plain text URI to HTML links in wordpress themes

When you put some URL and email address you need to manually add the link URL to that text. This action always takes the some time of wordpress blogger. WordPress has facility to add the links to your URL and email address automatically.

 

convert plain text URI to HTML links in wordpress

This facility is available in wordpress since wordpress 2.7 version but many wordpress theme and plugin developers never used this functionality.

WordPress provides the make_clickable() function for convert plain text URI to HTML links. This function able to convert URI, www, ftp, and email addresses. Finishes by fixing links within links. You just need to pass the string parameter to this method.

More detail information you can find in following file.
wp-includes/formatting.php.

You can use this method in your functions.php file also. Use the following code.

add_filter('the_content', 'make_clickable');

By using this code you are able to covert the URI, www, ftp, and email addresses in to link.

If you are having any issues or question about make_clickable method then please write to me.

most popular posts wordpress without plugin

Many times you want to show the popular posts in your wordpress theme and you use popular post wordpress plugin or widget for showing the popular posts in your wordpress theme. As much possible you need to avoid the wordpress plugins for minimal code.

most popular posts wordpress without plugin

With very easy steps you can fetch the most popular posts from your wordpress. Most common trick or technique is on comments base you can fetch the popular posts.

You just need to open your functions.php file from wordpress posts and put following code in file.


// Get Most Popular Posts in theme
function popular_posts_by_comments( $posts = 5) {
 $popular = new WP_Query('orderby=comment_count&posts_per_page='.$posts);
 while ($popular->have_posts()) : $popular->the_post();
?>
<li>
<div>
 <a title="<?php the_title(); ?>" href="<?php the_permalink() ?>"><?php the_title(); ?></a>
 <span><?php comments_popup_link('0 Comment', '1 Comment', '% Comments', 'comments-link', ''); ?></span>
 </div> <!--end .info-->
 <div></div>
</li>
<?php endwhile;
}

This is very easy code to fetch you wordpress popular posts. Here I am fetching only 5 popular posts from wordpress. You can fetch the multiple popular posts by changing the $post variable value.

In wordpress theme sidebar or footer section if you want to show the popular post then just use following code.

popular_posts_by_comments();

most popular posts wordpress without plugin
most popular posts wordpress without plugin

where you want to show the popular posts.

show popular posts without wordpress plugin in theme
show popular posts without wordpress plugin in theme

Remove Unwanted Meta Boxes from wordpress dashboard through wordpress theme

When we login to wordpress admin area that time we first saw the admin dashboard. Many tabs and section are not useful in admin dashboard section for wordpress admin and sometimes we don’t know what is that sections.

Remove Unwanted Meta Boxes from wordpress dashboard through wordpress theme

We saw the right now, recent comments, quick press, stat, recent drafts, incoming links, wordpress development blog, other wordpress news, plugins and more sections in wordpress dashboard section. Most of that section are not useful to wordpress admin. So is that better to remove unwanted section from dashboard.

Remove Unwanted Meta Boxes from wordpress dashboard through wordpress theme
Remove Unwanted Meta Boxes from wordpress dashboard through wordpress theme

For disable the dashboard section we are going to use the wp_dashboard_setup method. In wordpress dashboard there are multiple meta boxes listed. some of them as follows:

//Main column
$wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']
$wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']
$wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']
$wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']

//Side Column
$wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']
$wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']
$wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']
$wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']

For removing the widgets or meta boxes from dashboard you need to open your functions.php file from wordpress theme folder and put following code in that file.

function remove_dashboard_meta_boxes(){
  global$wp_meta_boxes;
  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
  unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
  unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}

add_action('wp_dashboard_setup', 'remove_dashboard_meta_boxes')

This code will remove the incoming link, right now, plugins, recent comments and secondary section from wordpress dashboard section.

Remove Unwanted Meta Boxes from wordpress dashboard through wordpress theme
Remove Unwanted Meta Boxes from wordpress dashboard through wordpress theme

If you want the more information about wordpress dashboard widget then check following URL
http://codex.wordpress.org/Dashboard_Widgets_API

If you are having any issue or questions about wordpress dashboard then please write to me.

Create multiple widgets in wordpress theme

WordPress tutorial for, In this article we will show, how to Create multiple widgets in wordpress theme. Widgets for very important in wordpress themes and plugins. First I need to tell you this widget api is located in following file.

wp-includes/widgets.php

For enable the sidebar support in wordpress theme you need to register atleast one sidebar in wordpress api. For enabling the side bar you need to just open the functions.php file and put following code in that file.

if ( function_exists('register_sidebar') )
register_sidebar();

This is enable the global sidebar for your wordpress theme.

If you want multiple sidebar in your wordpress theme then use the following code. I created two sidebars in my wordpress theme. First is normal sidebar and second is footer sidebar.

For main sidebar showing just open your sidebar.php file put following code in that file.


if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Main Sidebar') ) :
 endif;

For showing second widget in footer section open your footer.php file and put following code in that file.


if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer Sidebar') ) :
 endif;

Then go to your widget section through admin panel and select your widget which you want to show in widget sections.

Create multiple widgets in wordpress theme
Create multiple widgets in wordpress theme

If you are having any issues or question about using widget in wordpress theme then write to me.

how to use shortcodes in wordpress posts

Short code api is introduced in wordpress from 2.5 version. Since short code is very popular and used by wordpress plugin developers. Many wordpress theme and plugin developers do use the shortcode api regularly.

how to use shortcodes in wordpress posts

how to use shortcodes in wordpress posts
how to use shortcodes in wordpress posts

Using shortcode api is very easy. If you want to use the shortcode in your wordpress theme then open your functions.php file and put following code. Here is example for using shortcode.


function wordpressapi_content() {

echo "Hello World";

}

add_shortcode('wordpressapi_content', 'wordpressapi_content');

Create any page and just put following line in that post or page.

[wordpressapi_content]

If you put following code in your page or post then you can see the hello world content in your page or post.

If you want to add the google adsence using shortoce then use the following code.


function google_adsence($atts) {
 return ' "<script type="quot;text/javascript"quot;">"<!--
google_ad_client = "quot;ca-pub-4949877136251097"quot;;
/* 160x600, created 4/7/08 */
google_ad_slot = "quot;5503695728"quot;;
google_ad_width = 160;
google_ad_height = 600;
//--">
"</script">
"<script type="quot;text/javascript"quot;
src="quot;http://pagead2.googlesyndication.com/pagead/show_ads.js"quot;">
"</script">
'
}

add_shortcode('google_adsence', 'google_adsence');

Then just put the following words in your post or page or widget section.

[google_adsence]

Your adsence will be displayed. For advanced information about shortcode you should check following URL

http://svn.automattic.com/wordpress-tests/wp-testcase/test_shortcode.php

If you are having any issues or question about shortcode then please write to me.

How to display custom post type on wordpress page

From wordpress 3.0 version we got the custom_post_type method introduced in wordpress api.  Here we shown, How to display custom post type on wordpress page If you want to know how use this method or create the custom post type then use following URL:

How to display custom post type on wordpress page

https://purabtech.in/how-to-use-the-custom-post-type-in-wordpress-3-0/

In this tutorial I will show how to show the custom post type in wordpress theme page. First create custom-post.php page in your wordpress theme folder and use following code.

[/php]

php

/*Template Name: custom post*/

?>

php get_header(); ?>

<div id=”container”>

<div id=”content” role=”main”>

php the_ID(); ?>”

php $recent = new WP_Query(‘post_type=custom_post′); while($recent->have_posts()) : $recent->the_post();?>

php the_title( ‘

‘, ‘

‘ ); ?>

<div>

php the_content(); ?>

php

the_content();
global $post;
$custom = get_post_custom($post->ID);
echo $custom_meta = $custom[“custom_meta”][0];

?>

php wp_link_pages( array( ‘before’ => ‘

‘ . __( ‘Pages:’, ‘wordpressapi’ ), ‘after’ => ‘

‘ ) ); ?>

php edit_post_link( __( ‘Edit’, ‘wordpressapi’ ), ”, ” ); ?>

</div><!– .entry-content –>

php comments_template( “, true ); ?>

php endwhile; ?>

</div><!– #content –>

</div><!– #container –>

php get_sidebar(); ?>

php get_footer(); ?>

[/php]

Then go to your wordpress admin panel and create page called custom page and from right side panel you will find the page attribute section use the template drop down and choose the custom post option.

How to display custom post type on wordpress page
How to display custom post type on wordpress page

Now you are set for showing your custom post type in custom page. Open your custom page on that page you will see all the entries of custom post type.

For more detail information about custom post type and using this check above URL.

optimize wordpress database using phpmyadmin

Sometimes our wordpress tables became so big and we need to worry about wordpress database and table size. Big table always take extra time to execute the query. For this issue we need to keep our wordpress tables clean and do optimization time to time.

optimize wordpress database using phpmyadmin

Optimize wordpress database using phpmyadmin. For optimization, We used 2 tools which are reliable. We used wp-optimize wordpress plugin and PhpMyAdmin tool.

WP-Optimize is a wordpress database cleanup and optimization tool. It doesn’t require PhpMyAdmin to optimize your database tables. It allows you to remove post revisions, comments in the spam queue, un-approved comments within few clicks.

optimize wordpress database using phpmyadmin
optimize wordpress database using phpmyadmin

Second tool I used which is PhpMyAdmin. Using know which tables are over flowing and over size. In wp-optimize panel you will which tables are needed the optimization. Just open your phpmyadmin and select your wordpress database. Click on”Check tables having overhead” link, that will select the overhead tables from your wordpress database. Than just select the Optimize table option.

optimize wordpress database using phpmyadmin
optimize wordpress database using phpmyadmin

This action will just execute the following query.


optimize  table wp_posts, wp_comments;

if you want to optimize another tables then just use the above query. OPTIMIZE TABLE should be used if you have deleted a large part of a table or if you have made many changes to a table with variable-length rows (tables that have VARCHAR, VARBINARY, BLOB, or TEXT columns). Deleted rows are maintained in a linked list and subsequent INSERT operations reuse old row positions. You can use OPTIMIZE TABLE to reclaim the unused space and to defragment the data file.

For MyISAM tables, OPTIMIZE TABLE works as follows:

  1. If the table has deleted or split rows, repair the table.
  2. If the index pages are not sorted, sort them.
  3. If the table’s statistics are not up to date (and the repair could not be accomplished by sorting the index), update them.

If you having any issues or question about optimizing table then please do write to me.

custom post type permalink not working wordpress

From WordPress 3.0 version we are able to use the custom_post_type. In installation time of theme or plugin new permalink structure will be created and you can easily able to use the custom post type permalink.

custom post type permalink not working wordpress
custom post type permalink not working wordpress

If your custom_post_type function is having some issues then wordpress permalink for your custom post type will not work. If your custom post type permalink is not working properly then normally you will get the 404 page and message saying page not found.
Your wordpress does not create the permalink structure aumatically so you need to recreate the Rewrite rules again with wordpress.

If you not added following code in you custom_post_type function then please add the following code:

'rewrite' => array(
 'slug' => 'issue',
 'with_front' => FALSE,
 ),

The right way to use rewrite rule in function is as follows;

register_post_type( 'movies',
 array( 'label' => __('Movies')
, 'public' => true,
'show_ui' => true ,
'rewrite' => array( 'slug' => 'movies', 'with_front' => false )
 ) );

If you are still facing issue and 404 page is coming then go the your wordpress panel -> setting- > permalink page and hit save changes button.
That will flushes the rewrite rules and build rewirte rules again in wordpress.

how to serve wordpress images from subdomain

creating sub domain for wordpress images is best way to increase your wordpress site speed. We given steps to, how to serve wordpress images from sub domain. Many shared hosting and wordpress bloggers and  websites are using the apache web server for hosting the wordpress sites. Apache Web server is having his own rules and behavior. By default when you open webpage of your website. That time you are making so many requests to apache web server with same domain name. That will create queue to apache web server with same domain name.

how to serve wordpress images from subdomain

For reducing the load time you should keep image file on different sub domain. Means though image subdomain you can send a parallel request to Apache web server. It will reduce the concurrent connections to web server. WordPress provides the functionality to set different domain or sub domain for images.

In this article I will show you how easily you can set the wordpress images from sub domain. First create subdomain through your control panel. Use following step for creating subdomain.

how to serve wordpress images from subdomain
how to serve wordpress images from subdomain

I recommend to create the images subdomain because images subdomain is good for SEO. Here I created the purabtech.in/files/ subdomain for my images. Then set your wordpress images path in document root setting. Normally your wordpress images are stored in wp-content/uploads directory. You can use following setting for setting the document root.

how to serve wordpress images from subdomain
how to serve wordpress images from subdomain

After creating subdomain for images and setting up the correct document root for images subdomain. Go to your wordpress admin panel. From right side panel you should go to settings -> Media panel. This page will look like as follows:

how to serve wordpress images from subdomain
how to serve wordpress images from subdomain

In “Full URL path to files” textbox put your image subdomain name and click on save changes button. Uncheck the organize my uploads into month- and year-based folder option because which is not good for SEO purpose.

After this your images will come from image subdomain but old uploaded image files will still come from older location and same domain. For changing the older images file location and domain information you should use the following steps.

Go to your Mysql databases and select the your wordpress database. You can use the phpmyadmin sql manager for this or you can use command prompt for this if you are having dedicated hosting server. If you taken shared hosting then I recommend to use PhpMyAdmin.

Use following two SQL query: (Note: You should use your images subdomain and your domain name in SQL query)


UPDATE wp_posts SET post_content = REPLACE(post_content,'http://images.purabtech.in/','http://images.purabtech.in/');

UPDATE wp_posts SET guid = REPLACE(guid,'http://images.purabtech.in/','http://images.purabtech.in/');

After this your old images files will point to images subdomain. If your images and wordpress website is old then google and other search engines already indexed your images. So We need to write the redirection rewrite rule for images in your .htaccess file. This file you will find in your Root directory of wordpress installation.

Use following line of code in your .htaccess file.


RewriteEngine On
RewriteBase /

RedirectMatch 301 ^/wp-content/uploads/(.*)$ http://images.purabtech.in/$1

Above all steps are important to change the wordpress images into images subdoamin. If you are having any issues or questions about this article. Then please write to me.