This is such a useful plugin, but it’s being marked as abandoned by Wordfence. Is it going to be updated soon?
]]>Is there a way to modify the results so that the siblings of the ‘top level’ page are included in the results? I’m working in a structure where the actual top level pages are a different CPT and so don’t count, and I don’t want to change the structure which would change all the URLs!
]]>Hello,
This is a pretty straight-forward but neat plugin. I just have a feature request that maybe it could support Hierarchical Post Types. A simple selectbox would do, defaulting to Pages.
]]>Description says,
When on a page, it will find the section’s top level page and list its children.
How would one embed the widget in the content area of a page? Does it require another plugin (such as amr Shortcode Any Widget or Custom Content Shortcode)? Or must one add a snippet to functions.php?
Or have I misunderstood?
PS: I use the plugin on many sites. However, I’ve had to use the pagelist plugin to add section navigation on what I call section landing pages
]]>Hi Bill,
Thanks for the great plugin.
My question concerns the option “Use top level page as section title.”
I would like the top level page to appear just like the sub pages. That is, I don’t want the top level page to be styled as an <h3> element. Really, I don’t want it to appear as the title of the section, I just want it to be the first item in the list. I want it to be styled exactly the same as the sub pages.
Can you tell me how to do this?
]]>Greetings!
How can I use your plugin to automatically list all subpages — not just the next level of supbages?
For example:
Category
-Subpage 1
-Subpage 2
-Subpage 3
Category
-Subpage 1
-Subpage 1
-Subpage 1
The ideal would be that all the subpages listed by dashes would be automatically displayed without have to first click on the containing category above.
]]>Dears,
The plugin works great, but how can I include a specific menu pages in a PHP page? Imagine that the parent page is for example “News”, and I’d like to include its sub pages in archive.php page. How can I do that?
Thanks.
]]>Is there a way to hide some pages from showing? I’ve installed https://www.ads-software.com/plugins/exclude-pages-from-menu/ but it’s not stopping the few pages from showing up.
]]>I’d like to be able to show an indicator, such as an arrow, if the page contains sub-pages.
]]>Hello,
is it possible to add “has-children” class to parent li which has children?
Regards
Daniel
Hello!
I believe that the conditional on be-subpages-widget.php
Line 53 should read:
if ( !is_singular( $post_types ) || !apply_filters( 'be_subpages_widget_display_override', true ) )
Instead of &&
, and instead of false
. So if either of the test are true, the widget drops and returns nothing to display. Otherwise the filter simply never fires.
Usage example includes:
/**
* Don't display subpages on this specific page
*
* @param Boolean $show - Whether to show the Widget
*
* @return Boolean $show
*/
function mod_be_subpages_widget( $show ) {
global $post;
if( is_object( $post ) && 6 == $post->ID || 6 == $post->post_parent ) {
$show = false;
}
return $show
}
add_filter( 'be_subpages_widget_display_override', 'mod_be_subpages_widget' );
]]>
Hello!
Is there a way for the menu to highlight the active page? My menu currently does not indicate if the parent or child pages are active.
Thank you in advance!
]]>Before the most recent update, this filter worked to always display all sub pages, but it seems to have stopped working and is no longer in the code. Am I missing something, or is there a new filter for that same functionality?
//* Display all subpages in BE Subpages Widget
add_filter( 'be_subpages_widget_display_subpages', '__return_true' );
Basically I want it to display the expanded subpage menu at all times:
Parent A
Child B
Child C
Parent D
Child E
Child F
Hello,
Can the archive and single view pages of a CPT show up in the sidebar navigation if there is not a Page for either of them?
We are using a Genesis child theme (Education Pro) and created a CPT (Locations) with hierarchical set to true.
We added a Post Type Archive as a child of a primary menu item:
Appearance > Menus – Chose the CPT then added to menu as a child
At this point in the menu we have:
About Us (Page)
– Locations (Post Type Archive)
– Culture (Page)
When we view the site in a browser About Us in the primary menu has two children in its drop down menu.
When we go to About Us or Culture we see a sidebar menu that contains both About Us and Culture but not Locations. When we are on the Locations archive or single view pages there is no sidebar at all.
We saw this: https://www.ads-software.com/support/topic/submenu-on-post/ but it is from 2 years ago and we are not sure it is still relevant.
We saw this https://www.ads-software.com/support/topic/cant-get-it-to-display-on-cpt/ and it is exactly our problem but we are not already seeing the sidebar menu on the single page and the 4th paragraph in your answer seems to suggest we should. So perhaps some other issue is causing our problem?
Another developer and I have looked over your plugin code and it seems like the plugin will only work with Pages. Although we both have been web developers for years, we are fairly new to WordPress and really new to Genesis, so we are not sure we understand all that your code is doing.
Since we are not sure how/where to continue troubleshooting, we thought we should at least determine if what we are trying to do is even possible with your plugin. We are using ver 1.6.
This fellow Georgetown resident appreciates your making so much of your code and knowledge available. Thanks!
robertg
]]>The CPT archive page and single pages display the primary sidebar correctly, but does not display the widget. If you need a link, I would rather send in private since it is a beta page.
]]>It is possible to have the sub-pages listed in alphabetical order rather than published order?
]]>Hi Bill. Can you please provide some guidance on using the be_subpages_page_title filter?
I have tried to follow this Alternative link title post, but I can’t get it working.
I have used Advanced Custom Fields to add a meta_key called be_alt_link_title on the postmeta table. I have added an alternative title to a page and can see it in the postmeta table in SQL. I then added the code from your post https://gist.github.com/billerickson/eae1345d8df6c45c47aa to my child theme’s functions.php file:
/**
* Alternate Title for Subpages
*
* @author Bill Erickson
* @link https://gist.github.com/billerickson/eae1345d8df6c45c47aa
*
* @param string $title
* @param object $subpage
* @return string $title
*/
function be_subpages_alternate_title( $title, $subpage ) {
$alt = esc_attr( get_post_meta( $subpage->ID, 'be_alt_link_title', true ) );
if( $alt )
$title = $alt;
return $title;
}
add_filter( 'be_subpages_page_title', 'be_subpages_alternate_title', 10, 2 );
My expectation is that the title of that page will change in the sidebar and will show the alternative title. But nothing is changing. It is still just showing the full title.
Can you provide guidance for getting that working please?
Thanks!
]]>I have this hierarchy:
Sub Page 1
Sub Page 2
– SubSubPage 1
– SubSubPage 2
Sub Page 3
Sub Page 4
– SubSubSubPage 1
— A
— B
— C
– SubSubSubPage 2
When i select sub page 2, it will show subsubpage 1 and subsubpage 2 in the sidebar. And when i select SubSubSubPage 1, it will show A, B and C only and the sidebar title is SubSubSubPage 1.
How could i do this?
]]>Hi. One thing that I’ve found is missing from this BE Subpages Widget plugin is the ability to exclude specific pages. For example, I don’t want “Thank You” pages to appear in the list of subpages in the sidebar.
But I’ve just discovered that the BE Subpages Widget plugin works perfectly with the Exclude Pages from Navigation plugin.
The Exclude Pages plugin gives a checkbox on each page that we can untick to exclude pages – and this BE Subpages plugin honours that, which is brilliant.
My recommendation is to mention this on the description page for BE Subpages Widget, because being able to exclude pages is a key thing I was looking for. I searched through many subpages plugins looking for one that supported excluding pages, and now find that your one works well with that other plugin, giving the exact functionality I need.
]]>I don’t see anything at all in the sidebar from this plugin. The widget is in place.
On this page each header listed is a link to a subpage. https://toni-esl.com/grammar/
So there should be something on each of those subpages, right? I don’t see anything, I’m on an iPad.
]]>… since version 4.3.0! Use
__construct()
??
]]>Is it possible to hide to top levels and just show the children pages.
]]>This is not really a problem rather a request. I would like to be able to have this widget get all the subpages of the subpage. I have currently changed/added some lines in be-subpages-widget.php to do this. I then use css to hide the sub-subpages and use a :hover to show them as sublinks. Here are the changes I’ve made in the above file.
function build_subpages( $subpages, $parents, $deep_subpages = 0, $depth = 1, $nest_subpages = 0 ) {
if( empty( $subpages ) )
return;
global $post, $be_subpages_is_first;
// Build the page listing
// ADDED THIS IF() HERE TO ADD AN IMAGE TO THE CHILD THAT CONTAINS CHILDERN
if ($depth != 1){
echo '<img src="https://huntsd.org/wp-content/plugins/be-subpages-widget/drop_down_arrow.gif" style="float:right;"/><ul class="sub_subpages">';}
else{
echo '<ul class="subpages" id="accordian">';//added <div id="accordian">
}//END CHANGE
foreach ( $subpages as $subpage ) {
$class = array();
// Unique Identifier
$class[] = 'menu-item-' . $subpage->ID;
// Set special class for current page
if ( $subpage->ID == $post->ID )
$class[] = 'widget_subpages_current_page';
// First menu item
if( $be_subpages_is_first )
$class[] .= 'first-menu-item';
$be_subpages_is_first = false;
$class = apply_filters( 'be_subpages_widget_class', $class, $subpage );
$class = !empty( $class ) ? ' class="' . implode( ' ', $class ) . '"' : '';
echo '<li' . $class . '><a href="' . get_permalink( $subpage->ID ) . '">' . apply_filters( 'be_subpages_page_title', $subpage->post_title, $subpage ) . '</a>';
// If nesting supress the closing li
if (!$nest_subpages)
echo '</li>';
do_action( 'be_subpages_widget_menu_extra', $subpage, $class );
// Check if the subpage is in parent tree to go deeper
//if ( $deep_subpages && in_array( $subpage->ID, $parents ) ) { I'M REALLY NOT EXACTLY SURE WHAT THIS IF DOES BUT IT DOESN'T ALLOW THE CHILD PAGE TO GET IT'S CHILDREN PAGES
$args = array(
'child_of' => $subpage->ID,
'parent' => $subpage->ID,
'sort_column' => 'menu_order',
'post_type' => get_post_type(),
);
$deeper_pages = get_pages( apply_filters( 'be_subpages_widget_args', $args, $depth ) );
$depth++;
$this->build_subpages( $deeper_pages, $parents, $deep_subpages, $depth, $nest_subpages );
//}
// If li was surpressed for nesting echo it now
if ($nest_subpages)
echo '</li>';
}
echo '</ul>';
}
This also adds a subpages css class for applying style.
My site is https://www.huntsd.org and examples can be found under District Info.
I’m only asking for this to maybe a possibility for an actual release and not sure if this is even the place to put this. Thanks for the consideration.
]]>Resolved.
]]>Hey Bill,
I was wondering if you help me out with what I imagine is a simple task although im miserably failing at it.
I need to add your widget programatically to my page. I’ve already have displaying on the page but I can’t figure out how to setup a few defaults, as defined usually on the widget configuration when added via Dashboard. More specifically, I was looking into displaying the parent page name as the widget title, one of the options available in the widget configuration.
I looked into the be_subpages_widget_title
filter but couldn’t make it do any difference in the rendered page.
function mw_widget_title( $title )
{
$title = "test";
return $title;
}
add_filter( 'be_subpages_widget_title', 'mw_widget_title' );
Thanks.
]]>Hi Bill,
i added an option to your plugin to make the selected pages and its parents bold.
<style type="text/css">
.widget_subpages_current_page > a{
font-weight: bold;
}
.widget_subpages_subpage_is_selected > a{
font-weight: bold;
}
</style>
<?php
/*
Plugin Name: BE Subpages Widget
Plugin URI: https://www.billerickson.net
Description: Lists subpages of the current section
Version: 1.5
Author: Bill Erickson
Author URI: https://www.billerickson.net
License: GPLv2
*/
/**
* Register Widget
*
*/
function be_subpages_load_widgets() {
register_widget( 'BE_Subpages_Widget' );
}
add_action( 'widgets_init', 'be_subpages_load_widgets' );
/**
* Subpages Widget Class
*
* @author Bill Erickson <[email protected]>
* @copyright Copyright (c) 2011, Bill Erickson
* @license https://opensource.org/licenses/gpl-2.0.php GNU Public License
*/
class BE_Subpages_Widget extends WP_Widget {
/**
* Constructor
*
* @return void
**/
function BE_Subpages_Widget() {
load_plugin_textdomain( 'be-subpages', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
$widget_ops = array( 'classname' => 'widget_subpages', 'description' => __( 'Lists current section subpages', 'be-subpages' ) );
$this->WP_Widget( 'subpages-widget', __( 'Subpages Widget', 'be-subpages' ), $widget_ops );
}
/**
* Outputs the HTML for this widget.
*
* @param array, An array of standard parameters for widgets in this theme
* @param array, An array of settings for this widget instance
* @return void Echoes it's output
**/
function widget( $args, $instance ) {
extract( $args, EXTR_SKIP );
// Only run on hierarchical post types
$post_types = get_post_types( array( 'hierarchical' => true ) );
if ( !is_singular( $post_types ) && !apply_filters( 'be_subpages_widget_display_override', false ) )
return;
// Find top level parent and create path to it
global $post;
$parents = array_reverse( get_ancestors( $post->ID, 'page' ) );
$parents[] = $post->ID;
$parents = apply_filters( 'be_subpages_widget_parents', $parents );
// Build a menu listing top level parent's children
$args = array(
'child_of' => $parents[0],
'parent' => $parents[0],
'sort_column' => 'menu_order',
'post_type' => get_post_type(),
);
$depth = 1;
$subpages = get_pages( apply_filters( 'be_subpages_widget_args', $args, $depth ) );
// If there are pages, display the widget
if ( empty( $subpages ) )
return;
echo $before_widget;
global $be_subpages_is_first;
$be_subpages_is_first = true;
// Build title
$title = esc_attr( $instance['title'] );
if( 1 == $instance['title_from_parent'] ) {
$title = get_the_title( $parents[0] );
if( 1 == $instance['title_link'] )
$title = '<a href="' . get_permalink( $parents[0] ) . '">' . apply_filters( 'be_subpages_widget_title', $title ) . '</a>';
}
if( !empty( $title ) )
echo $before_title . $title . $after_title;
if( !isset( $instance['deep_subpages'] ) )
$instance['deep_subpages'] = 0;
if( !isset( $instance['nest_subpages'] ) )
$instance['nest_subpages'] = 0;
// Print the tree
$this->build_subpages( $subpages, $parents, $instance['deep_subpages'], $depth, $instance['nest_subpages'], $instance['format_subpage_and_parents'] );
echo $after_widget;
}
/**
* Build the Subpages
*
* @param array $subpages, array of post objects
* @param array $parents, array of parent IDs
* @param bool $deep_subpages, whether to include current page's subpages
* @return string $output
*/
function build_subpages( $subpages, $parents, $deep_subpages = 0, $depth = 1, $nest_subpages = 0, $format_subpage_and_parents ) {
if( empty( $subpages ) )
return;
global $post, $be_subpages_is_first;
// Build the page listing
echo '<ul>';
foreach ( $subpages as $subpage ) {
$class = array();
// Unique Identifier
$class[] = 'menu-item-' . $subpage->ID;
// Check if format_subpage_and_parents is set
if( $format_subpage_and_parents == 1 ) {
// Set special class for current page parents
if ( in_array( $subpage->ID, $parents ) )
$class[] = 'widget_subpages_subpage_is_selected';
// Set special class for current page
if ( $subpage->ID == $post->ID )
$class[] = 'widget_subpages_current_page';
}
// First menu item
if( $be_subpages_is_first )
$class[] .= 'first-menu-item';
$be_subpages_is_first = false;
$class = apply_filters( 'be_subpages_widget_class', $class, $subpage );
$class = !empty( $class ) ? ' class="' . implode( ' ', $class ) . '"' : '';
echo '<li' . $class . '><a href="' . get_permalink( $subpage->ID ) . '">' . apply_filters( 'be_subpages_page_title', $subpage->post_title, $subpage ) . '</a>';
// If nesting supress the closing li
if (!$nest_subpages)
echo '</li>';
do_action( 'be_subpages_widget_menu_extra', $subpage, $class );
// Check if the subpage is in parent tree to go deeper
if ( $deep_subpages && in_array( $subpage->ID, $parents ) ) {
$args = array(
'child_of' => $subpage->ID,
'parent' => $subpage->ID,
'sort_column' => 'menu_order',
'post_type' => get_post_type(),
);
$deeper_pages = get_pages( apply_filters( 'be_subpages_widget_args', $args, $depth ) );
$depth++;
$this->build_subpages( $deeper_pages, $parents, $deep_subpages, $depth, $nest_subpages, $format_subpage_and_parents );
}
// If li was surpressed for nesting echo it now
if ($nest_subpages)
echo '</li>';
}
echo '</ul>';
}
/**
* Sanitizes form inputs on save
*
* @param array $new_instance
* @param array $old_instance
* @return array $new_instance
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
/* Strip tags (if needed) and update the widget settings. */
$instance['title'] = esc_attr( $new_instance['title'] );
$instance['title_from_parent'] = (int) $new_instance['title_from_parent'];
$instance['title_link'] = (int) $new_instance['title_link'];
$instance['deep_subpages'] = (int) $new_instance['deep_subpages'];
$instance['nest_subpages'] = (int) $new_instance['nest_subpages'];
$instance['format_subpage_and_parents'] = (int) $new_instance['format_subpage_and_parents'];
return $instance;
}
/**
* Build the widget's form
*
* @param array $instance, An array of settings for this widget instance
* @return null
*/
function form( $instance ) {
/* Set up some default widget settings. */
$defaults = array( 'title' => '', 'title_from_parent' => 0, 'title_link' => 0, 'deep_subpages' => 0, 'nest_subpages' => 0 , 'format_subpage_and_parents' => 0);
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'be-subpages' );?></label>
<input class="widefat" type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" />
</p>
<p>
<input class="checkbox" type="checkbox" value="1" <?php checked( $instance['title_from_parent'], 1 ); ?> id="<?php echo $this->get_field_id( 'title_from_parent' ); ?>" name="<?php echo $this->get_field_name( 'title_from_parent' ); ?>" />
<label for="<?php echo $this->get_field_id( 'title_from_parent' ); ?>"><?php _e( 'Use top level page as section title.', 'be-subpages' );?></label>
</p>
<p>
<input class="checkbox" type="checkbox" value="1" <?php checked( $instance['title_link'], 1 ); ?> id="<?php echo $this->get_field_id( 'title_link' ); ?>" name="<?php echo $this->get_field_name( 'title_link' ); ?>" />
<label for="<?php echo $this->get_field_id( 'title_link' ); ?>"><?php _e( 'Make title a link', 'be-subpages' ); echo '<br /><em>('; _e( 'only if "use top level page" is checked', 'be-subpages' ); echo ')</em></label>';?>
</p>
<p>
<input class="checkbox" type="checkbox" value="1" <?php checked( $instance['deep_subpages'], 1 ); ?> id="<?php echo $this->get_field_id( 'deep_subpages' ); ?>" name="<?php echo $this->get_field_name( 'deep_subpages' ); ?>" />
<label for="<?php echo $this->get_field_id( 'deep_subpages' ); ?>"><?php _e( 'Include the current page\'s subpages', 'be-subpages' ); ?></label>
</p>
<p>
<input class="checkbox" type="checkbox" value="1" <?php checked( $instance['nest_subpages'], 1 ); ?> id="<?php echo $this->get_field_id( 'nest_subpages' ); ?>" name="<?php echo $this->get_field_name( 'nest_subpages' ); ?>" />
<label for="<?php echo $this->get_field_id( 'nest_subpages' ); ?>"><?php _e( 'Nest sub-page <ul> inside parent <li>', 'be-subpages' ); echo '<br /><em>('; _e( "only if "Include the current page's subpages" is checked", 'be-subpages' ); echo ')</em></label>';?>
</p>
<p>
<input class="checkbox" type="checkbox" value="1" <?php checked( $instance['format_subpage_and_parents'], 1 ); ?> id="<?php echo $this->get_field_id( 'format_subpage_and_parents' ); ?>" name="<?php echo $this->get_field_name( 'format_subpage_and_parents' ); ?>" />
<label for="<?php echo $this->get_field_id( 'format_subpage_and_parents' ); ?>"><?php _e( 'Format selected page and parents', 'be-subpages' ); ?></label>
</p>
<?php
}
}
]]>
Hello,
i added the line to my css-file:
.widget_subpages_current_page a {
font-weight: bold;
}
and this works.
The Problem is, if a subpage has another subpage, they both are shown bold.
e.g.
-Main1.1
-Main1.2
-Main1.3 (selected)
–Main1.3.1
and
-Main1.1
-Main1.2
-Main1.3
–Main1.3.1 (selected)
In the first example i want only the selected page to be highlighted.
The second one works fine.
I use wordpress Version 4.0.1 and the plugin Version 1.5
Thanks for your help.
(sorry for my english)
Hi, I saw this question being asked before in the form but unfortunately I don’t have the technical knowledge to use it.
I want to highlight current page I’m on, so the user can easily see which page is next.
Your previous answer to the question was;
“The plugin indicates the current selected item with class .widget_subpages_current_page
Style the li with the class and you are done!”
Could you please explain what the above means in more detail?
Thanks
]]>My menu looks like this:
About Us
Link1
A
B
Link2
C
D
Link3
It’s easy to create a widget to show Link1, Link2 and Link3 subpages when you are on About Us page but is it possible to only show A and B pages when you are visiting Link1 or C and D when you are visiting Link2?
Thanks
]]>Hi Bill,
Phenomenal plugin! Thanks for the awesome, free work.
Here’s the question, perhaps someone else can help me:
When attempting to style the “current page item” to appear a different color using:
.widget_subpages_current_page ul a {
color:#000;
}
it works, to a degree. My top level pages are turning black when they’re the current page, but so do ALL of its children. BUT, when I am on one of the child pages in the menu, only that item is black. So, the problem in a nutshell,since I rarely make sense when typing, is that when my top level page is the “current page,” it styles that link ALONG with the rest of its children. But when a child page is “current page,” it only styles that link.
I DO have “nest subpage ul inside parent li” checked, because I absolutely want that appearance.. but it seems the styling is carried over when the parent is selected. Any ideas on how to CSS around this little roadblock?
Thanks,
Mark