wordpress show posts with certain tag

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.

<?php
$args = array( 'numberposts' => 5, 'order'=> 'DESC', 'orderby' => 'post_date', 'tag_slug__in' => array( 'wordpress, tag1,tag2' ) );
$postslist = get_posts( $args ); foreach ($postslist as $post) : setup_postdata($post); ?>
 <?php the_time('F j, Y'); ?>
<a href="<?php echo get_permalink(); ?>">
<?php the_title(); ?>
 </a> <?php the_excerpt(); ?>
 <?php endforeach; ?>
wordpress show posts with certain tag
wordpress show posts with certain tag

Limit excerpt length by characters in wordpress

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.”]

function get_excerpt($count){
  $permalink = get_permalink($post->ID);
  $excerpt = get_the_content();
  $excerpt = strip_tags($excerpt);
  $excerpt = substr($excerpt, 0, $count);
  $excerpt = substr($excerpt, 0, strripos($excerpt, " "));
  $excerpt = $excerpt.'... <a href="'.$permalink.'">more</a>';
  return $excerpt;
}

[/viral-lock]

Use this function if you’re planning on using it more than once with a different amount of characters.

Call the function plus the amount of characters –

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php echo get_excerpt(125); ?>

Following is my old article link.
https://purabtech.in/set-wordpress-post-excerpt-length-limited-characters/

Limit excerpt length by characters in wordpress
Limit excerpt length by characters in wordpress

How to create breadcrumbs in wordpress

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.

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
function wordpress_breadcrumbs() {

  $delimiter = '&raquo;';
  $name = 'Home'; //text for the 'Home' link
  $currentBefore = '<span class="current">';</span>
  $currentAfter = '';

  if ( !is_home() && !is_front_page() || is_paged() ) {

    echo '<div id="crumbs">';

    global $post;
    $home = get_bloginfo('url');
    echo '<a href="' . $home . '">' . $name . '</a> ' . $delimiter . ' ';

    if ( is_category() ) {
      global $wp_query;
      $cat_obj = $wp_query->get_queried_object();
      $thisCat = $cat_obj->term_id;
      $thisCat = get_category($thisCat);
      $parentCat = get_category($thisCat->parent);
      if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
      echo $currentBefore . 'Archive by category '';
      single_cat_title();
      echo ''' . $currentAfter;

    } elseif ( is_day() ) {
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
      echo '<a href="' . get_month_link(get_the_time('Y'),get_the_time('m')) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
      echo $currentBefore . get_the_time('d') . $currentAfter;

    } elseif ( is_month() ) {
      echo '<a href="' . get_year_link(get_the_time('Y')) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
      echo $currentBefore . get_the_time('F') . $currentAfter;

    } elseif ( is_year() ) {
      echo $currentBefore . get_the_time('Y') . $currentAfter;

    } elseif ( is_single() ) {
      $cat = get_the_category(); $cat = $cat[0];
      echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
      echo $currentBefore;
      the_title();
      echo $currentAfter;

    } elseif ( is_page() && !$post->post_parent ) {
      echo $currentBefore;
      the_title();
      echo $currentAfter;

    } elseif ( is_page() && $post->post_parent ) {
      $parent_id  = $post->post_parent;
      $breadcrumbs = array();
      while ($parent_id) {
        $page = get_page($parent_id);
        $breadcrumbs[] = '<a href="' . get_permalink($page->ID) . '">' . get_the_title($page->ID) . '</a>';
        $parent_id  = $page->post_parent;
      }
      $breadcrumbs = array_reverse($breadcrumbs);
      foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
      echo $currentBefore;
      the_title();
      echo $currentAfter;

    } elseif ( is_search() ) {
      echo $currentBefore . 'Search results for '' . get_search_query() . ''' . $currentAfter;

    } elseif ( is_tag() ) {
      echo $currentBefore . 'Posts tagged '';
      single_tag_title();
      echo ''' . $currentAfter;

    } elseif ( is_author() ) {
       global $author;
      $userdata = get_userdata($author);
      echo $currentBefore . 'Articles posted by ' . $userdata->display_name . $currentAfter;

    } elseif ( is_404() ) {
      echo $currentBefore . 'Error 404' . $currentAfter;
    }

    if ( get_query_var('paged') ) {
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
      echo __('Page') . ' ' . get_query_var('paged');
      if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
    }

    echo '</div>';

  }
}
?>

After that put following code in header.php file.

<?php if (function_exists('wordpress_breadcrumbs')) wordpress_breadcrumbs(); ?>

After putting above code we can see the breadcrumbs as following;

Home » Parent Page » Sub Page1 » Sub Page2

Home » Category » Subcategory » Post Name

How to create breadcrumbs in wordpress
How to create breadcrumbs in wordpress

Code has been taken from above Source

create wordpress custom post type permalink structure

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.

How to create wordpress custom post type permalink structure
How to create wordpress custom post type permalink structure

wordpress comment preview for box comment without plugin

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.


<?php wp_enqueue_script(</code><code>'jquery'</code><code>); ?>
<?php if (is_single()) { ?>

<script type="text/javascript">

jQuery(document).ready(function(){

	jQuery("").add("<h3 id='preview-title'>Comment Preview</h3><div id='comment-preview'></div>").appendTo(document.body);
	jQuery("#comment-preview, #preview-title").insertAfter("#comment");

	var $comment = '';
	jQuery('#comment').keyup(function() {
		$comment = jQuery(this).val();
		$comment = $comment.replace(/\n\n+/g, '<br /><br />').replace(/\n/g, "<br />");
		jQuery('#comment-preview').html( $comment );
	});

});

</script>
<?php } ?>

Then Open Your style.css file from your theme folder put the following code in that file.

#comment-preview {
	border: 1px solid #ccc;
	padding: 5px 15px 15px 15px;
	}
h3#preview-title {
	margin-bottom: 5px
	}

After that upload the modified files on server. you will see following functionality for your wordpress commnets section.

wordpress comment preview for comment box
wordpress comment preview for comment box

If you are not wordpress developer then please dont try this.

Create an Autocomplete Search Field in wordpress

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.

Create an Ajax-based Auto complete Search Field in wordpress
Create an Ajax-based Auto complete Search Field in wordpress

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.

Add a search from in your navigation menu of wordpress theme

Set the style for default search widget

increase file upload size limit in wordpress

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.

Add following code in that file.


php_value upload_max_filesize 200M
php_value post_max_size 200M
php_value max_execution_time 2000
php_value max_input_time 2000

increase file upload size limit in wordpress
increase file upload size limit in wordpress

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.

How to Display WordPress Shortlink in Your post

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:

<link rel='shortlink' href='http://wp.me/p1kxw4-1uP' />

For adding short link in your single post you need to the following code in to your single.php file.

   if ( function_exists('the_shortlink') ) the_shortlink( __('Shortlink'), __('wordpress api short link'), ' · ' );

For adding the shortlink support in admin panel you need to add the following code in to functions.php file.

    add_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );

For adding the short link in head section add following code.


<link rel='shortlink' href='<?php if (function_exists('wp_get_shortlink')) { echo wp_get_shortlink(get_the_ID()); } ?>' />

For more detailed information you  can check following article.

Getting Shortlink in WordPress admin panel

How to Display WordPress Shortlink in Your post
How to Display WordPress Shortlink in Your post

Most important wordpress tags for wordpress themes

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
Most important wordpress tags for wordpress themes and template

 

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.

  1. <?php language_attributes(); ?> found in header.php if not present then put in that file.
  2. <?php bloginfo(‘html_type’); ?> found in header.php if not present then put in that file.
  3. <?php bloginfo(‘charset’); ?> found in header.php if not present then put in that file.
  4. <meta name=”description” content=”<?php the_excerpt_rss(); ?>” /> found in header.php if not present then put in that file.
  5. <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.
  6. <?php bloginfo(‘name’); ?> found throughout the theme and header.php if not present then put in that file.
  7. <?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.
  8. <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.
  9. <?php bloginfo(‘stylesheet_url’); ?> found in header.php.
  10. <?php bloginfo(‘rss2_url’); ?> founder in header.phpsidebar.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).
  11. <?php bloginfo(‘pingback_url’); ?> found in header.php.
  12. <?php bloginfo(‘stylesheet_directory’); ?> found throughout the theme.
  13. <?php bloginfo(‘description’); ?> found throughout the theme. Your site’s slogan
  14. <?php wp_head(); ?> found in header.php in head section
  15. <body <?php body_class(); ?>>found in header.php.

Here is list which functions and tags need to include in functions.php file.

  1. if ( ! isset( $content_width ) ) $content_width = 500; found in functions.php
  2. add_filter(‘the_content’, ‘make_clickable’); found in functions.php
  3. add_theme_support( ‘post-thumbnails’ ); found in functions.php
  4. add_theme_support( ‘automatic-feed-links’ ); found in functions.php
  5. add_shortcode(‘wp_caption’, ‘fixed_img_caption_shortcode’); found in functions.php
  6. 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.

how to speed up wordpress site load time

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.

You need to install varnish with wordpress and apache and increase wordpess website performance so much drastically.

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

how to speed up wordpress site load time
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.


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?purabtech.in [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?feeds2.feedburner.com/wordpressapi [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]

Remove the unnecessary wordpress plugins

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:

  1. how to create contact us page without wordpress plugin
  2. Add the extra new users details or fields to wordpress without plugin
  3. Display wordpress Tags In A Dropdown Menu without plugin
  4. How to change the Visual Editor Font Size wordpress without plugin
  5. Display wordpress Tags In A Dropdown Menu without plugin
  6. wordpress pagination style without wordpress plugin
  7. show popular posts without wordpress plugin in theme
  8. How to send smtp email through wordpress without plugin
  9. How to put digg button in wordpress without plugin
  10. Get the recent comments without using wordpress plugin or widget
  11. How to Add the social Bookmar Icons in WordPress theme without wordpress plugins
  12. How to exclude pages from wordpress menu without plugin
  13. Show related posts with wordpress post without using any plugin

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.