Issue with query_posts and pagination

If you are using query_posts in your theme for category and you are facing issue with pagination. usage of query_posts, leave the original query on the home page intact, and modify the query from your functions.php file, using pre_get_posts

Solved issue with query_posts and pagination

we solved Issue with query_posts and pagination. If you are using query_posts in your theme and you are facing issue with pagination. for altering any query

Use following code to fix the issue with pagination.

php
$paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
$sticky=get_option(‘sticky_posts’);
$args=array(
‘cat’=>3,
‘caller_get_posts’=>1,
‘post__not_in’ => $sticky,
‘paged’=>$paged,
);
query_posts($args);
?>

or use following code.

php if (have_posts()) : ?>
php query_posts(“cat=3”); ?>
php while (have_posts()) : the_post(); ?>

replace with above with this code.

php if (have_posts()) : ?>
php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; query_posts(“cat=3&paged=$paged”); ?>
<?php while (have_posts()) : the_post(); ?>

Solved issue with query_posts and pagination
Solved issue with query_posts and pagination

Useful article for query post

http://codex.wordpress.org/Template_Tags/query_posts

set max image size in wordpress post for showing

wordpress tutorial, Here in this article, How to  set max image size in wordpress post for showing. We given simple CSS code which can be used in your style.css file.

Simply paste the following in your style.css file. This code will work with latest wordpress versions.

 set max image size in wordpress post for showing

.postarea img {
max-width: 500px;
height: auto;
}

.post img {
max-width: 500px; /* Adjust this value according to your content area size*/
height: auto;
}

.size-full {
max-width: 500px;
height: auto;
}

 set max image size in wordpress post for showing
set max image size in wordpress post for showing

Add custom gravatars to your wordPress default gravatar list

By default wordpress has some profile photos. In this tutorial we will show to you to Add custom gravatars to your wordPress default gravatar list.

custom gravatars to your wordPress

Just copy paste following code to functions.php file. This file can be found in your current activated theme folder.

if ( !function_exists('fb_addgravatar') ) {
function fb_addgravatar( $avatar_defaults ) {
$myavatar = get_bloginfo('template_directory').'/images/avatar.gif';
//default avatar
$avatar_defaults[$myavatar] = 'people';

$myavatar2 = get_bloginfo('template_directory').'/images/myavatar.png';
//Avatar for user "admin"
$avatar_defaults[$myavatar2] = 'admin';

return $avatar_defaults;
}

add_filter( 'avatar_defaults', 'fb_addgravatar' );
}
Add custom gravatars to your wordPress default gravatar list
Add custom gravatars to your wordPress default gravatar list

Thanks to WpEngineer for this such great wordpress hack!

I found useful following articles for wordpress plugin developers.

http://codex.wordpress.org/Using_Gravatars

http://codex.wordpress.org/Function_Reference

http://codex.wordpress.org/Function_Reference/add_filter

http://codex.wordpress.org/Plugin_API/Filter_Reference

Show related posts with wordpress post without plugin

For reducing bounce rate Show related posts with wordpress post without plugin is really great solution. There are many wordpress plugins which will give similar functionality but it will add extra code server hits to your server. It causes slowness.

Show related posts with wordpress post

Just copy paste the following code in your functions.php file.  You will find this file in your wordpress theme folder.

Show related posts with wordpress post
Show related posts with wordpress post
function get_related_posts($post_id) {
$tags = wp_get_post_tags($post_id);
if ($tags) {
echo 'Check some Related Posts<br>';
$first_tag = $tags[0]->term_id;
$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post->ID),
'showposts'=>10,
'caller_get_posts'=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
$the_permalink = get_permalink();
$post_title =  get_the_title();
$related_post = '<a href="'.$the_permalink.'">'.$post_title.'</a><br>';
echo $related_post;
endwhile;
}
}
}

You just need to use this function in your loop using “get_related_posts();” this function.

add common content after every wordpress post

WordPress tutorial, In this article we will show, how to add common content after every wordpress post. We given simple code for adding in wordpress theme.

Just copy paste the following code in your functions.php file.  You will find this file in your wordpress theme folder.

add common content after every wordpress post


function insert_common_content($_common_content) {
if(!is_feed() && !is_home()) {
$_common_content.= "<div class='wordpressapi'>";
$_common_content.= "<h4>Enjoyed this article?</h4>";
$_common_content.= "Check more articles on <a href='http://images.purabtech.in/'>purabtech.in/files/</a>";
$_common_content.= "</div>";
}
return $_common_content;
}
add_filter ('the_content', 'insert_common_content');

add common content after every wordpress post
add common content after every wordpress post

Useful article related to this wordpress hack.

http://codex.wordpress.org/Plugin_API/Filter_Reference/the_content

wordpress check if post has image attachment

In custom theme checking post image is really useful because old post has no featured image set. Using our code wordpress check if post has image attachment. Just use following code the check for image in wordpress post.

wordpress check if post has image attachment

Copy paste the following function in functions.php file.


function check_image(){
$content = $post->post_content;
$all_images = '~<img [^>]* />~';

preg_match_all( $all_images, $content, $pics );

// Check to see if we have at least 1 image
$all_pics = count($pics[0]);

if ( $all_pics > 0 ) {
// Your post have one or more images.
return true
} else {
return false;

}

wordpress check if post has image attachment
wordpress check if post has image attachment

In post loop just add or call this function. This function will return the true or false.

get first image thumbnail from wordpress post

Most WordPress theme are using custom fields to display thumbs on their blog homepage. How to get first image thumbnail from wordpress post

get first image thumbnail from wordpress post

But you can take easily extract the first image from the post, and display the image as post thumbnail.

Just copy paste the following function in your functions.php file.


function get_first_image($id) {
$PostID = $id;
$all_images =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $PostID );

if($all_images) {

$arr_of_all_images = array_keys($all_images);

// Get the first image attachment from post
$firstImage = $arr_of_all_images[0];

// Get the thumbnail url for the attachment
// If you want the full-size image instead of the thumbnail, use wp_get_attachment_url() instead of wp_get_attachment_thumb_url().
$thumb_url = wp_get_attachment_thumb_url($firstImage);

// Build the <img> string
$First_thumb_image = '<a href="' . get_permalink() . '">' .
'src="' . $thumb_url . '" width="150" height="150" alt="Thumbnail Image" title="Thumbnail Image" />' .
'</a>';

// Print the thum image form post
echo $First_thumb_image;
}
}

You can call above “get_first_image” function anywhere in your post loop. I loop you need to just copy paste the following lines
to print the first image of post body.

<!--?php get_first_image($post--->ID);  ?>
get first image thumbnail from wordpress post
get first image thumbnail from wordpress post

Follwing article I found useful

http://codex.wordpress.org/Plugin_API/Filter_Reference

http://codex.wordpress.org/Function_Reference/wp_get_attachment_thumb_url

Put Google Analytics code into your wordpress theme

Adding Google Analytics is important for website. Here in this article we given code snippet and show to Put Google Analytics code into your wordpress theme

Put Google Analytics code into your wordpress theme

Copy paste following lines to your wordpress theme folder’s functions.php file.


function google_analytics() {

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-12453889-1");
pageTracker._trackPageview();
} catch(err) {}</script>
}
add_action('wp_footer', 'google_analytics');

Dont forget to replace your google analytics code in google_analytics code.

Put Google Analytics code into your wordpress theme
Put Google Analytics code into your wordpress theme

have fun!

Change WordPress login logo using wordpress hack

If you want to Change WordPress login logo using wordpress hack. Just copy paste following lines to your wordpress theme folder’s functions.php file for this. There is very small code snippet you need put in your wordpress theme.

Change WordPress login logo using wordpress hack

function change_login_logo() {
echo ‘<style type=”text/css”>
h1 a { background-image:url(‘.get_bloginfo(‘template_directory’).’/images/logo.png); }
</style>’;
}

add_action(‘login_head’, ‘change_login_logo’);

Change WordPress login logo using wordpress hack
Change WordPress login logo using wordpress hack

have fun!

how to add favicon to wordpress theme

Favion is small image icon which is shown on browser left top side. Left side of browser address bar, we can see the favicon image. Here in this article We will show you, how to add add favicon to wordpress theme.

how to add favicon to wordpress theme

Create favicon image using photoshop or any photo editing tool. Favicon image side should be 16x16px or 32x32px. Many times favicon image should be .ico or png format. All latest browser are able to show png format image but in old browser icon format image should be supported.

Just copy paste the following lines to your function.php file.

<?php 
function add_favicon() {
?>
<link rel="shortcut icon" href="<?php echo bloginfo('stylesheet_directory') ?>/images/favicon.ico" >
<?php 
}
add_action('wp_head', 'add_favicon');
?>

if wp_head() function added in your header.php file, If that function not added then this hack will never work

Or you can just add favicon image file in themes folder and use following code in header.php file.


<link rel="icon" href="https://purabtech.in/favicon.ico" type="image/x-icon" />
<link rel="shortcut icon" href="https://purabtech.in/favicon.ico" type="image/x-icon" />

how to add favicon to wordpress theme
how to add favicon to wordpress theme