https://www.23creative.com.au/latest-news/wordpress-development/item/category-specific-column-settings-in-wordpress-and-yootheme-2
Using a Yootheme template and need the ability to set a columns for individual categories in WordPress?
I did and this is how i went about it.
firstly in my template folder /wp-content/themes/[themeName] found and opened thefunctions.php file.
just under the code
// load config?? ? require_once(dirname(__FILE__).'/config.php'); $found = locate_template( 'ptp_functions/ptp_category_widget.php', TRUE, TRUE );
I insertered the following
<?php /** Add Custom Field To Category Form */ add_action( 'category_add_form_fields', 'category_form_custom_field_add', 10 ); add_action( 'category_edit_form_fields', 'category_form_custom_field_edit', 10, 2 ); function category_form_custom_field_add( $taxonomy ) { ?> <div class="form-field"> ? <label for="category_column_count">Column Count</label> ? <input name="category_column_count" id="category_column_count" type="text" value="" size="40" aria-required="true" /> ? <p class="description">Enter a Column Count value.</p> </div> <?php } function category_form_custom_field_edit( $tag, $taxonomy ) { ??? $option_name = 'category_column_count_' . $tag->term_id; ?? ?$category_column_count = get_option( $option_name ); ?> <tr class="form-field"> ? <th scope="row" valign="top"><label for="category_column_count">Column Count</label></th> ? <td> ??? <input type="text" name="category_column_count" id="category_column_count" value="<?php echo esc_attr( $category_column_count ) ? esc_attr( $category_column_count ) : ''; ?>" size="40" aria-required="true" /> ??? <p class="description">Enter a Column Count value.</p> ? </td> </tr> <?php } /** Save Custom Field Of Category Form */ add_action( 'created_category', 'category_form_custom_field_save', 10, 2 );?? ? add_action( 'edited_category', 'category_form_custom_field_save', 10, 2 ); function category_form_custom_field_save( $term_id, $tt_id ) { ??? if ( isset( $_POST['category_column_count'] ) ) {?? ??? ??? ? ?? ??? ?$option_name = 'category_column_count_' . $term_id; ?? ??? ?update_option( $option_name, $_POST['category_column_count'] ); ?? ?} }
This adds a new field Column Count to the category taxonomy, in my category I want it to be a 3 column layout, luckliy the yootheme template handles all this for me. All I have to do now is pass the new column count value to the _posts.php file. So go to wp-content/themes/[yourThemeName]/warp/systems/wordpress/layouts/_posts.php (i noticed the latest Warp framework handles overrides alot better so the process would be different) find
// init vars $colcount = is_front_page() ? $this['config']->get('multicolumns', 1) : 1; $count??? = $this['system']->getPostCount(); $rows???? = ceil($count / $colcount); $columns? = array(); $row????? = 0; $column?? = 0; $i??????? = 0;
and replace with
// init vars $colcount = is_front_page() ? $this['config']->get('multicolumns', 1) : 1; $count??? = $this['system']->getPostCount(); $rows???? = ceil($count / $colcount); $columns? = array(); $row????? = 0; $column?? = 0; $i??????? = 0; global $wp_query; $queried_object = $wp_query->get_queried_object(); //get the entered value from the category settings $option_name = 'category_column_count_' . $queried_object->term_id; $category_column_count = get_option( $option_name ); if($category_column_count){ ?? ?$colcount = $category_column_count; }
Now your edited category will now output posts in the desired column layout.