Show only current wiki and subwikis via widget

Hello guys, whats up? I'm setting up a Wiki to serve as guides, like ign does (ign.com/wikis) on my website (criticalhits.com.br/wikis) and on the sidebar, i'd like to show only my current wiki and it's subwikis via widget.

Is there any fast way I can modify the "Display Wiki Pages" to do this?

If not, well, that's a great suggestion for next updates

Thanks a lot

  • Vinod Dalvi
    • WP Unicorn

    Hi Eric,

    Thank you for your question.

    Unfortunately currently it's not possible with Wiki plugin out of the box.

    I will move this over to the features & feedback section. This way it can be considered for future development, and we can also see what other community members think about the feature request.

    You can display subwikis of current wiki in the widget by adding / modifying the wikiwidget code in the following Wiki plugin file on line numbers 33 and 36 respectively or you can just create a new widget by copy pasting the following wiki widget code and changing the widget class and widget name.

    Wiki widget File Path:
    wiki/lib/classes/WikiWidget.php

    Before Editing:

    $wiki_posts = get_posts(
    	array(
    		'post_parent' => 0,
    		'post_type' => 'incsub_wiki',
    		'orderby' => $order_by,
    		'order' => $order,
    		'numberposts' => 100000
    	)
    );

    After Editing:

    $parent_wiki = ( is_singular('incsub_wiki') ) ? get_the_ID() : 0;
    $wiki_posts = get_posts(
    	array(
    		'post_parent' => $parent_wiki,
    		'post_type' => 'incsub_wiki',
    		'orderby' => $order_by,
    		'order' => $order,
    		'numberposts' => 100000
    	)
    );

    Best Regards,
    Vinod Dalvi

  • Eric
    • WPMU DEV Initiate

    Hello, mr Dalvi, thanks a lot for the response, it worked!

    I just realised, though, that I want to show the first wiki before all the sub-wikis get shown on the menu. Could you help me doing that?

    Thanks a lot!

  • Eric
    • WPMU DEV Initiate

    I've found another issue, If I enter a subwiki and it has no further subwikis, the menu doesn't show at all. I'd like something like:

    On wikis/titanfall/:

    Titanfall (main wiki)
    Burn Cards (Sub wiiki)

    On wikis/titanfall/burn-cards/

    Titanfall (main wiki)
    Burn Cards

    On wikis/teste/: <-- it has no sub wikis

    Teste (main wiki)

  • Eric
    • WPMU DEV Initiate

    I've managed to show the current link also but just on subpages with the follow, but I still can't show the main wiki link when I'm on it. Could anyone help me please?

    $ancestrais = get_post_ancestors(  get_the_ID() );
    
    		$ancestral_distante = end($ancestrais);
    
    		if (empty($ancestral_distante))
    			{ $ancestral_distante = get_the_ID();}
    
    		$wiki_posts = get_posts(
    			array(
    				'post_parent' => $ancestral_distante,
    				'post_type' => 'incsub_wiki',
    				'orderby' => $order_by,
    				'order' => $order,
    				'numberposts' => 100000
    			)
    		);
  • Vinod Dalvi
    • WP Unicorn

    Hi Eric,

    Thank you for your reply.

    To achieve this add the following code in the functions.php file of your child theme or add it in your site using the following plugin.

    http://wordpress.org/plugins/code-snippets/

    function get_top_ancestor($id){
    	$current = get_post($id);
    	if(!$current->post_parent){
    	return $current->ID;
    	} else {
    	return get_top_ancestor($current->post_parent);
    	}
    }

    Change the code in Wiki widget File wiki/lib/classes/WikiWidget.php as following from line number 34 to 47.

    $parent_wiki = ( is_singular('incsub_wiki') ) ? get_the_ID() : 0;
    $wiki_posts = get_posts(
    	array(
    		'post_parent' => $parent_wiki,
    		'post_type' => 'incsub_wiki',
    		'orderby' => $order_by,
    		'order' => $order,
    		'numberposts' => 100000
    	)
    );
    
    		?>
    		<ul>
    			<?php if( empty($wiki_posts) ) {
    				$wiki_post_id = get_top_ancestor($parent_wiki);
    				if($parent_wiki != $wiki_post_id ){
    				$wiki_post = get_post($wiki_post_id);
    				?>
    				<li>
    					<a href="<?php print get_permalink($wiki_post->ID); ?>" class="abc <?php print ($wiki_post->ID == $post->ID)?'current':''; ?>" ><?php print $wiki_post->post_title; ?></a>
    				</li>
    			 <?php } } ?>
    			<?php if( $parent_wiki ) {
    				$wiki_post = get_post($parent_wiki);
    				?>
    				<li>
    					<a href="<?php print get_permalink($wiki_post->ID); ?>" class="abcd <?php print ($wiki_post->ID == $post->ID)?'current':''; ?>" ><?php print $wiki_post->post_title; ?></a>
    				</li>
    			 <?php } ?>
    			<?php
    			foreach ($wiki_posts as $wiki) {
    			?>

    Cheers,
    Vinod Dalvi

  • Eric
    • WPMU DEV Initiate

    One last thing, I believe, If I have 3 sublevels, it shows the third also, is there any way it could show only wiki and sub wikis on wiki page and the subwikis of a subwiki once I'm in a sub wiki (like a drop sub menu once you start opening it's menus)

    check out:

    http://criticalhits.com.br/wikis/dark-souls-2/

    Chefes is a subwiki and Last Giant is a subwiki of Chefes. I'd like to show only Chefes on Dark Souls II page, not it's sub wikis.

  • Vinod Dalvi
    • WP Unicorn

    Hi Eric,

    Hey, that worked! Thanks a lot :slight_smile:

    You are most welcome.

    One last question, is there any way it shows the same menu on Wiki and Sub wiki pages? Once I click a sub-wiki page, the menu shows only the main Wiki and the sub-wiki I'm in.

    One last thing, I believe, If I have 3 sublevels, it shows the third also, is there any way it could show only wiki and sub wikis on wiki page and the subwikis of a subwiki once I'm in a sub wiki (like a drop sub menu once you start opening it's menus)

    You can achieve this by developing some more custom code.

    If you are not a developer then consider hiring a developer from https://premium.wpmudev.org/wpmu-custom-development/ to develop it for you.

    Developing custom code for the new functionality is beyond the scope of support we provide.

    Cheers,
    Vinod Dalvi

  • John Sinclair
    • New Recruit

    I am trying something similar to Eric. I would actually like to make an additional widget that displays only the sub-wikis of the currently selected top level wiki.

    That way I can display all the top level wikis all the time, as well all the detail of the sub-wikis of just the currently selected wiki

    eg
    Wikis
    Wiki 1
    Wiki 2
    Wiki 3 (selected)

    Sub-wikis from selected wiki
    Sub-wiki 1
    Sub-wiki 2
    Sub-wiki 3
    Sub-sub-wiki1

    I hope that all makes sense. can you help me?

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.