WordPress.org

Ready to get started?Download WordPress

Forums

Custom design for register_post_type and theyr (2 posts)

  1. JaJco
    Member
    Posted 1 year ago #

    Good day,

    I have registered custom post type ("register_post_type") and in it i have "register_taxonomy" like category.

    When user click in the menu on ("register_taxonomy") category, he view only main loop, how can I make loop for this category?

    My code:

    <?php
    add_action('init', 'custom_post_type_onody');
    
    function custom_post_type_onody() {
    	$custom_slug = get_option('slug') != '' ? get_option('slug') : 'work';
    
    	$args = array(
    		'labels'			=> array(
    			'name'					=> __('Práca', 'simple-onody'),
    			'singular_name' 		=> __('Pracovné ponuky', 'simple-onody'),
    			'add_new'				=> __('Pridať ponuku', 'simple-onody'),
    			'add_new_item'			=> __('Pridať ponuku', 'simple-onody'),
    			'new_item'				=> __('Pridať ponuku', 'simple-onody'),
    			'view_item'				=> __('Zobraziť ponuku', 'simple-onody'),
    			'search_items' 			=> __('Vyhladať ponuku', 'simple-onody'),
    			'edit_item' 			=> __('Upraviť ponuku', 'simple-onody'),
    			'all_items'				=> __('Všetky ponuky', 'simple-onody'),
    			'not_found'				=> __('Žiadne ponuky sa nenašli', 'simple-onody'),
    			'not_found_in_trash'	=> __('Žiadne ponuky sa nenašli v koši', 'simple-onody')
    		),
    		'taxonomies'		=> array('custom-categories'),
    		'public'			=> true,
    		'show_ui'			=> true,
    		'_builtin'			=> false,
    		'_edit_link'		=> 'post.php?post=%d',
    		'capability_type'	=> 'post',
    		'rewrite'			=> array('slug' => __($custom_slug)),
    		'hierarchical'		=> false,
    		'menu_position'		=> 20,
    		'supports'			=> array('title', 'editor', 'comments', 'thumbnail')
    	);
    
    	/** create categories (taxonomy) */
    	register_taxonomy('custom-categories', 'project', array(
    			'hierarchical'		=> true,
    			'show_ui'			=> true,
    			'rewrite'			=> array('slug' => __($custom_slug . '/stat')),
    			'labels'			=> array(
    					'name' 							=> __('Štáty', 'simple-onody'),
    					'singular_name'					=> __('Ponky v štátoch', 'simple-onody'),
    					'search_items' 					=> __('Hľadať ponuku v štátoch', 'simple-onody'),
    					'popular_items'					=> __('Obľúbené štáty', 'simple-onody'),
    					'all_items'						=> __('Všetky štáty', 'simple-onody'),
    					'parent_item'					=> __('Nadradený štát (nepovinné!)', 'simple-onody'),
    					'parent_item_colon'				=> __('Nadradený štát (nepovinné!)', 'simple-onody'),
    					'edit_item'						=> __('Upraviť štáty', 'simple-onody'),
    					'update_item'					=> __('Pridať štát', 'simple-onody'),
    					'add_new_item'					=> __('Pridať nový štát', 'simple-onody'),
    					'new_item_name'					=> __('Nový štát', 'simple-onody'),
    					'separate_items_with_commas'	=> __('Separate Categories with commas', 'simple-onody'),
    					'add_or_remove_items' 			=> __('Pridať alebo Odstrániť štát', 'simple-onody'),
    					'choose_from_most_used' 		=> __('Vyberte z najpožívanejších štátov', 'simple-onody')
    		)
    	));
    
    	/** create new custom post type */
    	register_post_type('work', $args);
    }

    I am sorry but my English is poor.

  2. adamweclick
    Member
    Posted 1 year ago #

    before main loop on custom template:

    <?php if ( get_query_var('paged') ) {
    
    				    $paged = get_query_var('paged');
    
    				} elseif ( get_query_var('page') ) {
    
    				    $paged = get_query_var('page');
    
    				} else {
    
    				    $paged = 1;
    
    				}
    
    				$cats = array(
    					intval(get_cat_ID( $cat_name='categoryname' )),
    					intval(get_cat_ID( $cat_name='category2' )),
    					intval(get_cat_ID( $cat_name='category3' )),
    					intval(get_cat_ID( $cat_name='category4' )),
    					intval(get_cat_ID( $cat_name='category5' ))
    				);
    
    				query_posts( array( 'post_type' => 'post', 'paged' => $paged, 'posts_per_page' => 5, 'category__in' => $cats ) );

    Took me ages to figure this out myself, hope it helps myself

Topic Closed

This topic has been closed to new replies.

About this Topic