Themes y Diseño

Foro WordPress » WordPress » Themes y Diseño

Máximo de items en una columna (1 mensaje)

Acerca de este hilo

Tags

Etiquetas:

No hay tags todavía.

  1. makiaji

    3.0
    Antiguedad: Ago 2009
    Mensajes: 18

    offline

    Publicado hace 1 año
    #

    Hola,

    Tengo el siguiente código de mi theme en Wordpress en el cual quiero marcarle que pueda tener como máximo 24 "entradas o categorías":

    // directory home page category display
    if (!function_exists('cp_directory_cat_columns')) {
        function cp_directory_cat_columns($cols) {

            // get all cats except for the blog
            $cats = get_categories('hide_empty=0&hierarchical=0&pad_counts=1&show_count=1&orderby=name&order=ASC&exclude='.CP_BLOG_CAT_ID);

            // remove all sub cats from the array
            foreach ($cats as $key = > $value){
                if ($value- >category_parent != 0)
                    unset($cats[$key]);
            }

            $i = 0;
            $cat_cols = $cols; // change this to add/remove columns
            $total_main_cats = count($cats); // total number of parent cats
            $cats_per_col = round($total_main_cats / $cat_cols); // items per column

            // loop through all the sub
            foreach($cats as $cat) {

                if (($i == 0) || ($i == $cats_per_col) || ($i == ($cats_per_col * 2))) {
                ? >

                    < div class="catcol" >

                < ?php
                }
                ? >
    <ul>
                    < li class="maincat" ><a>term_id); ? >" >< ?php echo $cat- >name; ? ></a> (< ?php echo $cat- >category_count; ? >)

                < ?php
                // now get all the sub cats based off the parent cat id
                $subcats = wp_list_categories('orderby=name&amp;order=asc&amp;hierarchical=0&amp;show_count=1&amp;use_desc_for_title=0&amp;hide_empty=0&amp;depth=1&amp;number='.get_option('cp_dir_sub_num').'&amp;title_li=&amp;echo=0&amp;child_of='.$cat- >cat_ID);

                // strip out the default wp title tag since the use_desc_for_title param doesn't seem to work in WP 2.9.2
                $subcats = preg_replace('/title=\"(.*?)\"/','',$subcats);

                // if you want to strip out the no categories text, just uncomment the line below
                // $subcats = str_replace('
    <li>No categories</li>
    ', '', $subcats);

                // print out all the subcats for the current parent cat
                echo $subcats;
                ? >
    </ul>

                < ?php

                if (($i == ($cats_per_col - 1)) || ($i == (($cats_per_col * 2) - 1)) || ($i == ($total_main_cats - 1))) {
                ? >
                    < /div >< !-- /catcol -- >

                < ?php
                }

                $i++;
            }

        }
    }

    Según leo en los comentarios del código debería modificarlo aquí:

    $i = 0;
            $cat_cols = $cols; // change this to add/remove columns
            $total_main_cats = count($cats); // total number of parent cats
            $cats_per_col = round($total_main_cats / $cat_cols); // items per column

    Modificar las 3 líneas y dejarlas así:

    $i = 0;
            $cat_cols = 3; // change this to add/remove columns
            $total_main_cats = 72; // total number of parent cats
            $cats_per_col = round($total_main_cats / $cat_cols); // items per column

    Pero haciendo esto se queda exactamente como está, en una única columna con las 72 categorías en ella con lo que aparece una columna extremadamente larga.

    ¿Qué debería modificar para poder hacer que esos 72 items se repartan en 3 columnas?

    Saludos

Responder

Debes Identificarte para publicar.

Foro WordPress » WordPress » Themes y Diseño