pag_page = isset( $_GET['ipage'] ) ? intval( $_GET['ipage'] ) : 1; $this->pag_num = isset( $_GET['num'] ) ? intval( $_GET['num'] ) : $per_page; $taxonomies = oci_get_query_var(OCI_TAXONOMY); $terms = oci_get_query_var(OCI_TERM); $this->taxonomies = $taxonomies; $this->terms = $terms; if ($terms && $taxonomies) $this->items = OCI_Item::get_items_in_terms($terms, $taxonomies, $this->pag_num, $this->pag_page); if ( !$max || $max >= (int)$this->items['total'] ) $this->total_item_count = (int)$this->items['total']; else $this->total_item_count = (int)$max; $this->items = $this->items['items']; if ( $max ) { if ( $max >= count($this->items) ) $this->item_count = count($this->items); else $this->item_count = (int)$max; } else { $this->item_count = count($this->items); } $this->pag_links = paginate_links( array( 'base' => add_query_arg( 'ipage', '%#%' ), 'format' => '', 'total' => ceil( (int) $this->total_item_count / (int) $this->pag_num ), // tot num pages possible 'current' => (int) $this->pag_page, 'prev_text' => '«', 'next_text' => '»', 'mid_size' => 1 )); } function has_items() { if ( $this->item_count ) return true; return false; } function next_item() { $this->current_item++; $this->item = $this->items[$this->current_item]; return $this->item; } function rewind_items() { $this->current_item = -1; if ( $this->item_count > 0 ) { $this->item = $this->items[0]; } } function items() { if ( $this->current_item + 1 < $this->item_count ) { return true; } elseif ( $this->current_item + 1 == $this->item_count ) { do_action('loop_end'); // Do some cleaning up after the loop $this->rewind_items(); } $this->in_the_loop = false; return false; } function the_item() { global $item, $bp; $this->in_the_loop = true; $this->item = $this->next_item(); $item_id = $this->item->item_id; $item_type = $this->item->item_type; $id = $this->item->id; if ( !$this->item = wp_cache_get( 'oci_item_' . $id, 'oci' ) ) { $this->item = OCI_Item::get_source_object($item_id, $item_type); wp_cache_set( 'oci_item_' . $id, $this->item, 'oci' ); } if ( 0 == $this->current_item ) // loop has just started do_action('loop_start'); } } function oci_rewind_items() { global $oci_items_template; return $oci_items_template->rewind_items(); } function oci_has_items( $args = '' ) { global $bp, $oci_items_template; $defaults = array( 'taxonomy' => OCI_DEFAULT_TAG_TAXONOMY, 'per_page' => 10, 'max' => false ); $r = wp_parse_args( $args, $defaults ); extract( $r, EXTR_SKIP ); if ( $max ) { if ( $per_page > $max ) $per_page = $max; } $oci_items_template = new OCI_Items_Template( $taxonomy, $per_page, $max ); return $oci_items_template->has_items(); } function oci_the_item() { global $oci_items_template; return $oci_items_template->the_item(); } function oci_the_items() { global $oci_items_template; return $oci_items_template->items(); } function oci_items_pagination() { echo oci_get_items_pagination(); } function oci_get_items_pagination() { global $oci_items_template; return apply_filters( 'oci_get_items_pagination', $oci_items_template->pag_links ); } function oci_the_items_pagination_count(){ echo oci_get_the_items_pagination_count(); } function oci_get_the_items_pagination_count() { global $bp, $oci_items_template; $from_num = intval( ( $oci_items_template->pag_page - 1 ) * $oci_items_template->pag_num ) + 1; $to_num = ( $from_num + ( $oci_items_template->pag_num - 1 ) > $oci_items_template->total_item_count ) ? $oci_items_template->total_item_count : $from_num + ( $oci_items_template->pag_num - 1) ; return sprintf( __( 'Viewing item %d to %d (of %d items)', 'bpcontents' ), $from_num, $to_num, $oci_items_template->total_item_count ); } function oci_the_items_term_and_taxonomy(){ echo oci_get_the_items_term_and_taxonomy(); } function oci_get_the_items_term_and_taxonomy() { global $bp, $oci_items_template; $pretty_tax = apply_filters('oci_get_the_items_term_and_taxonomy_taxonomy' , $bp->contents->taxonomy->{$oci_items_template->taxonomies}->label); $term = apply_filters('oci_get_the_items_term_and_taxonomy_taxonomy_term' , get_term_by('slug', $oci_items_template->terms, $oci_items_template->taxonomies)); return apply_filters('oci_get_the_items_term_and_taxonomy_taxonomy' , sprintf( __(' for %s in %s', 'bpcontents'), $term->name, $pretty_tax)); } function oci_bpc_nav_item(){ ?>