Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi dooza

    Do you need this for the shortcode or the widget, or both?

    Can you post the code for pages to have taxonomies?

    Thread Starter dooza

    (@dooza)

    Hi there,
    At the moment widget, but being able to do both would be great.

    I thought I added code, but it looks like I used a plugin that adds the taxonomies for me: https://www.ads-software.com/plugins/category-tag-pages/

    Cheers,

    Steve

    Plugin Author keesiemeijer

    (@keesiemeijer)

    For the shortcode try the post_types attribute:
    https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/#post-types

    [related_posts_by_tax post_types="page"]

    And for the widget try it with this in your theme’s functions.php file. It adds a ‘page’ checkbox to the widget.

    add_filter( 'related_posts_by_taxonomy_widget_form_fields', 'add_post_type_page_related_widget', 10, 3 );
    
    function add_post_type_page_related_widget( $pieces, $i, $_this ) {
    
    	$post_types         = $_this->defaults->post_types;
    	$post_types['page'] = __('Page');
    	$after              = "\n\t";
    	$before             = "\t";
    
    	// post types
    	$field = '<div class="rpbt_post_types"><h4>' . __( 'Post Types', 'related-posts-by-taxonomy' ) .' </h4><p>';
    	foreach ( $post_types as $name => $label ) {
    		$field .= '<input type="checkbox" class="checkbox" id="' . $_this->get_field_id( 'post_types' ) . "_$name" . '" ';
    		$field .= 'name="' . $_this->get_field_name( 'post_types' ) . "[$name]" .'"';
    		if ( isset( $i['post_types'][ $name ] ) && ( 'on' === $i['post_types'][ $name ] ) ) {
    			$field .= ' checked="checked"';
    		}
    		$field .= ' /> <label for="' .$_this->get_field_id( 'post_types'  ) . "_$name" . '">' . $label . '</label><br />';
    	}
    	$pieces['post_types'] = $before . $field . '</p></div>' . $after;
    
    	return $pieces;
    }

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.

    Thread Starter dooza

    (@dooza)

    Hi there,
    Thank you for the code, I will have a play and let you know how I get on.

    My theme is hand created by me, its based on underscore_s and the Concise CSS framework, so no risk of losing my modifications.

    Cheers,

    Steve

    Thread Starter dooza

    (@dooza)

    It works nicely, thank you!

    One last question, is there a filter I can use to make the list ignore the relevance and just show the most recent?

    Cheers,

    Steve

    Plugin Author keesiemeijer

    (@keesiemeijer)

    For the shortcode try it with the “related” attribute.
    https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/#related

    [related_posts_by_tax post_types="page" related="false"]

    And for the widget try it with this in your theme’s functions.php file. This will display related posts by post date for all related posts widgets.

    add_filter( 'related_posts_by_taxonomy_widget_args', 'widget_not_related', 10, 2 );
    
    function widget_not_related( $args, $instance ) {
    	$args['related'] = false;
    
    	return $args;
    }

    Thread Starter dooza

    (@dooza)

    For some reason my widget doesn’t display at all when I use the above code.

    Steve

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Ah, I see ‘related’ only works if you use the ‘include_terms’ attribute.

    I will add a beta version tomorrow where it displays related posts by post date even if include_terms isn’t used.

    I will let you know when it’s ready.

    Thread Starter dooza

    (@dooza)

    Thank you, your support is awesome!

    Steve

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi dooza

    Download the Development Version (0.4.2-beta1) here:
    https://www.ads-software.com/plugins/related-posts-by-taxonomy/developers/

    Let me know if with the code above it displays the most recent related posts.

    Plugin Author keesiemeijer

    (@keesiemeijer)

    I also found a better way to add the ‘page’ checkbox to the widget. Add this to your functions.php file.

    // Add the 'page' post type just after the plugin's defaults are set (priority 11).
    add_action( 'wp_loaded', 'add_related_post_type_page', 11 );
    
    function add_related_post_type_page() {
    
    	if ( !class_exists( 'Related_Posts_By_Taxonomy_Defaults' ) ) {
    		return;
    	}
    
    	$defaults = Related_Posts_By_Taxonomy_Defaults::get_instance();
    	$defaults->post_types['page'] = __( 'Pages' );
    }

    Remove the old code for the ‘page’ checkbox from your functions.php file if you’re using this.

    Thread Starter dooza

    (@dooza)

    I have uploaded the development version and replaced the page checkbox code with the above. The page checkbox isn’t appearing now.

    The ordering is working on some pages and not others.

    Could you email me and I will show you some test links?

    Cheers,

    Steve

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Thats strange. Can you refresh the widgets page and add a new widget to the sidebar.

    You can contact me here: [contact info redacted]

    Thread Starter dooza

    (@dooza)

    Thank you Kees for the support, all is good now.

    Steve

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Related Pages?’ is closed to new replies.