Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

mattregister on "Cutting a list of terms in half"

$
0
0

I have a custom taxonomy called "guest". This function outputs an unordered list of the guests linked to the taxonomy archive for the term.

function print_guests() {
$terms = get_terms( 'guest' );

echo '<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.
    echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>';
}

echo '</ul></div>';
}
add_shortcode('print-guests', 'print_guests');

What I am trying to do is split the list into two lists; one with the first half and the other with the second half so I can split the output into two columns on the page they are being displayed in.

Any thoughts as to how I can limit this list to the first half and then split the list into the second in another shortcode?


Viewing all articles
Browse latest Browse all 8245

Trending Articles