How to fix, Error establishing a database connection in wordpress?

Sometime you may able to see the error message in your wordpress site that is ‘Error establishing a database connection’. If you are so lucky, then you will be see that, you can not access your wp-admin part due to the same reason. If you have experienced on it, definitely you are luck wp developer.  Anyways, lets see how to fix that kind of issues.

Wordpress Database connection error fix

Well, now first thing you have to do, log in your site via cpanel or ftp accounts. I am pretty sure that you have a that kinds of access authority if you are a real developer.

Continue reading

Advertisements

WordPress SEO: Add meta description to your theme

Hello friends
Today I am going to show how to add meta description in your wordpress custom theme. Unfortunately there is no meta data in wordpress default theme except the page title and description. Its very easy to write only few line of code.

 

<?php if (  (is_home()) || (is_front_page())  ) { ?>
<meta name="description" content="Blog description goes here" />
<?php } elseif (is_single()) { ?>
<meta name="description" content="<?php the_excerpt();?>"/>
<?php } ?>

Oky done. Just put this code into your head section and save it. Refresh and check the meat information again. 

Thanks for reading...

show all post form specific post_type in wordpress

Hello all,
Now I am going to show how to get the post from a specific post type. Just follow the code –

$args = array( 'post_type' => 'product', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
	the_title();
	echo '<div>';
	the_content();
	echo '</div>';
endwhile;

Just put this information in your desire page and it will be post last 10 post. Be remember to change the ‘product’ name. It must be the name of your post type.

Thanks for reading…

The WordPress Theme Search Template and Page Template

The Search Template and The Page Template are vital to any complete WordPress Theme. And they’re both really easy to code. For both these two Templates we’ll start with our template-template again.

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
<?php get_header(); ?>
    
        <div id="container"
            <div id="content">
            
                <div id="nav-above" class="navigation">
                </div><!-- #nav-above -->
                <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                </div><!-- #post-<?php the_ID(); ?> -->          
                
                <div id="nav-below" class="navigation">
                </div><!-- #nav-below -->                  
            
            </div><!-- #content -->    
        </div><!-- #container -->
        
<?php get_sidebar(); ?>  
<?php get_footer(); ?>

But, of course, each one is going to take it’s own different path.

The Search Template

In search.php we’re going to reintroduce the loop back into our Template. This time with an IF statement—in case we don’t have any posts to loop through.

Here’s how it’ll work: IF we have posts, or, in other words, if there are posts that match the terms we’re searching for, THEN loop through them, sorta just like in index.php, but IF we don’t have posts to loop through, or, if there aren’t any posts that match our search terms, give our searchers another chance at this searching business.

In code, it would look like this:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php get_header(); ?>
    
        <div id="container"
            <div id="content">
            
<?php if ( have_posts() ) : ?>               
<?php while ( have_posts() ) : the_post() ?>
<!-- this is our loop -->
<?php endwhile; ?>
<?php else : ?>
<!-- here's where we'll put a search form if there're no posts -->
<?php endif; ?>          
            </div><!-- #content -->    
        </div><!-- #container -->
        
<?php get_sidebar(); ?>  
<?php get_footer(); ?>

Pretty straightforward, right? Almost.

I like to keep all my index-ey Templates the same: Post Title, Meta, Content (or excerpt), Utility links. But when WordPress searches for posts it also searches through Pages, which don’t need the post meta or utility links displayed. So, in our loop, we’re going to check and see if we’re dealing with a post or a page. Continue reading

check the parent page in wordpress theme

Hay all…
Today, I am going to show how to identify the parent page in wordpress. It’s very easy to do. Just write a 3 line code in page.php file in wordpress.

<?php
if(get_pages(array(‘child_of’=>’post_ID’)) || $post->post->parent){
echo “This is the parent page”;
}else{
echo “This is not a parent page”;
}
?>

Save your file and check the page.