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; }
/** * Get the data and generate output content for the book grid * * * * @since 1.0 * * @return content to be displayed * * @access public */ function mbdb_bookgrid_content() { global $post; $content = ''; $mbdb_book_grid_meta_data = get_post_meta($post->ID); // VALIDATE THE INPUTS // loop through the group by levels // set up the group arrays // stop at the first one that is none // if there is a series, add none after that and stop $groups = array(); $current_group = array(); $group_by_levels = mbdb_book_grid_group_by_options(); for ($x = 1; $x < count($group_by_levels); $x++) { if (!array_key_exists('_mbdb_book_grid_group_by_level_' . $x, $mbdb_book_grid_meta_data)) { $groups[$x] = 'none'; $current_group['none'] = 0; break; } $group_by_dropdown = $mbdb_book_grid_meta_data['_mbdb_book_grid_group_by_level_' . $x][0]; $groups[$x] = $group_by_dropdown; $current_group[$group_by_dropdown] = 0; if ($group_by_dropdown == 'none') { break; } if ($group_by_dropdown == 'series') { $groups[$x + 1] = 'none'; $current_group['none'] = 0; break; } } // set the sort if (array_key_exists('_mbdb_book_grid_order', $mbdb_book_grid_meta_data)) { $sort = mbdb_set_sort($groups, $mbdb_book_grid_meta_data['_mbdb_book_grid_order'][0]); } else { $sort = mbdb_set_sort($groups, 'titleA'); } // if selection isn't set, default to "all" if (array_key_exists('_mbdb_book_grid_books', $mbdb_book_grid_meta_data)) { $selection = $mbdb_book_grid_meta_data['_mbdb_book_grid_books'][0]; } else { $selection = 'all'; } // turn selected_ids into an array // or null if there aren't any if (array_key_exists('_mbdb_book_grid_' . $selection, $mbdb_book_grid_meta_data)) { $selected_ids = unserialize($mbdb_book_grid_meta_data['_mbdb_book_grid_' . $selection][0]); } else { $selected_ids = null; } // start off the recursion by getting the first group $level = 1; $books = mbdb_get_group($level, $groups, $current_group, $selection, $selected_ids, $sort, null); // $books now contains the complete array of books to display in the grid // get the display output content $content = mbdb_display_grid($books, 0); // find all the book grid's postmeta so we can display it in comments for debugging purposes $grid_values = array(); foreach ($mbdb_book_grid_meta_data as $key => $data) { if (substr($key, 0, 5) == '_mbdb') { $grid_values[$key] = $data[0]; } } $content = '<!-- Grid Parameters: ' . print_r($grid_values, true) . ' -->' . $content; // add on bottom text if (array_key_exists('_mbdb_book_grid_description_bottom', $mbdb_book_grid_meta_data)) { $book_grid_description_bottom = $mbdb_book_grid_meta_data['_mbdb_book_grid_description_bottom'][0]; } else { $book_grid_description_bottom = ''; } return $content . $book_grid_description_bottom; }