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.

how to create contact us page without plugin

Every wordpress site is need to contact us page for there website or blog. All the people use the wordpress plugin for creating the contact us page. When you install the wordpress plugin that will install some extra code to your wordpress site. After using wordpress plugin you need some customization in that plugin due to UI. You need R&D time and development time. Code for contact us page without plugin.

contact us page without plugin

In this article I will show how you can create the contact us page with out any wordpress plugin. Using following code you can create the contact us form very easily.

First create contact-us.php page in your wordpress theme folder and put following code in that file.

[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: Contact Us
*/
if($_POST[sent]){
 $error = "";
 if(!trim($_POST[your_name])){
 $error .= "<p>Please enter your name</p>";
 }
 if(!filter_var(trim($_POST[your_email]),FILTER_VALIDATE_EMAIL)){
 $error .= "<p>Please enter a valid email address</p>";
 }
 if(!trim($_POST[your_message])){
 $error .= "<p>Please enter a message</p>";
 }
 if(!trim($_POST[your_subject])){
 $error .= "<p>Please enter a message</p>";
 }
 if(!$error){
 $email = wp_mail(get_option("admin_email"),trim($_POST[your_name])." sent you a message from ".get_option("blogname"),stripslashes(trim($_POST[your_message])),"From: ".trim($_POST[your_name])." <".trim($_POST[your_email]).">\r\nReply-To:".trim($_POST[your_email]));
 }
}
?>
<?php get_header(); ?>
<div id="container">
 <div id="content" role="main">
 <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
 <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
 <h1><?php the_title(); ?></h1>
 <div>
 <?php if($email){ ?>
 <p><strong>Message succesfully sent. I'll reply as soon as I can</strong></p>
 <?php } else { if($error) { ?>
 <p><strong>Your messange hasn't been sent</strong><p>
 <?php echo $error; ?>
 <?php } else { the_content(); } ?>
 <form action="<?php the_permalink(); ?>" id="contact_me" method="post">
 <input type="hidden" name="sent" id="sent" value="1" />
 <div id="form">
 <div id="lebel">Your Name (required)</div>
 <div id="input-field"><input type="text" name="your_name" id="your_name" value="<?php echo $_POST[your_name];?>" /></div>
 <div id="lebel">Your Email (required)</div>
 <div id="input-field"><input type="text" name="your_email" id="your_email" value="<?php echo $_POST[your_email];?>" /></div>
 <div id="lebel">Subject</div>
 <div id="input-field"><input type="text" name="your_subject" id="your_subject" value="<?php echo $_POST[your_subject];?>" /></div>
 <div id="lebel">Your Message(required)</div>
 <div id="input-field"><textarea name="your_message" id="your_message"><?php echo stripslashes($_POST[your_message]); ?></textarea></div>
 <div id="lebel"> </div>
 <div id="input-field"><input type="submit" name = "send" value = "Send email" /></div>
 </div>

 </form>
 <?php } ?>
 </div><!-- .entry-content -->
 </div><!-- #post-## -->
 <?php endwhile; ?>
 </div><!-- #content -->
</div><!-- #container -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>

[/viral-lock]

Then go to your wordpress admin panel. Create page called contact us. In Right side panel you will find the “page attribute” section. From template drop down choose the Contact Us option. and create the contact us page.

contact us page without plugin
contact us page without plugin

WordPress uses the wp_mail() function for sending the email. all wordpress plugin also use the wp_mail() function for sending the email.

If you are having issues with sending the email with this function then you should use the different SMTP mail server for sending mail.

For sending email through SMTP  in detail you should check the following article.

https://purabtech.in/send-smtp-email-wordpress-plugin/

With this code you can write your own CSS for styling the contact form as per your wordpress theme. If you are having any issues or question about this script then please write to me.

All wordpress websites has requirement to add the contact form in there website. We always searching for wordpress contact form code, wordpress simple contact form, wordpress contact form with captcha, wordpress default contact form, wordpress contact form without plugin, wordpress contact form not sending email, wordpress custom contact form, best wordpress contact form solution. We can easily add the contact form without using any wordpress plugin very easily. You can use the my code snippet in your wordpress theme and you will be able to add the wordpress contact form.

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 show featured posts in wordpress homepage

For show featured posts in wordpress on home page. You can select article to show on home page. We have code snippet for show featured posts in wordpress. Showing featured post is good for seo also. Important and selected article you can show on home always. Featured post is great functionality introduced by wordpress.

show featured posts in wordpress

Some times we want to need to show featured posts in wordpress blogs on home page. You can select most popular or nice articles to show on home page. In this tutorial I will will show how you can show the featured wordpress posts on home page.

There is very simple way to show featured post on home page. First you need to create featured wordpress category and whatever post you want to show as featured post that posts select under featured post.

Then use following code:

<?php
  query_posts('category_name=featured&posts_per_page=5');
  if (have_posts()) : while (have_posts()) : the_post();
?>
<?php the_title(); ?>
<?php the_excerpt(); ?>
<?php endwhile; endif; ?>

Above code you need use in index.php and single.php file. Or you can following code for showing featured wordpress post.

 <?php while ( have_posts() ) : the_post() ?>

      <?php  if(get_post_meta($post->ID, 'type', true) == "featured") {; ?>
  <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark">
<img src="<?php echo get_post_meta($post->ID, 'intro_thump', true); ?>" alt="Icon for Post #<?php the_ID(); ?>" />
</a></h2>
<?php  }; ?>
<div class="entry-content">

     </div><!– .entry-content –>
<?php endwhile; ?>
show featured posts in wordpress
show featured posts in wordpress

wordpress plugin create table on activation

WordPress plugin tutorial, wordpress plugin create table on activation, If you are making plugin and in plugin many times we need to create new tables. In this article I will show you how easily we can create the wordpress plugin.

wordpress plugin create table on activation

wordpress plugin create table on activation
wordpress plugin create table on activation

Using following code you can create the table in wordpress database.

global $jal_db_version;
$jal_db_version = "1.0";

function jal_install () {
   global $wpdb;
   global $jal_db_version;

   $table_name = $wpdb->prefix . "liveshoutbox";
   if($wpdb->get_var("show tables like '$table_name'") != $table_name) {

      $sql = "CREATE TABLE " . $table_name . " (
	  id mediumint(9) NOT NULL AUTO_INCREMENT,
	  time bigint(11) DEFAULT '0' NOT NULL,
	  name tinytext NOT NULL,
	  text text NOT NULL,
	  url VARCHAR(55) NOT NULL,
	  UNIQUE KEY id (id)
	);";

      require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
      dbDelta($sql);

      $rows_affected = $wpdb->insert( $table_name, array( 'time' => current_time('mysql'), 'name' => $welcome_name, 'text' => $welcome_text ) );

      add_option("jal_db_version", $jal_db_version);

   }
}

Now that we have the initialization function defined, we want to make sure that WordPress calls this function when the plugin is activated by a WordPress administrator. To do that, we will use the activate_ action hook. If your plugin file is wp-content/plugins/plugindir/pluginfile.php, you’ll add the following line to the main body of your plugin:

register_activation_hook(__FILE__,'jal_install');