• Resolved themichaelglenn

    (@themichaelglenn)


    Hi,

    I have a custom taxonomy that is shared by pages, posts, forums and topics. Using your plugin (and widget), I’m able to show related posts on corresponding pages, posts, and forums – but not on topics. So I’d like to know if there’s a way your plugin can use the taxonomy assigned to the parent forum, and display related posts when I’m viewing a “topic” page?

    Also, I’d like the related posts to differ, depending on what page type the user is on. Specifically:

    If someone is on a “page” I want to show one link that says “For more help, check ‘x’ forum”, followed by a group of links to ‘x’ posts.
    (‘x’ being the name of the taxonomy.)

    If on a “post,” I want the one link to ‘x’ forum, followed by links to the child pages of the top-level page for ‘x’.

    If on a forum (or topic), I want links to the ‘x’ child pages, followed by links to ‘x’ posts.

    Can this be accomplished with your plugin, and if so, what do I need to do to make it work this way?

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

    (@keesiemeijer)

    Hi themichaelglenn

    Can you see forum post types (topics?) in the widget?
    What forum plugin are you using?

    Can you post links to a topic?

    Thread Starter themichaelglenn

    (@themichaelglenn)

    I just found the topics post type in the widget, so sorry… It does work now on topics, as long as the topic has been assigned to the correct taxonomy.

    As for the rest of my question – I also found the widget settings that let me choose between post, forum, topic, and reply, so that’s all working properly as well. (I should have found all that before writing this post, so that’s my fault for not checking everything out…)

    So the only thing I want to do now, that the plugin doesn’t do, is show links to related “pages” – but, I only want to show the links to the first-child pages of the top level parent page within that taxonomy.

    Right now I’m only playing with the plugin on a development site, but if I take it live and have any problems I’ll give the live URL.

    • This reply was modified 6 years, 7 months ago by themichaelglenn. Reason: Further explanation of what I want to achieve
    Plugin Author keesiemeijer

    (@keesiemeijer)

    You can use your own template to output the related posts.
    https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/templates/

    There you could use conditional tags to output what you want.
    https://developer.wordpress.org/themes/basics/conditional-tags/

    This plugin shows related posts with terms in common from the taxonomy ‘x’.

    It’s not really clear what it is you want to do, for example:
    On pages you want to get the related pages, but display the top level first-child pages for those related pages?

    Thread Starter themichaelglenn

    (@themichaelglenn)

    Holy smokes I think the example for using your own template is a bit over my head!

    Anyway, let me see if I can do a better job explaining what I meant. I run a gaming site that’s split into three main sections: Games, Forums, and Blog.

    Games – this is where all the game “pages” are. Pages are heirarchical (naturally), and the page with the “name of the game” is the top level parent. (For example, if the game was Final Fantasy, the top level parent page would be “final-fantasy.”)

    Next, the child pages. Games that have child pages have something like the following:

    Hints and Tips
    Location Walkthrough
    Skill List

    Now, within each child page, there are pages that relate to that subject. So, if there’s a location walkthrough page called “Home Town,” it would under “final-fantasy/location-walkthrough/hometown.” Whereas a skill list for, let’s say, a black mage, would be “final-fantasy/skill-list/black-mage.”

    Then of course there’s the bbPress forum, and the blog (which only contains “posts”). I assume those sections are self-explanatory.

    What I was thinking in terms of my “Game” pages and your plugin, was that if someone is reading a forum topic or a blog post on “Final Fantasy,” it would be nice to have links to the Final Fantasy child pages, i.e.:

    Hints and Tips
    Location Walkthrough
    Skill List

    instead of random links to random Final Fantasy pages that could be anywhere in the hierarchy…

    But, having installed your plugin and seen how it works with posts, forums and topics, I think I’d actually be just as happy if you could simply add support for “pages” – even if the result was a “random” list of related pages anywhere within the same taxonomy.

    (I actually can sort of see how that could be better, anyway, because the exact pages the plugin would come up with would probably be more closely related to the specific forum topic or blog post… so my original thought may not have been all that great to begin with.)

    I hope that makes it more clear, and that you can help me find a way to add page support to an otherwise perfect plugin.

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Sorry for the very late reply.

    Thanks, I have a better understanding now. Let’s stay with the ‘final fantasy’ example. As I understand it, all final fantasy Pages get a term of ‘final fantasy’ to relate them to posts and forum posts (also with that term)?

    To get only the first child pages (if you still want that), we don’t need the related posts query. I think I can find a way to override the posts the widget uses.

    For post type Page support in the widget see this
    https://keesiemeijer.wordpress.com/related-posts-by-taxonomy/recipes/#widget_page

    Thread Starter themichaelglenn

    (@themichaelglenn)

    Yes, all pages, posts, and forum posts associated with the game ‘Final Fantasy’ would share the term ‘final fantasy.’ Likewise, all pages, posts, and forums associated with, say, ‘Mario Kart,’ would share the term ‘mario kart.’

    (It was the only way I could think of to get the results I wanted.)

    I may be using your plugin a bit differently than most:

    On “Game” Pages, I use two widgets; one to show 5 related forum topics, and one to show 5 related blog posts.
    On “Forum” Topics, I use three widgets; one for 5 forum topics, one for 5 blog posts, and one for 5 pages.
    Then, on “Blog” Posts, I also use all three widgets.

    (On my “Game” Pages, I have another plugin that displays the menu for all pages for that particular game, i.e. ‘final fantasy’ world map, location walkthrough, hints and tips, etc. And they’re all displayed heirarchically – if that’s a word? – anyway those links work the way I want them to on the “Game” pages… and with your plugin to take care of all the rest, I’m very satisfied now with how the rest of the related content links appear.)

    I added Page support to the widget, by the way, and for the moment I think I’m satisfied with showing 5 related pages, rather than links to the specific child pages. However, if I had an option to show the specific child pages instead, then what I would do is to ask my members if ‘choice a’ worked better than ‘choice b’ (but I don’t want to offer two choices, unless I know I can deliver on the specific child pages if that’s the one they choose.)

    So, if there’s an easy workaround to use your plugin/widget to show the top level child pages (or, rather, the children of the top level parent page), that would be great. But if it’s gonna take you a ton of effort, then I wouldn’t bother.

    Like I said, overall I’m very satisfied with this plugin.

    Plugin Author keesiemeijer

    (@keesiemeijer)

    Hi agiain

    I’ve come up with this. Put it in your functions.php

    
    // Create  a new format parent_first_child and add support for pages in the widget
    add_action( 'wp_loaded', 'rpbt_first_child_page_format_and_page_support', 11 );
    
    function rpbt_first_child_page_format_and_page_support() {
    
    	if ( ! class_exists( 'Related_Posts_By_Taxonomy_Defaults' ) ) {
    		return;
    	}
    
    	$defaults = Related_Posts_By_Taxonomy_Defaults::get_instance();
    
    	// Add the new format .
    	$defaults->formats['parent_first_child'] = __( 'First child pages' );
    
    	// Add page support for the widget
    	$defaults->post_types['page'] = __( 'Pages' );
    }
    
    // If the new format is used and we're on a page display first level pages with the widget.
    add_action( 'widget_display_callback', 'page_widget_output', 10, 3 );
    
    function page_widget_output( $instance, $widget, $args ) {
    	$plugin = function_exists( 'km_rpbt_plugin' ) ? km_rpbt_plugin() : false;
    
    	// Check if the plugin is activated and this is the related posts widget.
    	if ( ! $plugin || ( 'Related Posts By Taxonomy' !== $args['widget_name'] ) ) {
    		return $instance;
    	}
    
    	// Get all default settings for the widget.
    	$instance = array_merge( $plugin->get_default_settings( 'widget' ), $instance );
    
    	// Get the post types selected in the widget.
    	$post_types = array_keys( $instance['post_types'] );
    
    	// See if only 'page' post type is selected.
    	$is_post_type_page = ( array( 'page' ) == array_values( $post_types ) );
    
    	if ( ! ( $is_post_type_page && is_page() && ( 'parent_first_child' === $instance['format'] ) ) ) {
    		return $instance;
    	}
    
    	// Get the current page ID.
    	$page_id = get_the_ID();
    
    	// Get an array of Ancestors and Parents if they exist.
    	$parents = get_post_ancestors( $page_id );
    
    	// Get the top Level page->ID.
    	$parent_id = ( $parents ) ? $parents[ count( $parents ) - 1 ] : $page_id;
    
    	if ( ! $parent_id ) {
    		// Do not display the widget if no parent page ID is found.
    		return false;
    	}
    
    	// Query for first level pages.
    	$query_args = array(
    		'parent'  => $parent_id,
    		'exclude' => array( $page_id ),
    	);
    
    	// Use the first level pages to display with the widget.
    	$first_child_pages = get_pages( $query_args );
    
    	// Echo the widget.
    	$widget->widget_output( $first_child_pages, $instance, $args );
    
    	// Important to return false as we have already displayed the widget.
    	return false;
    }

    In the first function page support and a new format is added for use in the widget. (you can remove the page support you’ve added earlier)

    Now, if you select only the post type “Page” and use the format “First child pages” in the widget the first child pages are displayed. It only displays the first child pages if you’re visiting a Page.

    I hope this comes close to what you need 🙂

    btw:
    consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Showing different results on pages, posts, forums and topics’ is closed to new replies.