Tuesday, June 25, 2013

Widgets and Visual Editor not working Wordpress


Sometimes this is happen when we update the version of the wordpress or add some new plugin in our
wordpress site, some part of our admin area stop the working like Editor or Widgets etc.

To overcomes that problem you can simply put following code on your wp-config.php just under
define('DB_COLLATE', '');


define( 'CONCATENATE_SCRIPTS', false ); 


so our new code becomes like :

define('DB_COLLATE', '');

define( 'CONCATENATE_SCRIPTS', false );   


 in the wp-config.php that is location  on root of the wordpress site.


 




















Show Random Posts Wordpress


You can show Random Posts on your WordPress site with very simple code.

Just add the following code on single.php where you want to show the Random Posts in wordpress


<div class="related_post">
      <?php 
echo '<h3>Random Posts</h3>';
$posts = get_posts('orderby=rand&numberposts=5');
foreach($posts as $post) :
?>
      <div class="rp">
        <li><a href="<?php the_permalink() ?>">
          <?php the_post_thumbnail(array(120,120)); ?>
          </a>
          <h4><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
            <?php the_title(); ?>
            </a></h4>
        </li>
      </div>
      <?php
wp_reset_query(); 
endforeach;
?>
    </div>
  </div>

Wednesday, June 19, 2013

Add own excerpt length wordrpess

 With the following code the use your new excerpt with specific length in wordpress .

Add the following code the functions.php

 function wpe_excerpt($length_callback='', $more_callback='') {
    global $post;
    if(function_exists($length_callback)){
    add_filter('excerpt_length', $length_callback);
    }
    if(function_exists($more_callback)){
    add_filter('excerpt_more', $more_callback);
    }
    $output = get_the_excerpt();
    $output = apply_filters('wptexturize', $output);
    $output = apply_filters('convert_chars', $output);
    $output = '<p>'.$output.'</p>';
    echo $output;
    }


    function wpe_excerptlength_teaser($length) {
    return 45;  // show 45 characters
    }
    function wpe_excerptlength_index($length) {
    return 30;  // show 45 characters
    }
    function wpe_excerptmore($more) {
    return '...';
    }

----------------

    function wpe_excerpt($length_callback='', $more_callback='') {
   
   global $post;
 
   if(function_exists($length_callback)){
 
    add_filter('excerpt_length', $length_callback);
    }
 
    if(function_exists($more_callback)){
    add_filter('excerpt_more', $more_callback);
    }
 
    $output = get_the_excerpt();
 
   $output = apply_filters('wptexturize', $output);

   $output = apply_filters('convert_chars', $output);

   $output = '<p>'.$output.'</p>';
   
   echo $output;
 
   }

 





Add Search box in wordpress

Use following code to add  Search field on your specific area in WordPress


First add the following code in function.php of wordpress theme


function my_search_form( $form ) {

    $form = '<form role="search" method="get" id="searchform" action="' . home_url( '/' ) . '" >
    <div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
    <input type="text" value="' . get_search_query() . '" name="s" id="s" />
    <input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
    </div>
    </form>';

    return $form;
}

add_filter( 'get_search_form', 'my_search_form' );


After that use the following code where you want to show your code.


<form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>">
                <input type="text" size="10" class="txt_bg" name="s" id="s"/>
                </div>
                <div class="box_right">
                <input alt="search" type="image" src="<?php bloginfo( 'template_url' ); ?>/img/search.png" />
  </form>

With that you can showe anywhere Search field in wordpress.

Show Related Posts of Specific Category Wordpress

Use following code to show  Related Posts of Specific Category in wordpress 
$categories = get_the_category($post->ID);
if ($categories) {
    $category_ids = array();
    foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;

    $args=array(
        'category__in' => $category_ids,
        'post__not_in' => array($post->ID),
        'showposts'=>5, // Number of related posts that will be shown.
        'caller_get_posts'=>1
    );
    $my_query = new wp_query($args);
    if( $my_query->have_posts() ) {
        echo '<h3>Related Posts</h3><ul>';
        while ($my_query->have_posts()) {
            $my_query->the_post();
        ?>
            <li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></li>
        <?php
        }
        echo '</ul>';
    }
}

Show Specific Page Content Wordpress

Sometimes you need to put the content of specific page on your desired location in wordpress. For that use can use the following code

<?php
$page_id = 152;   // Page id
$page_data = get_page( $page_id );
$content = apply_filters('the_content', $page_data->post_content); 
$title = $page_data->post_title; // Get title
echo $content; // Output Content
?>

with that use can show anywhere  Specific Page Content in Wordpress. 

Wordpress Pagination Problem with query_posts()

This is very common problem that is occurring every time while we are working in wordpress that is Pagination Problem with query_posts(). So for that

instead of using only  query_posts("category_name=categoryname");

Use That code:

       <?php if (have_posts()) : ?>
   
       <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

       query_posts("category_name=category-name&paged=$paged"); ?>
     
       <?php while (have_posts()) : the_post(); ?>

       *** Your code Here ****

       <?php endwhile; ?>

       <?php wp_reset_query(); ?>

        <?php endif; ?>

 
 OR You can use following code for Pagination with query_posts()
       
       <?php

       //The Query
        $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
        $args=array(
        ‘paged’=>$paged,      //Pulls the paged function into the query
        ‘posts_per_page’=>5,   //Limits the amount of posts on each page
        'cat'=>'category ID'
          );
        query_posts($args);

         //The Loop
         if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

         <!– Display Content –>
         <!– Display Pagination –>

        <?php endwhile; endif;

         wp_reset_query(); ?>

   All the above will resolve your problem of  Pagination Problem with query_posts()