I am trying to post to the loop.php template file and it is not going through for some reason, usually it should work but it isnt. Is there a alternative way to get this done?

This is what I have in the index.php file of the theme.

$('.load_more_cont a').live('click', function(e) {
            leftwrapper = 'THIS IS WORKING';
                url: "<?php bloginfo('template_url') ?>/loop.php",
                data: "left_wrapper=leftwrapper", 
                success: function(data){
                    console.log('successful call');

This is what I have in the loop.php file.

$left_wrapper = $_POST['left_wrapper'];
        $args = array(
           'post_type' => 'post',
           'posts_per_page' => 15,
           'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1)
        $x = 0;

        $leftside = (!isset($left_wrapper) ? '3' : $left_wrapper);

        while (have_posts()) : the_post(); ?>

        <?php the_title(); ?>

        <?php $x++; ?>
        <?php endwhile; ?>
        <?php wp_reset_query(); ?> 

If that is the sum total of your loop.php, and you are accessing it directly which you are, your biggest problem is that you aren't going to have access to any WordPress functions and yet you are trying to use WordPress functions. You are going to get fatal errors. Your script does nothing to boot WordPress. You need to do that.

You could include('wp-blog-header.php'); at the top of that script or you could do the right thing and use the AJAX API. It is a relatively simple conversion. Instead of a separate file create a callback function and hook it to the AJAX system.

function sample_ajax_callback() {
  // your script

Your Javascript then POSTs to /wp-admin/admin-ajax.php with an action parameter named sample_ajax_callback_hookname.

| improve this answer | |

Bellow is full solution for you.

Here is demo page http://dashtutor.com/tuts/

and here is full tutorial

| improve this answer | |
  • 1
    an answer that is just a link to an external site is not considered a good answer. if that link breaks, so does your answer. – Milo Jan 13 '13 at 16:55
  • wp.tutsplus.com is very popular website.but next time i will be careful. – Muhammad Furqan Jan 13 '13 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.