• Hi.
    I use this plugin for years and it’s very usefull for me. I would like to show informations from related posts thru a ajax call.

    it works, but the result is empty. not totally empty but
    <div id=”crp_related”> </div>

    when I use the function call thru a [code] (bottom of page)
    if ( function_exists( 'echo_crp' ) ) { echo_crp(); }
    inside my function.php, it works finely and I see my 6 links with thumbnails.

    if you have ideas...
    kind regards.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author Ajay

    (@ajay)

    What is the code you’re using for the Ajax call?

    Since 3.1, the plugin also supports the REST API, so I’m not sure if that would be easier to fetch the posts via Ajax and create the HTML on the fly?

    https://webberzone.com/support/knowledgebase/wp-rest-api-integration/

    Thread Starter BARBAROUX

    (@barbaroux)

    Hi Ajay,

    thanks for your quick response.

    well I use
    if ( function_exists( ‘echo_crp’ ) ) { echo_crp(); }
    as line code to fetch the information from the crp plugin.

    I want to use ajax and I am aware that not in the loop so parameters (at least page_id) are needed to work fine.

    I’ll take a look at the rest api and will make response afters tests.
    regards;

    Thread Starter BARBAROUX

    (@barbaroux)

    Hi,
    I’ve just seen
    get_crp_posts() on your website webberzone.com
    would it be not more convinient to use it ?
    regards,

    Plugin Author Ajay

    (@ajay)

    Yes, I was thinking – in your Ajax call, are you passing a parameter for postid?

    https://github.com/WebberZone/contextual-related-posts/blob/master/includes/main-query.php#L635

    Thread Starter BARBAROUX

    (@barbaroux)

    Hi Ajay, it’s ok now.
    I’ve used get_crp_posts() in my php code thru an ajax mechanism.
    it works fine on my resume-cv blog. I use it to delay the display of some bottom information.
    many thanks for your advices and all the work on your plugins.
    kind regards.

    Plugin Author Ajay

    (@ajay)

    @barbaroux

    Will you be able to share the code you’re using – I’m quite curious on the implementation and if there is a performance improvement

    Thread Starter BARBAROUX

    (@barbaroux)

    on server side, this is the main function used :

    function appel_crp($po) {
    
           $li=6;
            
           $thumb_height=140;
           $thumb_width=140;
           $thumb_meta="post-image";
           $thumb_html="html";
           $thumb_default="";
           $thumb_default_show=true;
           $thumb_timthumb="";
           $thumb_timthumb_q="";
           $scan_images=false;
           
           
           if ( function_exists( 'get_crp_posts' ) )
           {
               $results = get_crp_posts(array ('postid' => $po, 'limit' => $li));
               if ($results) {
                   $output='<div class="crp_related crp_related_widget crp-grid"><ul>';
                   foreach ($results as $result)
                   {
                       $output.="<li>";
                       
                       $output .= '<a href="' . get_permalink($result->ID) . '" ' . $rel_attribute . ' ' . $target_attribute . '>';
                       $output .= crp_get_the_post_thumbnail(array('post' => $result->ID, 'thumb_height' => $thumb_height, 'thumb_width' => $thumb_width, 'thumb_meta' => $thumb_meta, 'thumb_html' => $thumb_html, 'thumb_default' => $thumb_default, 'thumb_default_show' => $thumb_default_show, 'thumb_timthumb' => $thumb_timthumb, 'thumb_timthumb_q' => $thumb_timthumb_q, 'scan_images' => $scan_images, 'class' => 'crp_thumb', 'filter' => 'crp_postimage'));
                       
                       $output.='<span class="crp_title">';
                       $output.= get_the_title($result->ID);
                       $output.='</span>';
                       $output .= '</a>';
                       $output.="</li>";
                       
                   }
                   $output.="</div><ul>";
                   return $output;
               } else
                   return "Pas d'articles relatifs";
           }
               else
                   return "fonction inexistante";
         
       }

    the result is json encapsulated then returned to the client side and managed by javscript.

    Plugin Author Ajay

    (@ajay)

    Thank you. I’ll look into this!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘using php echo_crp() thru ajax mechanism’ is closed to new replies.