args = $args;
if (! $this->args['print']) {
$this->the_html_sitemaps($this->args);
}
}
/**
* Get the author list
*
* @see https://codex.wordpress.org/Function_Reference/wp_list_authors
* @param array $author_args Arguments for wp_list_author().
* @return string Return list of author
*/
private function get_wp_list_author($author_args = [])
{
$author_args['echo'] = false;
return wp_list_authors($author_args);
}
/**
* Get the pages list
*
* @see https://codex.wordpress.org/Function_Reference/wp_list_pages
* @param array $pages_args Argument for wp_list_pages()
* @return string Return list of pages
*/
private function get_wp_list_pages($pages_args = [])
{
$pages_args['title_li'] = '';
$pages_args['echo'] = false;
return wp_list_pages($pages_args);
}
/**
* Print the HTML sitemaps
*
* @param array $args The arguments for class.
*/
public function the_html_sitemaps($args = [])
{
echo $this->get_the_html_sitemaps($args); // XSS ok.
}
/**
* Get the HTML sitemaps outputs
*
* @param array $args Argument for HTML sitemaps.
* @return string Return the HTML sitemaps
*/
public function get_the_html_sitemaps($args = [])
{
/**
* The post HTML output
*
* @var string
*/
$posts_output = '';
$posts_output .= '
';
//http://yoast.com/html-sitemap-wordpress/
//
// var_dump(get_pages());
// var_dump(get_posts());
/**
* Args for wp_list_authors function
*
* @var array
*/
$author_args = ['exclude_admin' => false];
$posts_output .= '
' . __('Authors:', 'italystrap') . '
' . $this->get_wp_list_author($author_args) . '
';
/**
* A list of post names registered
*
* @var array
*/
$post_types = get_post_types(['public' => true]);
foreach ($post_types as $post_type) {
// if ( in_array( $post_type, array('post','page','attachment') ) )
// continue;
$pt = get_post_type_object($post_type);
if ('post' === $post_type) {
$posts_output .= '
' . $pt->labels->name . '
';
/**
* Returns an array of category objects matching the query parameters.
*
* @link https://codex.wordpress.org/Function_Reference/get_categories
* @var array
*/
$cats = get_categories(['hide_empty' => 1]);
foreach ($cats as $cat) {
$posts_output .= '' . $cat->cat_name . '
';
query_posts('posts_per_page=-1&cat=' . $cat->cat_ID);
while (have_posts()) {
the_post();
$category = get_the_category();
// Only display a post link once, even if it's in multiple categories.
if ($category[0]->cat_ID == $cat->cat_ID) {
$posts_output .= '- ' . get_the_title() . '
';
}
}
$posts_output .= '
';
}
$posts_output .= '
';
} elseif ('page' === $post_type) {
$posts_output .= '
' . $pt->labels->name . '
' . $this->get_wp_list_pages() . '
';
} elseif ('attachment' === $post_type) {
continue;
} else {
/**
* Get all custopm post type
*/
$posts_output .= '
' . $pt->labels->name . '
';
query_posts('post_type=' . $post_type . '&posts_per_page=-1');
while (have_posts()) {
the_post();
$posts_output .= '- ' . get_the_title() . '
';
}
$posts_output .= '
';
}
}
$posts_output .= '
';
return apply_filters('italystrap_html_sitemaps', $posts_output);
}
}