Category specific column settings in Wordpress and Yootheme

Category specific column settings in Wordpress and Yootheme

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 the functions.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.

You may be interested in...



Had enough browsing?

Get in touch

Get in touch

We wont charge you for the inital project meeting. So really you have nothing to lose.

Fill out the form below with as much information as you can provide and we will be in touch with you asap to discuss.

Name(*)
Please type your full name. Also only allowing alpha numeric characters here. Why do you have all this fancy stuff in your name anyway?

Email(*)
Invalid email address.

Phone
Please enter a valid phone number.

Enquiry Type(*)
Invalid Input

Message(*)
Please only use alphanumeric characters in your message

Invalid Input