Skip to content
Permalink
Browse files

версия 1.1

  • Loading branch information...
avovkdesign committed Jan 25, 2016
0 parents commit d4e81208627aa5737980cf383bce4989c092230e
Showing with 239 additions and 0 deletions.
  1. +148 −0 hierarchical-sitemap.php
  2. +91 −0 readme.txt
@@ -0,0 +1,148 @@
<?php
/* ====================================================================================================
* Plugin Name: Hierarchical HTML Sitemap
* Description: This plugin is generate Hierarchical HTML Sitemap for your WordPress blog. It displays posts in categories which sorted hierarchically. Easy and fast. By using a shortcode <code>[htmlmap]</code> you can display sitemap on page or anywhere. Only PHP code, without additional CSS or JS files.
* Plugin URI: http://avovkdesign.com/plugin-hierarchical-html-sitemap.html
* Donate link: http://avovkdesign.com/bymecoffee
* Author: Alexandra Vovk
* Version: 1.1
* Author URI: http://avovkdesign.com/
* ==================================================================================================== */
// HIERARHICAL BLOG MAP shortcode
function hierarchicalsitemap_shortcode_htmlmap( $atts , $content = null ) {
$hidecloud = ( ''!=$atts && in_array('hidecloud', $atts) ) ? 1 : 0 ;
$showpages = ( ''!=$atts && in_array('showpages', $atts) ) ? 1 : 0 ;
/* new params - showdescription, hidedate
* @since v.1.1
*/
$showdescription = ( ''!=$atts && in_array('showdescription', $atts) ) ? 1 : 0 ;
$hidedate = ( ''!=$atts && in_array('hidedate', $atts) ) ? 1 : 0 ;
extract( shortcode_atts( array( 'exclude' => '', 'exclude_cat' => '' ), $atts ) );
$exclude = ($exclude) ? '&exclude='.$exclude : '';
$exclude_cat = ($exclude_cat) ? '&exclude='.$exclude_cat : '';
//$html = hierarchicalsitemap_hierarchical_category_tree( 0, $exclude, $exclude_cat, $hidecloud );
$html = hierarchicalsitemap_hierarchical_category_tree(
0,
$exclude,
$exclude_cat,
array(
'hidecloud' => $hidecloud,
'showdescription' => $showdescription,
'hidedate' => $hidedate,
)
);
$out = ( $hidecloud ) ? "" : "<p id=\"htmlmap_cats\">". substr($html['cloud'], 2 ) ."</p>";
$out .= "<div id=\"htmlmap_posts\">". $html['posts'] ."</div>";
$out .= ( $showpages ) ? hierarchicalsitemap_get_pages_list( $exclude ) : "";
return $out;
}
add_shortcode( 'htmlmap', 'hierarchicalsitemap_shortcode_htmlmap' );
/* RECURSIVE get html blog map
*
* @param (string) $cid category ID
* @param (string) $ex list posts IDs to exclude from HTML Map
* @param (string) $ex_cat list categories IDs to exclude from HTML Map
* @param (array) $arg array with display options:
* hidecloud=1 - hide categories cloud
* showdescription=0 - show category description
* hidedate=0 - hide post date
*
* @return (string) HTML code with sitemap
*/
//function hierarchicalsitemap_hierarchical_category_tree( $cid, $ex, $ex_cat, $hidecloud, $out = array( 'cloud' => '', 'posts' => '' ) ) {
function hierarchicalsitemap_hierarchical_category_tree(
$cid,
$ex,
$ex_cat,
$arg = array(
'hidecloud' => 1,
'showdescription' => 0,
'hidedate' => 0,
),
$out = array( 'cloud' => '', 'posts' => '' )
) {
$categories = get_categories('hide_empty=false&orderby=name&order=ASC&parent=' . $cid . $ex_cat );
if( $categories ) :
foreach( $categories as $cat ) :
$out['cloud'] .= ", <span class=\"cat\"><a href=\"#cat_$cat->term_id\">$cat->name</a> <small>[$cat->count]</small></span>";
$tocloudlink = ( $arg['hidecloud'] ) ? "" : " <a href='#htmlmap_cats'>&uarr;</a>";
$tag = ( 0 == $cid ) ? "h2" : "h3";
$out['posts'] .= "\n<$tag id='cat_$cat->term_id'>". $cat->name ." <small>[". $cat->count ."]</small>". $tocloudlink ."</$tag>\n";
$out['posts'] .= ( "" != $cat->category_description && $arg['showdescription'] ) ? "<p><i>". $cat->category_description ."</i></p>\n" : '';
$out['posts'] .= "<ul>\n";
$posts = get_posts('posts_per_page=-1&orderby=post_date&order=DESC&category__in='.$cat->term_id . $ex );
if ( count( $posts ) > 0 ) {
$cnt = 0;
foreach ( $posts as $post ) {
$cnt++;
$date = explode(" ", $post->post_date );
$out['posts'] .= ( $arg['hidedate'] ) ? "<li>" : "<li><small>$date[0]</small>&nbsp;";
$out['posts'] .= "<a href=\"".get_permalink( $post->ID )."\">$post->post_title</a>";
if ( $cnt == count( $posts ) ) {
$out = hierarchicalsitemap_hierarchical_category_tree(
$cat->term_id,
$ex,
$ex_cat,
$arg,
$out
);
}
$out['posts'] .= "</li>\n";
}
}
// check empty category for all childrens and show it
else if ( 0 == count( $posts ) ) {
$out['posts'] .= '<li class="null" style="list-style:none">';
$out = hierarchicalsitemap_hierarchical_category_tree(
$cat->term_id,
$ex,
$ex_cat,
$arg,
$out
);
$out['posts'] .= "</li>";
}
$out['posts'] .= "</ul>\n";
endforeach;
endif;
$out['posts'] .= "\n";
return $out;
}
// get html pages list
function hierarchicalsitemap_get_pages_list( $exclude ) {
$html = "<ul id=\"htmlmap_pages\">";
$pages = get_pages( $exclude );
foreach ( $pages as $page ){
$id = $page->ID;
$title = $page->post_title;
$link = apply_filters('the_permalink', get_permalink($id));
$html .= "<li><a href=\"$link\" title=\"$title\">$title</a></li>";
}
$html .= "</ul>";
return "<h2>". __("All Pages") ."</h2>" . $html;
}
?>
@@ -0,0 +1,91 @@
=== Hierarchical HTML Sitemap ===
Contributors: egolacrima
Tags: html sitemap, seo, sitemap, hierarchical, posts, posts list, pages, pages list, shortcode

Requires at least: 3.0
Tested up to: 4.3
Stable tag: 1.1
License: GPLv2 or later

A lightweight and simple HTML sitemap for your WordPress blog.

== Description ==

Hierarchical HTML Sitemap offers visitors an easy and intuitive navigation across your blog.

This plugin generates HTML Sitemap of your WordPress blog. It displays a list of posts, grouped by hierarchically sorted categories. By using a shortcode you can easily and quickly display sitemap on a page, or anywhere where shortcodes work, e.g. in a widget.

The output does not include any CSS or JavaScript files - it is pure HTML, ready for you to style as you want it.

*Полное руководство по установке и использованию плагина на **русском языке** доступны на [блоге автора](http://avovkdesign.com/plugin-hierarchical-html-sitemap.html "Руководство по установке и настройке плагина Hierarchical HTML Sitemap").*


= Features: =

* Short and easy shortcode: `[htmlmap]`
* Categories sorted hierarchically.
* Displays posts and/or pages.
* Can exclude specified posts/pages or categories.
* Displays categories cloud above posts list, for better navigation.
* Displays post’s published date.
* Clean HTML without inline styles or scripts.
* Does not enqueue any unnecessary .js or .css files.
* No ads nor author links.


= Options: =

The plugin’s shortcode `[htmlmap]` accepts several optional parameters:

* `exclude` : specify posts’ or pages’ IDs you don't want displayed (example: `[htmlmap exclude=445,446]`).
* `exclude_cat` : specify categories’ IDs you don't want displayed (example: `[htmlmap exclude_cat=1,34]`).
* `showpages` : enables displaying list of pages (example: `[htmlmap showpages]`).
* `hidecloud` : disable categories’ cloud (example: `[htmlmap hidecloud]`).
* `showdescription` : enables displaying categories’ descriptions (they are not shown by default; example: `[htmlmap showdescription]`).
* `hidedate` : disable displaying posts’ published dates (example: `[htmlmap hidedate]`).

Several parameters could be used in the same shortcode. For example:

`[htmlmap exclude="3546,7398" exclude_cat="1,34" showpages hidecloud]`


== Installation ==

= Automatic installation: =

1. Log-in to your WordPress admin interface.
1. Hover over "Plugins" and click on "Add New".
1. Under Search enter Hierarchical HTML Sitemap and click the "Search Plugins" button.
1. In results page click the "Install Now" link for "Hierarchical HTML Sitemap".
1. Click "Activate Plugin" to finish installation. You're done!

= Manual installation: =

1. Download [Hierarchical HTML Sitemap](http://avovkdesign.com/plugin-hierarchical-html-sitemap.html "Hierarchical HTML Sitemap") and unzip the plugin folder.
1. Upload `hierarchical-sitemap` folder into to the `/wp-content/plugins/` directory.
1. Go to WordPress dashboard and navigate to "Plugins" -> "Installed Plugins".
1. Activate "Hierarchical HTML Sitemap".

= Usage: =

1. Make sure the plugin is installed and activated.
1. Hover over "Pages" and click on "Add New" in WordPress dashboard.
1. Give your page a title "Sitemap" and put `[htmlmap]` into the content box.
1. Save the page and click "View page" link to see your sitemap.



== Screenshots ==

1. Example of a sitemap.

== Changelog ==

= 1.1 =
* Fix: displaying empty categories (those without children posts but having non-empty sub-categories)
* New Feature: show categories’ descriptions (use option `showdescription`)
* New Feature: hide post’s published date (use option `hidedate`)


= 1.0 =
* Initial release.

0 comments on commit d4e8120

Please sign in to comment.
You can’t perform that action at this time.