• Resolved gmsalomao2

    (@gmsalomao2)


    I’m trying to use the Grid template on category pages.
    I can use the template when creating new pages, but not when creating new categories.
    So I’ve installed the “Custom Category Template” plugin and now there’s an option to choose the Grid template when creating categories, but there’s no “Grid Settings” section, so the categories keep showing like they used to.
    I need help to write the settings, even if manually, to the category pages.

    Here I have a page with grid layout:
    https://krato.com.br/

    And here a category page I’m trying to enable the same grid layout:
    https://krato.com.br/category/forca/

    • This topic was modified 7 years, 8 months ago by gmsalomao2.
Viewing 2 replies - 16 through 17 (of 17 total)
  • Actually, I tested now and realized that though I can pick a category, that category is not being saved. I bet I did something pretty wrong, sorry to botter again. This is what I did:

    // Custom query for grid pages
    function bento_grid_query() {
    	$post_id = get_queried_object_id();
    	$bento_grid_query_args = array();
    	$post_types = get_post_meta( $post_id, 'bento_page_content_types', true );
    	$bento_grid_query_args['post_type'] = $post_types;
    	$bento_grid_query_args['post_tag'] = $post_tag;
    	$bento_grid_query_args['category'] = $category;
    	if ( is_front_page() ) {
    		$bento_paged = ( get_query_var('page') ) ? get_query_var('page') : 1;
    	} else {
    		$bento_paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    	}
    	$bento_grid_query_args['paged'] = $bento_paged;
    	$bento_grid_number_items = get_post_meta( $post_id, 'bento_page_number_items', true );
    	if ( ctype_digit($bento_grid_number_items) && ctype_digit($bento_grid_number_items) != 0 ) {
    		$bento_grid_query_args['posts_per_page'] = (int)$bento_grid_number_items;
    	} else {
    		$bento_grid_query_args['posts_per_page'] = get_option('posts_per_page');	
    	}
    	return $bento_grid_query_args;
    }
    
    // Page settings metaboxes
    function bento_metaboxes() {
    	
    	// Define strings
    	$bento_prefix = 'bento_';
    	$bento_ep_url = wp_kses( 
    		'<a href="https://satoristudio.net/bento-free-wordpress-theme/#expansion-pack/?utm_source=disabled&utm_medium=theme&utm_campaign=theme" target="_blank">Expansion Pack</a>', 
    		array(
    			'a' => array(
    				'href' => array(),
    				'target' => array(),
    			),
    		) 
    	);
    	
    	// Callback to display a field only on single post types
    	function bento_show_field_on_single() {
    		$current_screen = get_current_screen();
    		if ( $current_screen->id == 'page' ) {
    			return false;
    		} else {
    			return true;
    		}
    	}
    	
    	// Function to add a multicheck with post types
    	add_action( 'cmb2_render_multicheck_category', 'bento_render_multicheck_category', 10, 5 );
    	function bento_render_multicheck_category( $args = '', $post_category, $category ) {
    	    $defaults = array(
    	        'show_option_all'   => '',
    	        'show_option_none'  => '',
    	        'orderby'           => 'id',
    	        'order'             => 'ASC',
    	        'show_count'        => 0,
    	        'hide_empty'        => 1,
    	        'child_of'          => 0,
    	        'exclude'           => '',
    	        'echo'              => 1,
    	        'selected'          => 0,
    	        'hierarchical'      => 0,
    	        'name'              => 'cat',
    	        'id'                => '',
    	        'class'             => 'postform',
    	        'depth'             => 0,
    	        'tab_index'         => 0,
    	        'taxonomy'          => 'category',
    	        'hide_if_empty'     => false,
    	        'option_none_value' => -1,
    	        'value_field'       => 'term_id',
    	        'required'          => false,
    	    );
    	    wp_dropdown_categories( 'show_count=1&hierarchical=1' );
    	    /**
    	     * Filters the taxonomy drop-down output.
    	     *
    	     * @since 2.1.0
    	     *
    	     * @param string $output HTML output.
    	     * @param array  $r      Arguments used to build the drop-down.
    	     */
    	}
    Theme Author satoristudio

    (@satoristudio)

    The metabox field doesn’t save the category value because it’s not being handled correctly – please see CMB2 documentation for examples of taxonomy multicheck implementations.

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Use Grid layout on category pages’ is closed to new replies.