Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/10/2010, 08:03
makiaji
 
Fecha de Ingreso: julio-2009
Ubicación: 127.0.0.1
Mensajes: 54
Antigüedad: 14 años, 9 meses
Puntos: 0
Máximo de items en una columna

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":

Código:
// 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 href="<?php echo get_category_link($cat->term_id); ?>"><?php echo $cat->name; ?></a> (<?php echo $cat->category_count; ?>)</li>
	
			<?php
			// now get all the sub cats based off the parent cat id
			$subcats = wp_list_categories('orderby=name&order=asc&hierarchical=0&show_count=1&use_desc_for_title=0&hide_empty=0&depth=1&number='.get_option('cp_dir_sub_num').'&title_li=&echo=0&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í:

Código:
		$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í:

Código:
		$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