Support » Plugin: Contextual Related Posts » 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 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 to see the link]

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.