show related posts wordpress without plugin using category

How to show related posts wordpress without plugin using category. Showing related article in wordpress site is always good for users to attract visitors.  In many blogs people are showing the related or linked articles. Showing similier or related articles will increaze your site SEO. show related posts without wordpress plugin using category in wordpress site is always good for users to attract the visitors.

show related posts wordpress without plugin

More visitor will visit your site. For showing the related articles you need copy following code into your functions.php file.

[viral-lock message=”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.”]

// "Similier Articles"
function wpapi_more_from_cat( $title = "Similier Articles:" ) {
    global $post;
    // We should get the first category of the post
    $categories = get_the_category( $post->ID );
    $first_cat = $categories[0]->cat_ID;
    // Let's start the $output by displaying the title and opening the <ul>
    $output = '<h3>' . $title . '</h3>';
    // The arguments of the post list!
    $args = array(
        // It should be in the first category of our post:
        'category__in' => array( $first_cat ),
        // Our post should NOT be in the list:
        'post__not_in' => array( $post->ID ),
        // ...And it should fetch 5 posts - you can change this number if you like:
        'posts_per_page' => 5
    );
    // The get_posts() function
    $posts = get_posts( $args );
    if( $posts ) {
        $output .= '<ul>';
        // Let's start the loop!
        foreach( $posts as $post ) {
            setup_postdata( $post );
            $post_title = get_the_title();
            $permalink = get_permalink();
            $output .= '
<ul>
	<li>permalink . '" title="' . esc_attr( $post_title ) . '">' . $post_title . '</li>
</ul>
';
        }
        $output .= '</ul>';
    } else {
        // If there are no posts, we should return something, too!
        $output .= '<p>Sorry, this category has just one post and you just read it!</p>';
    }
    echo $output;
}

[/viral-lock]

After that open your single.php file and use following code.

wpapi_more_from_cat();
show related posts wordpress without plugin
show related posts wordpress without plugin

Using above code you can show the related articles in your wordpress site.

Show QR code in your wordpress post

QR codes are digital information which will be stored in image format. Many people are showing the QR code image in there site. You can very easily show the chart qr image in your post.

Show QR code in your wordpress post

You need to use the following code in your single.php file.

<img src="https://chart.googleapis.com/chart?cht=qr&chs=250x250&chl=<!--?php the_permalink(); ?-->" alt="QR: <!--?php the_title(); ?-->"/>
Show QR code in your wordpress post
Show QR code in your wordpress post

How to wordpress secure file upload using apache rules

WordPress tutorial, How to wordpress secure file upload using apache rules, Here we given apache rule for secure your wordpress file upload functionality.

How to wordpress secure file upload using apache rules

Website security is most important point of any website. In wordpress we need to give 777 permission to wp-content/uploads folder. Some time we don’t want to give the 777 (read, write and execute) permission to folder due to security reason but wordpress do not allow you to upload images or media files to uploads folder.

Tip: Do not give 777 permission to wp-content/uploads folder. In stead change user ownership to apache folder.

Security

What you can do is. You can restrict other file types to upload in uploads folder using simple apache rule. following code you can use in .htaccess file.


	Order Allow,Deny
	Deny from all

<FilesMatch ".(jpg|jpeg|jpe|gif|png|tif|tiff)$">
	Order Deny,Allow
	Allow from all

Using above code you can secure your uploads folder and only selected files can be pushed into uploads folder.

How to wordpress secure file upload using apache rules
How to wordpress secure file upload using apache rules

how to get post data outside loop in wordpress

WordPress hack, In this wordpress tutorial we given code and shown, how to get post data outside loop in wordpress. In wordpress theme you can get post data.

how to get post data outside loop in wordpress

Outside the loop you can get the a post data. you just need to copy paste following code in your theme file.

<?php
global $post;

$args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );

$myposts = get_posts( $args );

foreach( $myposts as $post ) : setup_postdata($post); ?>
 <li>
 <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
 </li>
<?php endforeach; ?>
how to get post data outside loop in wordpress
how to get post data outside loop in wordpress

how to get parent page title in wordpress

If want to get parent page title in wordpress and show in wordpress then use following code snippet in your theme you can easily get the parent page title.

how to get parent page title in wordpress

Normally what I would do is check $post->parent and if 0 then return page title else return title of page above. Problem is that $post->parent will only go back one level. I need to use some sort of recursive function that keeps going back until $post->parent == 0.

Add following code in to your wordpress theme, functions.php file and that sit. you will done.

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
 global $post;
 $parent_title = get_the_title($post->post_parent);
 echo $parent_title;
?>

Using above code you can easily print the page title in wordpress theme.

how to get parent page title in wordpress
how to get parent page title in wordpress

Disable comments on posts after certain comment count

Many people want to disable the post comments for some posts which has too many comments. Using simple code you can easily disable the comments for your posts which has many comments.

Here I written simple code. Using following code you can disable the comments which posts has more than 100 comments. you need to just put following code into your functions.php file.

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1"-->php
$comment_count = 100;
function disable_comments( $posts ) {
 if ( !is_single() ) { return $posts; }
 if ( $posts[0]->comment_count > $comment_count ) {
 $posts[0]->comment_status = 'disabled';
 $posts[0]->ping_status = 'disabled';
 }
return $posts;
}
add_filter( 'the_posts', 'disable_comments' );
?>
Disable comments on posts after certain commment count in wordpress
Disable comments on posts after certain commment count in wordpress

how to get current user information in wordpress

In wordpress current user means, Who written current post or article.In this article we are going show you, how to get current user information in wordpress. Following methods are useful when user are logged in to wordpress CMS.

You can print the user information using following information. Retrieves the information pertaining to the currently logged in user, and places it in the global variable $current_user.

how to get current user information in wordpress

You can put following code in your theme folder.

<?php 

global $current_user;
 get_currentuserinfo();
 echo 'Username: ' . $current_user->user_login . "\n";
 echo 'User email: ' . $current_user->user_email . "\n";
 echo 'User first name: ' . $current_user->user_firstname . "\n";
 echo 'User last name: ' . $current_user->user_lastname . "\n";
 echo 'User display name: ' . $current_user->display_name . "\n";
 echo 'User ID: ' . $current_user->ID . "\n";
?>

Or you can use following code for showing the current user information

<?php&nbsp;
wp_get_current_user();&nbsp;
?>  

<?php
$user_info = get_userdata(1);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo 'Username: ' . $user_info->user_login . "\n";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo 'User roles: ' . implode(', ', $user_info->roles) . "\n";
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo 'User ID: ' . $user_info->ID . "\n";
?>

For more detailed information you can visit following link:
http://codex.wordpress.org/Function_Reference/get_userdata

how to get current user information in wordpress
how to get current user information in wordpress

How to create custom shortcode for wordpress site

There are many wordpress plugins which using the shortcode. But you easily create custom shortcode for wordpress site. there is no need of external plugin.

custom shortcode for wordpress

Since Version 2.5 WordPress support so called Shortcodes. They have been introduced for creating macros to be use in a posts content. Many people looking for how to create the shortcode in wordpress using theme. It is very easy to build shortcode in wordpress. I given very simple code sample for creating the custom shortcode.

For more information visit following page.

For creating the custom shortcodes you need add following method in functions.php file which is located in your theme folder.


function myshortcode(){
 return '<img src="http://images.purabtech.in/How-to-make-empty-the-wordpress-trash-automatically.png">';
}
add_shortcode('myshortcode', 'myshortcode');

custom shortcode for wordpress
custom shortcode for wordpress

you can change the return text or shortcode name aslo.

How to show featured image in wordpress admin panel list

Featured images are very important feature of wordpress. Many blogger use the featured images on top. With watching the featured images user got idea about blog post or your article. Some time we miss to upload the featured image.

How to show featured image in wordpress admin panel list

But in post list cannot able to see the featured image in admin panel.

I found very nice wordpress plugin which is helpful to show the featured image in admin panel.

Featured Image Column – Adds a column to the edit screen with the featured image if it exists.

This plugin has no options. It simply adds a column before the title (far left) the show’s the posts featured image if it’s supported and/or exists.

Add a defualt image simply by filtering you own image in. Use featured_image_column_default_image or filter your own CSS by using featured_image_column_css.

Add support for a custom default image

How to show featured image in admin panel list - in post list - for wordpress
How to show featured image in admin panel list – in post list – for wordpress
function my_custom_featured_image_column_image( $image ) {
    if ( !has_post_thumbnail() )
        return trailingslashit( get_stylesheet_directory_uri() ) . 'images/featured-image.png';
}
add_filter( 'featured_image_column_default_image', 'my_custom_featured_image_column_image' );

Add your own CSS to change the size of the image.

/**
 * @use '.featured-image.column-featured-image img {}'
 */
function my_custom_featured_image_css() {
    return trailingslashit( get_stylesheet_directory_uri() ) . 'css/featured-image.css'; //URL to your css
}
add_filter( 'featured_image_column_css', 'my_custom_featured_image_css' );

I found this plugin is really helpful to me. Using this plugin I can easily check the featured image.