Thursday 15 October 2015

How to create load more posts in wordpress using jQuery Ajax

Step 1: Put the following javascript in the section.
<script type="text/javascript">
jQuery(document).ready(function($) {
  var page = 1; // What page we are on.
  var ppp = 3; // Post per page
                var posts = 3;
                var author_posts = parseInt(<?php echo get_the_author_posts(); ?> ); // Get all posts
              $("#load_more_posts").click(function() {
               if ((author_posts - posts ) < 0) {
                    $("#load_more_posts").attr('disabled');
                    $("#load_more_posts").css({'cursor': 'default','opacity': '0.61'});
                    $("#load_more_posts").text('No more posts!');
                }else {
                    OffSet = (page * ppp);
                    $.ajax({
                    type: "GET",
                    url: "/WordPress/wp-admin/admin-ajax.php",
                    dataType: 'html',
                    data: ({ action: 'loadMore', offset:OffSet , ppp: ppp}),
                    success: function(data){    
                    //$('#load_posts').append( $.parseHTML(data));
                    var $items = $($.parseHTML(data));
                    $('#load_posts').append( $items ).isotope( 'appended', $items );
                    // #load_posts is the id of main posts container
                    posts = posts + 3;
                    page++;
                    if ((author_posts - posts ) < 0) {
                        $("#load_more_posts").attr('disabled');
                        $("#load_more_posts").css({'cursor': 'default','opacity': '0.61'});
                        $("#load_more_posts").text('No more posts!');
                        }
                    }
                });
            }
        });
    });
 </script>
Step 2: After that put the following code in function.php file.
<?php
 function loadMore() {
        $offset     = $_GET["offset"];
        $ppp         = $_GET["ppp"];
        $args2         = array( 'posts_per_page' => $ppp, 'offset' => $offset, 'orderby' => 'DESC');
        $custom2     = new WP_Query($args2);
        // the Loop
        while ($custom2->have_posts()) : $custom2->the_post();  ?>
        <div class="item">
        <div class="grid-text">   
        <?php the_content('Read More...');?>
        </div>
        </div>
        <?php
        endwhile;
        // Reset Query
        wp_reset_query();
      
}
add_action('wp_ajax_loadMore', 'loadMore');
add_action('wp_ajax_nopriv_loadMore', 'loadMore'); // not really needed
?>
Step 3: Finally put the following code line in index.php page after closing main div of posts container.
<div id="load_more_posts"> Load More</div>

Thursday 14 May 2015

how to Install SugarCRM on localhost in windows - Step by Step Guide

 I had followed this link when I was installing SugarCRM on my local Server. This link provides step by step solutions for installing SugarCRM on localhost.

http://marwahjatin.blogspot.in/2010/06/install-sugarcrm-step-by-step-guide.html

Thursday 5 February 2015

How to Upload File in PHP using jquery with multiple file selection, drag&drop support, progress bars, validation and preview images

File Upload widget with multiple file selection, drag&drop support, progress bars, validation and preview images, audio and video for jQuery.
Supports cross-domain, chunked and resumable file uploads and client-side image resizing.
Works with any server-side platform (PHP, Python, Ruby on Rails, Java, Node.js, Go etc.) that supports standard HTML form file uploads.
Please visit the following to download source code.

https://blueimp.github.io/jQuery-File-Upload/

Thursday 29 January 2015

Tutorial on install, setup and getting started in Symfony 2 PHP MVC framework with Hello World example on Windows


PHP is one of the widely used web development language, and Symfony is an Enterprise level PHP MVC framework. Here the following link is explaining the steps for getting started with Symfony in Windows with a 'Hello World' example in Symfony.

http://www.tinywall.info/2014/05/install-setup-getting-started-tutorial-php-symfony-hello-world-example-windows.html

Friday 9 January 2015

How to Display Comments on Home Page of a WordPress Site

 I have just put $withcomments = "1"; before comments_template() function.
<?php  
$withcomments = "1"; 
comments_template(); 
 ?>

Thursday 8 January 2015

How to Get Different Themes on Different WordPress Pages

Select different themes for one or more wordpress pages, posts or other non-admin pages or site home. Please visit the below link.

https://wordpress.org/plugins/jonradio-multiple-themes/



Monday 5 January 2015

How to import .sql file in mysql database using php


<?php
           // Name of the file
          $filename = 'filename.sql';
          // MySQL host
          $mysql_host = 'localhost';
         // MySQL username
         $mysql_username = 'root';
        // MySQL password
        $mysql_password = '';
        // Database name
        $mysql_database = 'dbName';

        // Connect to MySQL server
        mysql_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to           MySQL server: ' . mysql_error());
       // Select database
       mysql_select_db($mysql_database) or die('Error selecting MySQL database: ' . mysql_error());

      // Temporary variable, used to store current query
      $templine = '';
     // Read in entire file
     $lines = file($filename);
     // Loop through each line
      foreach ($lines as $line)
       {
         // Skip it if it's a comment
           if (substr($line, 0, 2) == '--' || $line == '')
           continue;

        // Add this line to the current segment
        $templine .= $line;
       // If it has a semicolon at the end, it's the end of the query
        if (substr(trim($line), -1, 1) == ';')
       {
          // Perform the query
            mysql_query($templine) or print('Error performing query \'<strong>' . $templine . '\': ' .                      mysql_error() . '<br /><br />');
           // Reset temp variable to empty
          $templine = '';
          }
}
 echo "Tables imported successfully";
?>

Friday 2 January 2015

How to display Posts in lightbox with pagination In WordPress

// Create post_lightbox.php template or simple page

<?php
         require_once( './wp-load.php' );
         $post_id = $_REQUEST['post_id'];

         $author_query = array('posts_per_page' => '-1');  
         $author_posts = new WP_Query($author_query);
         if($author_posts->have_posts()):
         while($author_posts->have_posts()) : $author_posts->the_post();  
         ?>
        <p><a  class="inline post-<?php echo get_the_ID();?>" href="#post-<?php echo get_the_ID();?>"><?php the_title(); ?></a></p>
        <div id="post-<?php echo get_the_ID();?>" class="inline-post">
            <?php  wdpv_vote(); ?>   
            <h2 class="inline-header" style="text-align:center;">
                <a href="<?php the_permalink();?>" target="_blank"><?php the_title(); ?></a>
            </h2>
            <div class="userpro-post-stat lightbox-icons">
                <a href="<?php the_permalink(); ?>#comments"><i class="userpro-icon-comment"></i> <?php echo (get_comments_number())?get_comments_number().' Comments':'Leave a Comment'; ?></a> |
                <a href="#"><i class="userpro-icon-time"></i><?php echo get_the_date();?></a> |
                <a href="#"><i class="userpro-icon-user"></i> By <?php the_author(); ?></a>
               
            </div>
                       
            <div class="inline-content">
                 <?php the_content(); ?>
             
            </div>
                   
        </div>
    <?php          
    endwhile;
    else:
    echo '<h5 style="margin-top: 24px;text-align: center;">No Matches Found!</h5>';
    endif;?>
  
==================================================================

<!--open posts in light box-->
<!--<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>-->
<link rel="stylesheet" href="<?php echo get_template_directory_uri(); ?>/css/colorbox.css" />
    <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.colorbox.js"></script>
    <script type="text/javascript">
    jQuery(document).ready(function (){
   

 jQuery('.inline-post').on('click',function(event){        
//event.preventDefault();
var id = jQuery(this).attr('href');
var post_id = id.split("-");
 var post_class= 'post-'+post_id[1];
jQuery.ajax({ 
type: "POST",                 
url:  "<?php echo home_url('/');?>post_display_in_lightbox.php", 
   data: 'post_id='+post_id[1],   
   beforeSend: function() {
        // setting a timeout
        jQuery('.lightbox-loading').css('display','block');
    },
   success: function (msg) { 

  jQuery('#all_ajax_posts').html(msg);
   jQuery('.lightbox-loading').css('display','none');

   var mmmm= setInterval(function() {
     jQuery('.'+post_class).trigger('click');
   
  //jQuery(".inline").colorbox({inline:true,rel:'inline', transition:"none", width:"85%", height:"100%",position:'fixed'});
   
}, 500);

jQuery(".inline").colorbox({inline:true,rel:'inline', transition:"none", width:"85%", height:"100%",position:'fixed'});
setTimeout(function(){clearInterval(mmmm); }, 2000);
},
error: function () {                 
  alert('Error');              

});  
       
});
   
});
   
</script>


Note: Download css and js files from colorbox-master site.