get_terms offset working?
-
I am trying to display a list of termsfrom my taxonomy “organization” in an unordered list but display them in two columns. This is what I have for my first column:
function print_organizations1() { $countterms = wp_count_terms( 'organization' ); if($countterms&1) { $firstcolumn = ( ( ( $countterms - 1) / 2 ) + 1); } else { $firstcolumn = ( $countterms / 2 ); } $secondcolumn = ( $countterms - $firstcolumn ); $terms = get_terms( 'organization', array('number' => $firstcolumn )); print '<div class="vcex-bullets vcex-bullets-gray"><ul>'; foreach ( $terms as $term ) { // The $term is an object, so we don't need to specify the $taxonomy. $term_link = get_term_link( $term ); // If there was an error, continue to the next term. if ( is_wp_error( $term_link ) ) { continue; } // We successfully got a link. Print it out. print '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>'; } print '</ul></div>'; } add_shortcode('print-organizations1', 'print_organizations1');That works perfectly. It figures out how many is in the first half of the list and uses that number of terms to display. When I try to make the second column is where I am getting lost. I try to offset the list by the number of terms in the first column.
function print_organizations2() { $countterms = wp_count_terms( 'organization' ); if($countterms&1) { $firstcolumn = ( ( ( $countterms - 1) / 2 ) + 1); } else { $firstcolumn = ( $countterms / 2 ); } $secondcolumn = ( $countterms - $firstcolumn ); $terms = get_terms( 'organization', array('offset' => $firstcolumn )); print '<div class="vcex-bullets vcex-bullets-gray"><ul>'; foreach ( $terms as $term ) { // The $term is an object, so we don't need to specify the $taxonomy. $term_link = get_term_link( $term ); // If there was an error, continue to the next term. if ( is_wp_error( $term_link ) ) { continue; } // We successfully got a link. Print it out. print '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>'; } print '</ul></div>'; } add_shortcode('print-organizations2', 'print_organizations2');This outputs the entire list. Even when I replace $firstcolumn with a hard number it still displays the whole list. What am I missing? any thoughts?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
The topic ‘get_terms offset working?’ is closed to new replies.