Ejemplo n.º 1
0
/**
 * Display the multidimensional array using a recursive function
 * 
 * @param array $nav
 * @param bool $useUL
 * @param bool $display_post_only_once
 * @return str $html
 */
function wsp_htmlFromMultiArray(array $nav = array(), $useUL = true, $display_post_only_once = true, $display_nofollow = false, $wsp_exclude_pages = array(), $sort = null, $sort_order = null)
{
    // check if not empty
    if (empty($nav)) {
        return '';
    }
    $html = '';
    if ($useUL === true) {
        $html .= '<ul class="wsp-posts-list">' . "\n";
    }
    // display a nofollow attribute ?
    $attr_nofollow = $display_nofollow == true ? ' rel="nofollow"' : '';
    // List all the categories
    foreach ($nav as $page) {
        $html .= "\t" . '<li><strong class="wsp-category-title">' . sprintf(__('Category: %1$s', 'wp_sitemap_page'), '<a href="' . get_category_link($page->cat_ID) . '"' . $attr_nofollow . '>' . $page->name . '</a>') . '</strong>' . "\n";
        $post_by_cat = wsp_displayPostByCat($page->cat_ID, $display_post_only_once, $display_nofollow, $wsp_exclude_pages, $sort, $sort_order);
        // List of posts for this category
        $category_recursive = '';
        if (!empty($page->sub)) {
            // Use recursive function to get the childs categories
            $category_recursive = wsp_htmlFromMultiArray($page->sub, false, $display_post_only_once, $display_nofollow, $wsp_exclude_pages, $sort, $sort_order);
        }
        // display if it exist
        if (!empty($post_by_cat) || !empty($category_recursive)) {
            $html .= '<ul class="wsp-posts-list">';
        }
        if (!empty($post_by_cat)) {
            $html .= $post_by_cat;
        }
        if (!empty($category_recursive)) {
            $html .= $category_recursive;
        }
        if (!empty($post_by_cat) || !empty($category_recursive)) {
            $html .= '</ul>';
        }
        $html .= '</li>' . "\n";
    }
    if ($useUL === true) {
        $html .= '</ul>' . "\n";
    }
    return $html;
}
Ejemplo n.º 2
0
/**
 * Display the multidimensional array using a recursive function
 * 
 * @param array $nav
 * @param bool $useUL
 */
function wsp_htmlFromMultiArray(array $nav = array(), $useUL = true)
{
    // check if not empty
    if (empty($nav)) {
        return '';
    }
    $html = '';
    if ($useUL === true) {
        $html .= '<ul class="wsp-posts-list">' . "\n";
    }
    // List all the categories
    foreach ($nav as $page) {
        $html .= "\t" . '<li><strong class="wsp-category-title">' . sprintf(__('Category: %1$s', 'wp_sitemap_page'), '<a href="' . get_category_link($page->cat_ID) . '">' . $page->name . '</a>') . '</strong>' . "\n";
        $post_by_cat = wsp_displayPostByCat($page->cat_ID);
        // List of posts for this category
        $category_recursive = '';
        if (!empty($page->sub)) {
            // Use recursive function to get the childs categories
            $category_recursive = wsp_htmlFromMultiArray($page->sub, false);
        }
        // display if it exist
        if (!empty($post_by_cat) || !empty($category_recursive)) {
            $html .= '<ul class="wsp-posts-list">';
        }
        if (!empty($post_by_cat)) {
            $html .= $post_by_cat;
        }
        if (!empty($category_recursive)) {
            $html .= $category_recursive;
        }
        if (!empty($post_by_cat) || !empty($category_recursive)) {
            $html .= '</ul>';
        }
        $html .= '</li>' . "\n";
    }
    if ($useUL === true) {
        $html .= '</ul>' . "\n";
    }
    return $html;
}