WordPress.org

Ready to get started?Download WordPress

Forums

Contextual Related Posts
Optimize Performance if output is off (6 posts)

  1. CodingFabian
    Member
    Posted 2 years ago #

    Hi,
    even when no post on the current page will display the related post, they are calculated for each of them.
    The reason for that is the function ald_crp_content:

    function ald_crp_content($content) {
    
    	global $single;
    	$crp_settings = crp_read_options();
    	$output = ald_crp();
    
        if((is_single())&&($crp_settings['add_to_content'])) {
            return $content.$output;
        } elseif((is_page())&&($crp_settings['add_to_page'])) {
            return $content.$output;
    	} elseif((is_feed())&&($crp_settings['add_to_feed'])) {
            return $content.$output;
        } else {
            return $content;
        }
    }

    als_crp is called even when the last return is used, which does not ouput it.

    I always patch it like this (there are more elegant alternatives, but this works):

    function ald_crp_content($content) {
    
    	global $single;
    	$crp_settings = crp_read_options();
    
        if((is_single())&&($crp_settings['add_to_content'])) {
            return $content.ald_crp();
        } elseif((is_page())&&($crp_settings['add_to_page'])) {
            return $content.ald_crp();
    	} elseif((is_feed())&&($crp_settings['add_to_feed'])) {
            return $content.ald_crp();
        } else {
            return $content;
        }
    }

    http://wordpress.org/extend/plugins/contextual-related-posts/

  2. Ajay
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks. I'll add the checks in. I think a better option would be to check for all three options and if failed, exit the routine.

  3. SEO Dave
    Member
    Posted 2 years ago #

    Nice code fix CodingFabian, I have a plugin derived from CRP and have been trying to figure out why it was interacting with a widget and generating over 100 extra database queries.

    Basically CRP is loading even for posts that are not within the main loop which meant if a widget or other plugin pulled say 5 posts the CRP code would try to find related posts for the 5 posts!! If you had the plugin set to show 5 related, it's finding 30 which it is showing 5.

    The code above fixed it removing over 100 database queries from single posts.

    There's a similar issue with the code running on archive pages, in this case it was worse because it would find 5 posts for the 10 archived posts on an archive page, so 55 posts found with none shown since CRP doesn't output anything on archives. I fixed it about a year ago in the plugin I use, it was resulting in 200+ extra database queries on archives.

    CRP is a great plugin base, I've added Timbthumb support, random thumbnail support, linked it in with a derivative of the All In One SEO Plugin pack so the anchor text and alt text can be changed. My version is hosted at http://www.stallion-theme.com/wordpress-seo-plugins and will be updated soon (need to test it on a theme other than Stallion - SEO theme I develop). Go to the Related Articles at the bottom of the page and refresh the page and see the thumbnails change, pretty cool.

    David

  4. CodingFabian
    Member
    Posted 2 years ago #

    Hi Ajay,

    ald_crp_content() still calls ald_crp() even if $output is not used in the return(). This is quite an important and easy fix I always need to redo every update.

    Fabian

  5. Ajay
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks. I missed that line! I'll definitely put this in the next version

  6. Ajay
    Member
    Plugin Author

    Posted 2 years ago #

    I've incorporated this in v1.8.2

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic