Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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';
            $.ajax({
                url: "<?php bloginfo('template_url') ?>/loop.php",
                type:'POST',
                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)
        );
        query_posts($args);
        $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(); ?> 
share|improve this question
add comment

2 Answers 2

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
}
add_action('wp_ajax_sample_ajax_callback_hookname','sample_ajax_callback');
add_action('wp_ajax_nopriv_sample_ajax_callback_hookname','sample_ajax_callback');

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

share|improve this answer
add comment

Bellow is full solution for you.

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

and here is full tutorial

share|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. –  Furqan Jan 13 '13 at 16:59
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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