Support » Plugin: Ajaxize » Function not being Ajaxized (no output)

  • Resolved joshuaiz

    (@joshuaiz)


    Hello,

    I have the following function that is working great in my theme. This randomly swaps between two featured images for a post using the Multi Post Thumbnails plugin.

    When I enter this function into Ajaxize there is no output. Is there anything here that you can see would be causing that? This is the only thing I need to be not cached on the home page of a site.

    function fapp_random_feature() {
      // Get a random number
        $min = 1 ;
        $max = 10;
        $num = rand($min,$max);
    
        if ( $num & 1 && has_post_thumbnail() ) { // if it is an odd number and we have a featured image ?>
    
          <a class="feature-img" href="<?php echo get_permalink(); ?>"><?php the_post_thumbnail('fapp-thumb-800'); ?></a>
    
           <?php } elseif ( $num % 2 == 0 && class_exists('MultiPostThumbnails') && MultiPostThumbnails(has_post_thumbnail( 'post', 'secondary-image', NULL) ) { // If it is an even number and we have a second featured image ?>
    
          <a class="feature-img" href="<?php echo get_permalink(); ?>"><?php MultiPostThumbnails(the_post_thumbnail('post', 'secondary-image', NULL,  'fapp-thumb-800')); ?></a>
    
          <?php } else { // It's even and we don't have a second feature image so get the default feature image
    
          if ( has_post_thumbnail() ) { ?>
          <a class="feature-img" href="<?php echo get_permalink(); ?>"><?php the_post_thumbnail('fapp-thumb-800'); ?></a>
          <?php } 
    
        }
    
    }

    Thanks!

    https://wordpress.org/plugins/ajaxize/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author yoav.aner

    (@yoavaner)

    Hi Joshua,

    (and thanks again for your post. I made a comment about it on a different question)

    I think this won’t work with Ajaxize because the function echo’s the output directly, rather than returning it as a string. I mention it briefly on the FAQ, but perhaps it deserves a more specific explanation.

    In short, function like this should work:

    function works() {
      return '<a href="xyz">...</a>';
    }

    This doesn’t:

    function doesnt_work() {
      echo '<a href="xyz">...</a>';
    }

    Thanks Yoav,

    For this particular case I ended up using jQuery with a simpler function but thanks for that info – that makes sense.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Function not being Ajaxized (no output)’ is closed to new replies.