Lego2012
12/13/2016 - 2:47 PM

Sample PHP code to split tags in columns

Sample PHP code to split tags in columns

<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.

/**
* Template Name: Blog index template
* Description: Used as a page template to show tags as an index followed by a loop
*/
// Add our custom loop
add_action( 'genesis_loop', 'custom_blogloop_new' );

function custom_blogloop_new() {

    $tags = get_tags(array('orderby' => 'name', 'order' => 'ASC'));

    $html = '<div class="page entry"><div class="entry-content">

<h2>Onderwerpen index</h2><div id="taglist">';

    $numberpercolumn = ceil(count($tags)/3);

    $colnum = 3;

    $itemnum = 0;

    $html .= '<div class="column-'.$colnum.'">';


        foreach ( $tags as $tag ) {

            $tag_link = get_tag_link( $tag->term_id );

            $html .= "<li><a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";

            $html .= "{$tag->name}</a></li>";

            $itemnum++;
            if ($itemnum==$numberpercolumn) {

            $colnum++;
            $html .= '</div>

<div class="column-'.$colnum.'">';

    $itemnum=0;

        }
    }

    $html .= '</div></div><div style="height:60px;clear:both;"></div>';

    echo $html;

}

genesis();