Title: Using the algorithm wih existing theme
Last modified: July 6, 2018

---

# Using the algorithm wih existing theme

 *  [frittfallfoto](https://wordpress.org/support/users/frittfallfoto/)
 * (@frittfallfoto)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/using-the-algorithm-wih-existing-theme/)
 * Hi!
 * I already have a related post section at the bottom of all blogposts on my site(
   see link). The trouble is the algorithm selecting related posts is far too simple(
   only relates on category). Would it be possible to replace the original algorithm
   with the CRP algorithm, thus keeping the design of the original theme?
 * Here’s the code displaying related posts in my site:
 * if ( ! function_exists( ‘hestia_related_posts’ ) ) :
    /** * Related posts for
   single view. * * [@since](https://wordpress.org/support/users/since/) Hestia 
   1.0 */ function hestia_related_posts() {
 *  global $post;
    $cats = wp_get_object_terms( $post->ID, ‘category’, array( ‘fields’
   => ‘ids’, ) ); $args = array( ‘posts_per_page’ => 3, ‘cat’ => $cats, ‘orderby’
   => ‘date’, ‘ignore_sticky_posts’ => true, ‘post__not_in’ => array( $post->ID ),);
   $allowed_html = array( ‘br’ => array(), ’em’ => array(), ‘strong’ => array(),‘
   i’ => array( ‘class’ => array(), ), ‘span’ => array(), );
 *  $loop = new WP_Query( $args );
    if ( $loop->have_posts() ) : ?> <div class=”
   section related-posts”> <div class=”container”> <div class=”row”> <div class=”
   col-md-12″> <h2 class=”hestia-title text-center”><?php esc_html_e( ‘Relaterte
   innlegg’, ‘hestia-pro’ ); ?></h2> <div class=”row”> <?php while ( $loop->have_posts()):
   $loop->the_post(); ?> <div class=”col-md-4″> <div class=”card card-blog”> <?php
   if ( has_post_thumbnail() ) : ?> <div class=”card-image”> ” title=”<?php the_title_attribute();?
   >”> <?php the_post_thumbnail( ‘hestia-blog’ ); ?>  </div> <?php endif; ?> <div
   class=”content”> <h6 class=”category text-info”><?php hestia_category(); ?></
   h6> <h4 class=”card-title”> ” title=”<?php the_title_attribute(); ?>” rel=”bookmark”
   > <?php echo wp_kses( force_balance_tags( get_the_title() ), $allowed_html );?
   >  </h4> <p class=”card-description”><?php echo wp_kses_post( get_the_excerpt());?
   ></p> </div> </div> </div> <?php endwhile; ?> <?php wp_reset_postdata(); ?> </
   div> </div> </div> </div> </div> <?php endif; } endif;
 * Any help appreciated.
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fusing-the-algorithm-wih-existing-theme%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 1 replies (of 1 total)

 *  Plugin Author [Ajay](https://wordpress.org/support/users/ajay/)
 * (@ajay)
 * [7 years, 11 months ago](https://wordpress.org/support/topic/using-the-algorithm-wih-existing-theme/#post-10472045)
 * Check out this code: [https://gist.github.com/ajaydsouza/968b24a052e858bf8926#file-crp-plugin-api-examples-php-L9-L19](https://gist.github.com/ajaydsouza/968b24a052e858bf8926#file-crp-plugin-api-examples-php-L9-L19)

Viewing 1 replies (of 1 total)

The topic ‘Using the algorithm wih existing theme’ is closed to new replies.

 * ![](https://ps.w.org/contextual-related-posts/assets/icon-256x256.png?rev=2985705)
 * [Contextual Related Posts](https://wordpress.org/plugins/contextual-related-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/contextual-related-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/contextual-related-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/contextual-related-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/contextual-related-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/contextual-related-posts/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Ajay](https://wordpress.org/support/users/ajay/)
 * Last activity: [7 years, 11 months ago](https://wordpress.org/support/topic/using-the-algorithm-wih-existing-theme/#post-10472045)
 * Status: not resolved