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.
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
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:
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.
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
If you are having any issues or question about using widget in wordpress theme then write to me.
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
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.
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:
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();?>
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
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.
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
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
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.
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.”]
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
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.
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.
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
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:
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.
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.
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
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: