Ninja Pages Shortcode

Below, you’ll find a detailed guide on how to add the Ninja Pages Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Ninja Pages Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the Ninja Pages Plugin and the shortcodes it provides:

Plugin Icon
Ninja Pages

"Ninja Pages is a dynamic WordPress plugin designed to efficiently categorize and tag your pages. Easy to use, it enhances organization and user navigation."

★★★★☆ (12) Active Installs: 4000+ Tested with: 4.6.27 PHP Version: false
Included Shortcodes:
  • [ninja_child_pages]

Ninja Pages [ninja_child_pages] Shortcode

The ninja-page-categories-and-tags plugin shortcode ‘ninja_child_pages’ is designed to display child pages of a parent page. The shortcode fetches child pages based on specified parameters like number of children, order, and orderby. It also checks if the current page is not an archive. The child pages are then displayed with their thumbnails, titles, and excerpts.

Shortcode: [ninja_child_pages]

Examples and Usage

Basic example – The shortcode displays the child pages of the current page in a structured format.

[ninja_child_pages /]

Advanced examples

Displaying child pages with a specific number of posts. The ‘num_children’ attribute is used to limit the number of child pages displayed. For instance, if you want to display only 5 child pages, you would use the following shortcode:

[ninja_child_pages num_children=5 /]

Ordering child pages by a specific parameter. The ‘orderby’ attribute can be used to order child pages by title, date, ID, or author. For example, to order child pages by title, you would use the following shortcode:

[ninja_child_pages orderby=title /]

Changing the order of child pages. The ‘order’ attribute can be used to display child pages in ascending (ASC) or descending (DESC) order. For instance, to display child pages in descending order, you would use the following shortcode:

[ninja_child_pages order=DESC /]

Combining different attributes. You can use multiple attributes in a single shortcode to customize the display of child pages. For example, the following shortcode displays 5 child pages, ordered by title in descending order:

[ninja_child_pages num_children=5 orderby=title order=DESC /]

PHP Function Code

In case you have difficulties debugging what causing issues with [ninja_child_pages] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('ninja_child_pages', 'ninjapages_child_pages');

Shortcode PHP function:

                    function ninjapages_child_pages( $content ) {

	global $post; // required

	$opt = get_option('ninja_pages_options');
	if( isset( $opt['display_children'] ) ) {
		$content = $content;
	} else {
		$content = '';
	}
	if( isset( $opt['num_children'] ) ) {
		$num = $opt['num_children'];
	} else {
		$num = get_option('posts_per_page');
	}
	if( isset( $opt['orderby'] ) ) {
		$orderby = $opt['orderby'];
	} else {
		$orderby = 'menu_order';
	}
	if( isset( $opt['order'] ) ) {
		$order = $opt['order'];
	} else {
		$order = 'ASC';
	}
	if( !is_archive() ) {

		$args = array(
			'post_type' => 'page',
			'post_parent' => $post->ID,
			'posts_per_page' => $num,
			'orderby' => $orderby,
			'order' => $order,
		);

		$children = new WP_Query( $args );

		//print_r($args);
		if ( $children ) {

			$content .= '<div id="ninja-children-wrap">';

			while( $children->have_posts()) : $children->the_post();

				$content .= '<div class="ninja-child-wrap">';
				if( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) {
					$content .= '<div class="ninja-child-thumbnail">';
					$content .= get_the_post_thumbnail( $post->ID, 'thumbnail' );
					$content .= '</div>';
				}
				$content .= '<h3 class="ninja-child-title">';
					$content .= '<a href="' . get_permalink() . '">';
					$content .= get_the_title();
					$content .= '</a>';
				$content .= '</h3>';
				$content .= '<div class="ninja-child-entry">';
					$content .= get_the_excerpt();
				$content .= '</div>';
				$content .= '</div>';

			endwhile;

			$content .= '</div>';

		}

	}

	return $content;

}
                    

Code file location:

ninja-page-categories-and-tags/ninja-page-categories-and-tags/shortcodes.php

Conclusion

Now that you’ve learned how to embed the Ninja Pages Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *