WordPress tutorial, wordpress show posts with certain tag. We can show the five posts with certain tags. We can use following code for showing the posts.
wordpress show posts with certain tag
Just use the following code. Copy paste in to template page where you want to show posts.
On wordpress home page many sites are showing the post description or we can say the excerpt. For UI purpose some time we need to control the excerpt character limit. I already written about this in following article. But some people need the more advanced excerpt. Following code snippet will be helpful to you show the limit excerpt length by characters in wordpress.
First open your functions.php file 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.”]
we need to show breadcrumbs in wordpress site. For pages and category we can create breadcrumbs in wordpress. Shown, How to create breadcrumbs in wordpress.
How to create breadcrumbs in wordpress
We need to put following code in functions.php file.
WordPress tutorial for, How to create wordpress custom post type permalink structure. Here we creating the Product post type with permalink. we given code.
How to create wordpress custom post type permalink structure
Please open the functions.php file and put following code in that file.
/*
* product custom post type added with new permalink
*/
function productposttype_with_custom_permalinks() {
register_post_type('product', array(
'label' => __('My product'),
'singular_label' => __('product'),
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
"supports" => array("title", "editor", "thumbnail", "author", "comments"),
'taxonomies' => array('category', 'post_tag'), // this is IMPORTANT
'rewrite' => array('slug' => 'product'),
'public' => true
));
//register_taxonomy( 'product-category', 'product', array ('hierarchical' => true, 'label' => __('product Categories'), 'rewrite' => array( 'slug' => 'product-category', 'with_front' => false ),)); // portfolio categories
add_rewrite_tag('%product%', '([^/]+)');
$extra_post_types = get_post_types(array('_builtin' => false, 'publicly_queryable' => true));
if (empty($extra_post_types))
return;
add_rewrite_tag('%post_type%', '(' . implode('|', $extra_post_types) . ')');
add_permastruct('product', '/%post_type%/%year%/%monthnum%/%day%/%product%/', true, 1);
}
/*
* Funcation onload added the product custom post type
*/
add_action( 'init', 'productposttype_with_custom_permalinks' );
/*
* product custom post added the permalink hook for enable the custom permalink
* product custom post type
*/
function productposttype_with_product_permalink( $link, $post, $leavename, $sample ){
if( 'product' != $post->post_type )
return $link;
$rewritecode = array(
'%year%',
'%monthnum%',
'%day%',
'%hour%',
'%minute%',
'%second%',
$leavename? '' : '%postname%',
'%post_id%',
'%post_type%',
$leavename? '' : '%pagename%',
$leavename? '' : '%product%',
);
$unixtime = strtotime($post->post_date);
$date = explode(' ', date('Y m d H i s', $unixtime));
$replace_array = array(
$date[0],
$date[1],
$date[2],
$date[3],
$date[4],
$date[5],
$post->post_name,
$post->ID,
$post->post_type,
$post->post_name,
$post->post_name,
);
$path = str_replace($rewritecode, $replace_array, $link);
return $path;
}
add_action( 'post_type_link', 'productposttype_with_product_permalink', 10, 4 );
If you have any issues or problem with permalink then please write to me.
Showing wordpress comment preview for comment box is always good for attracting the visitors. I shown code here for show the comments preview.
wordpress comment preview for comment box
Many times comments preview will be useful for visitors to see how comments will be looking. Using google Jquery or wordpress jquery you can add the comment preview to your wordpress blog. Showing comment preview is always good for attracting the visitors. Many clients demands for this. I shown you the example code over here for show the comments preview.
In this tutorial I am using the wordpress inbuild jquery. First open your header. php file from your theme folder and after head tag following code.
WordPress tutorial for, Create an Autocomplete Search Field in wordpress. In wordpress also you can easily achieve the auto complete search form easily.
Create an Autocomplete Search Field in wordpress
Now auto complete search box is very common for every web projects. Auto complete search functionality you can see in google also. In wordpress also you can easily achieve the auto complete search form easily.
There is very nice Jquery plugin for auto complete. First download the latest version of jQuery , as well as the autocomplete plugin. Now, create a folder in your theme called “javascripts” and copy paste the two files in that folder. Open your header.php from your wordpress theme folder and put following code in that file.
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/javascripts/jquery.js"></script>
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/javascripts/jquery.autocomplete.pack.js"></script>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('template_directory'); ?>/javascripts/jquery.autocomplete.css" media="screen" />
<script type="text/javascript">
$(document).ready(function(){
var data = '<?php global $wpdb; $search_tags = $wpdb->get_results("SELECT name FROM $wpdb->terms"); foreach ($search_tags as $mytag){ echo $mytag->name. " "; } ?>'.split(" ");
$("#SEARCH_INPUT_BOX").autocomplete(data);
})
</script>
Just you need change the search input box id in place of SEARCH_INPUT_BOX.
If you are wordpress developer then only use the above code in header.php file. If you are facing any issue then please write to on support@purabtech.in.
Here are some very useful articles which are related to wordpress Search functionality.
Many times people want to upload big size media files into wordpress blog for download. Some people asked me about uploading the PDF files and video files into wordpress blog. You can easily upload big size media file to wordpress.
increase file upload size limit in wordpress
When to do wordpress installation that time default upload file limit is 2mb. Best way to increase the upload limit is adding code into .htaccess file. This file you will find in wordpress installation folder. Dont look into theme folder. Check your wordpress root folder for finding the .htaccess file.
After this you need to add the following code in to your wp-config.php file.
<tt>define('WP_MEMORY_LIMIT', '200MB');</tt>
Increase the maximum amount of a time a PHP script will run. Note: If using a shared hosting service, you may need to ask your host to increase the limit.
For you information I am giving you the information about most popular hosting providers.
Hostgator will gives the ability to increase the limit upto only 64mb.
Bluehost will gives the ability to increase the limit upto only 96mb.
Godaddy will gives the ability to increase the limit upto only 64mb.
Mostly all shared hosting providers gives you facility to upload files upto 64mb size file. If you are having any doubts then you can write to me on wordpressapi@gmail.com.
WordPress tutorial, How to Display WordPress Shortlink in Your post. From wordpress 3.0 version you can add the short link in your post through api. For social networking you want to add the short links in your post.
How to Display WordPress Shortlink in Your post
Adding shortlink tag in head section is always good ieda for SEO. short link will look like as follows:
In wordpress themes some tags are very important for SEO purpose. Here are some important wordpress tags for wordpress. If some of them tags are not included then you should modify the theme or you need to choose another wordpress theme.
Most important wordpress tags for wordpress themes and template
Here I created the list of wordpress tags which must be added in the header.php file of your wordpress theme.
<?php language_attributes(); ?> found in header.php if not present then put in that file.
<?php bloginfo(‘html_type’); ?> found in header.php if not present then put in that file.
<?php bloginfo(‘charset’); ?> found in header.php if not present then put in that file.
<meta name=”description” content=”<?php the_excerpt_rss(); ?>” /> found in header.php if not present then put in that file.
<link rel=”shortcut icon” href=”/favicon.ico” type=”image/x-icon” />found throughout the theme and header.php if not present then put in that file.
<?php bloginfo(‘name’); ?> found throughout the theme and header.php if not present then put in that file.
<?php if ( is_singular() && get_option( ‘thread_comments’ ) ) wp_enqueue_script( ‘comment-reply’ ); ?> found throughout the theme and header.php if not present then put in that file.
<meta name=”generator” content=”WordPress <?php bloginfo(‘version’); ?>” /> <!– leave this for stats –> found in header.php. If you’re using a 3rd party stats program (like Google Analytics) then you’ve nothing to worry about, and if your version of WordPress is out of date, you won’t want hackers knowing that.
<?php bloginfo(‘stylesheet_url’); ?> found in header.php.
<?php bloginfo(‘rss2_url’); ?> founder in header.php, sidebar.php and footer.php. Be careful if you switch to FeedBurner after doing this. Make sure you remember to update the feed URL here manually (The FeedSmith plugin won’t do it anymore).
<?php bloginfo(‘pingback_url’); ?> found in header.php.
<?php bloginfo(‘stylesheet_directory’); ?> found throughout the theme.
<?php bloginfo(‘description’); ?> found throughout the theme. Your site’s slogan
<?php wp_head(); ?> found in header.php in head section
<body <?php body_class(); ?>>found in header.php.
Here is list which functions and tags need to include in functions.php file.
if ( ! isset( $content_width ) ) $content_width = 500; found in functions.php
add_filter(‘the_content’, ‘make_clickable’); found in functions.php
add_theme_support( ‘post-thumbnails’ ); found in functions.php
add_theme_support( ‘automatic-feed-links’ ); found in functions.php
add_shortcode(‘wp_caption’, ‘fixed_img_caption_shortcode’); found in functions.php
add_shortcode(‘caption’, ‘fixed_img_caption_shortcode’); found in functions.php
Above tags are very important and you need to include the this tags in your theme files.
For speed up WordPress without developer then you can also do that. In this Article we shown, how to speed up wordpress site load time, Using some tricks you can speed up your wordpress site. Here we given some very basic steps for this.
Now more than 19 millions websites build in wordpress only. So wordpress sites market increased so much. People like the faster sites with good content and graphics. If your site visitors are less and content is limited then you don’t need to worry but content grows and traffic of your site increases then problem happens.
how to speed up wordpress site load time
When my site traffic is grown then I faced lot of issue. I changed four times my hosting service. I spend to much time about doing R&D about bandwidth and speed of wordpress blog. Then I noted some certain points for loading the site fastly.
In this article I written some points which are very important for increasing the speed of wordpress blogs.
Use the Cache Plugin
Use the WP Super Cache in your wordpress site. This plugin is very helpful, If you are using shared hosting then also this plugin is very helpful. you will see significant decrease in your site load time and much more efficiency in the usage of server resources.
Get good Hosting
Choosing hosting for wordpress sites if always issue. There are some very nice hosting providers for small wordpress sites. If your blog or site is having less than one thousand page views per day then only you need to go with shared hosting. If you are having more than one thousand page views then you should go for VPS or dedicated linux server. But for setting up wordpress on server you need to server knowledge also. If you are having the more than 10k to 20k visitors per day then you should go with Amazon or Rackspace or Gogrid cloud hosting server. For shared I can recommend following options.
I worked on Amazon EC2 and Amazon s3 for many web applications. If you are having any issues then you can write to me.
Hotlinking and Prevent Leeching
hotlinking means someone directly accessing your site images from other site. This will kill your bandwidth. If you want to prevent to stealing your site images then you need to just put following code in .htaccess file.
We always use the multiple wordpress plugins for various purpose. My advise is as much as possible don’t use the wordpress plugins. Just use the required wordpress plugins. For contact form and share buttons we always use the wordpress plugins but don’t use plugins for that. Use the following articles and scripts for avoiding the wordpress plugins:
This will save your bandwidth and your wordpress load fast.
Choose the Best Theme for your site
Choosing the right wordpress theme is also important. Your wordpress theme should load faster and minimum quires will fired to database server so your web page load fast. You should check following article for choosing the fast loading themes.
With great CSS and HTML code wordpress themes are great and HTML5 ready themes will load fastly and that is SEO friendly aslo.
Use the Compressed Images
Images always take so much bandwidth so you need to be very careful about images in your wordpress blog. Before uploading images to wordpress resize the image and then upload it to wordpress.
Images that use only a few colors should be saved as .GIF or .PNG files, and images that use a full spectrum of colors (like true photographs) should be saved as .JPG files. If you use a photo editing software, like Photoshop, you can “save for the web,” which will find the best format to save, while still maintaining quality.
Show Excerpt on Home page
On homepage dont show the full post. Just show the excerpt of post on home page. With your post showing featured image is always good. That will attract your user to read the article.If each of your post is a list post and it is displayed in full text mode, then it will be very inconvenient for your users because the page will take an immense amount of time and server resources to load. Therefore you must use excerpts and limit the count on how many posts are displayed.
Compress CSS and Javascript
CSS and javascript files also another requests to apache server. You should compress your css and javascript file in one or two files.
Stylesheets
Stylesheets are easy to compress, just use your favorite text editor to delete comments and unnecessary spaces and line breaks. Although you won’t see a drastic difference unless your style sheets involve tens of thousands of lines.
JavaScript
Compressing JavaScript isn’t as simple, but it is still relatively easy. There are a number of tools available, such as this one, which is free, that will compress your JavaScript code for you. Better yet, don’t rely on much JavaScript at all if you can help it. If your site has lots of interactivity, moving parts and fancy features, there is a good chance it is running a lot of JavaScript and that could slow things down.
Optimize Your MySQL Database
Some times your tables will go overhead. You should clean your database. For this you should use Optimize DB, wordpress plugin does exactly what we mentioned above except you don’t have to mess with phpMyAdmin. This plugin will reduce your work. Every 5 posts you should optimize the your database.
Use Sprite Images
If you are using many small images in your website then create sprite image. Sprite image will increase your site performance.