コード例 #1
0
function mbdb_tax_grid_content($attr, $content)
{
    $attr = shortcode_atts(array('taxonomy' => '', 'term' => ''), $attr);
    global $wp_query;
    if (isset($wp_query->query_vars['the-term'])) {
        $term = trim(urldecode($wp_query->query_vars['the-term']), '/');
    } else {
        $term = $attr['term'];
    }
    if (isset($wp_query->query_vars['the-taxonomy'])) {
        $taxonomy = trim(urldecode($wp_query->query_vars['the-taxonomy']), '/');
    } else {
        $taxonomy = $attr['taxonomy'];
    }
    if ($taxonomy == '' || $term == '') {
        return __('There was an error!', 'mooberry-book-manager');
    }
    $selection = str_replace('mbdb_', '', $taxonomy);
    //$groups[1] = $selection;
    $groups[1] = 'none';
    $groups[2] = 'none';
    //$current_group = array($selection => 0, 'none' => 0);
    $current_group = array('none' => 0);
    $sort = mbdb_set_sort($groups, 'titleA');
    // set sort varialbles
    //list( $orderby, $order ) = MBDB()->books->get_sort_fields( $sort );
    // get id
    $term_obj = get_term_by('slug', $term, $taxonomy);
    if ($term_obj != null) {
        $selected_ids = array((int) $term_obj->term_id);
    } else {
        $selected_ids = null;
    }
    $books = apply_filters('mbdb_tax_grid_get_group', mbdb_get_group(1, $groups, $current_group, $selection, $selected_ids, $sort, null), $groups, $current_group, $selection, $selected_ids, $sort, $term);
    //$orderby, $order, null);
    /********************* term meta ***************************************/
    if (function_exists('get_term_meta')) {
        $content = '<p>' . get_term_meta($selected_ids[0], $taxonomy . '_book_grid_description', true) . '</p>';
        $content2 = '<p>' . get_term_meta($selected_ids[0], $taxonomy . '_book_grid_description_bottom', true) . '</p>';
    } else {
        $content = '';
        $content2 = '';
    }
    return $content . mbdb_display_grid($books, 0) . $content2;
}
コード例 #2
0
/**
 *  Get books by taxonomy
 *  
 *  @since 
 *  @param [int] $level         the nested level of the grid we're currently one
 *  @param [array] $groups       the groups in grid
 *  @param [array] $current_group  the id of the current group. Could be id of a
 *  								 series, genre, publisher, illustrator, etc.
 *  @param [string] $selection     what selection of books for the grid ('all',
 *  								 'unpublished', 'series', etc.)
 *  @param [array] $selected_ids  ids of the selection
 *  @param [string] $sort          represents sort, ie 'titleA', 'titleD', 
 *  								'series, etc.
 *  @param [array] $book_ids      optional list of book_ids to filter by, useful
 *  								for add-on plugins to add on to grid (ie MA)
 *  
 *  @return array of books
 *  
 *  @access public
 */
function mbdb_get_books_by_taxonomy($level, $groups, $current_group, $selection, $selected_ids, $sort, $book_ids)
{
    $books = array();
    // Get ones not in the taxonomy first
    $current_group[$groups[$level]] = -1;
    // recursively get the next nested group of books
    $results = mbdb_get_group($level + 1, $groups, $current_group, $selection, $selected_ids, $sort, $book_ids);
    // only return results if are any so that headers of empty groups
    // aren't displayed
    if (count($results) > 0) {
        switch ($groups[$level]) {
            case 'genre':
                $empty = apply_filters('mbdb_book_grid_uncategorized_heading', __('Uncategorized', 'mooberry-book-manager'));
                break;
            case 'series':
                $empty = apply_filters('mbdb_book_grid_standalones_heading', __('Standalones', 'mooberry-book-manager'));
                break;
            case 'tag':
                $empty = apply_filters('mbdb_book_grid_untagged_heading', __('Untagged', 'mooberry-book-manager'));
                break;
            case 'editor':
                $empty = apply_filters('mbdb_book_grid_uncategorized_heading', __('No Editor Specified', 'mooberry-book-manager'));
                break;
            case 'illustrator':
                $empty = apply_filters('mbdb_book_grid_uncategorized_heading', __('No Illustrator Specified', 'mooberry-book-manager'));
                break;
            case 'cover_artist':
                $empty = apply_filters('mbdb_book_grid_uncategorized_heading', __('No Cover Artist Specified', 'mooberry-book-manager'));
                break;
        }
        $books[$empty] = $results;
    }
    // loop through each term
    // and recursively get the next nested group of books for that term
    $terms_query = array('orderby' => 'slug', 'hide_empty' => true);
    // if we're grouping by what we're filtering by, only get terms that we're filtering on
    if ($groups[$level] == $selection) {
        $terms_query['include'] = $selected_ids;
    }
    $all_terms = get_terms('mbdb_' . $groups[$level], $terms_query);
    $taxonomy = get_taxonomy('mbdb_' . $groups[$level]);
    // loop through all the terms
    foreach ($all_terms as $term) {
        $current_group[$groups[$level]] = $term->term_id;
        $results = mbdb_get_group($level + 1, $groups, $current_group, $selection, $selected_ids, $sort, $book_ids);
        // only return results if are any so that headers of empty groups
        // aren't displayed
        if (count($results) > 0) {
            if (in_array($groups[$level], array('genre', 'series', 'tag'))) {
                $heading = $term->name . ' ' . $taxonomy->labels->singular_name;
            } else {
                $heading = $taxonomy->labels->singular_name . ' ' . $term->name;
            }
            $books[apply_filters('mbdb_book_grid_heading', $heading)] = $results;
        }
    }
    return $books;
}