WordPress.org

Ready to get started?Download WordPress

Forums

Conditional ajax loading (1 post)

  1. sagive
    Member
    Posted 1 year ago #

    i am trying to load some-ajax.php only when specific category
    is being viewed... but, no matter what i try or what action / hook
    i try to connect the "if($catid = '111') {" condition the ajax
    stops working...

    The condition is being met but i guess i got things mixed up
    with the order of load..?

    in my functions.php i am testing for the category

    global $post;
    $category = get_the_category($post->ID);
    $catID = $category[0]->term_id;
    if($catID == '111') {
     include(TEMPLATEPATH.'/ajaxLoops/tools/ajax-example.php');
    }

    Then inside "ajax-example.php" i have this code (just example):

    wp_enqueue_script( 'ajax-site-screenshot', get_stylesheet_directory_uri().'/ajaxLoops/tools/ajax-get_site_screenshot.js', array('jquery'), 1.0 ); // jQuery will be included automatically
    wp_localize_script( 'ajax-site-screenshot', 'ajax_object', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) ); // setting ajaxurl
    
    add_action( 'wp_ajax_action_site_screenshot', 'ajax_site_screenshot' ); // ajax for logged in users
    add_action( 'wp_ajax_nopriv_action_site_screenshot', 'ajax_site_screenshot' ); // ajax for logged in users
    function ajax_site_screenshot() {
    	$w150 = '
    	<div class="fullb">
    	<img src="http://s.wordpress.com/mshots/v1/' . urlencode($site_url) . '?w=150"/>
    	</div>';
    
    	echo '<div id="w150">'.$w150.'</div>';
    
    	die(); // stop executing script
    }

    Could anyone help / guide / refrence me? i search for a similer
    problem or question but could not find any data on this.

    My theme has 20-30 ajax files and i dont want to load each and
    every one of them in every page when some are only used in specific category...

    i would love for an example since i am a loss..

    Thanks.
    Sagive

Topic Closed

This topic has been closed to new replies.

About this Topic