• Hello i made a portfolio archive and is working fine. Now i’m triying to made four diferent adaptations for four categories. This is my category-imatge-coorporativa.php

    <?php 
    
    /**
     *
     * @author  Ivan Ortiz & Xavier Guerrero Calduch
     */
    
    //* Template Name: Portfolio Imatge Coorporativa
    //* The template for displaying the portfolio of our website.
    
    get_header(); ?>
    
    <div id="primary" class="content-area">
    	<main>
    
    		<?php
    
    			get_template_part("template-parts/content","page");
    
    			$args = array( 'post_type' =>portfolio, );
    			$query = new WP_Query( $args ); 
    
    			if ( $query->have_posts()) : while ( $query->have_posts() ) : $query->the_post();
    
    				if(is_category("Imatge coorporativa")):
    
    				$image = get_field('imagen');
    
    					if( !empty($image) ): ?>
    						<article class="article-portfolio">
    							<a href="<?php the_permalink(); ?>">
    								<img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>" />
    							</a>
    						</article>
    				<?php endif;
    				endif;
    			 endwhile;
    			endif; ?>
    
    	</main>
    </div>
    
    <?php get_footer(); ?>

    When i refesh the permalinks and seacrh http://www.location.com/imatge-coorporativa, a 404 error is displayed.

Viewing 6 replies - 1 through 6 (of 6 total)
  • are you trying to code a custom page template for a static page? (as the Template Name line suggests)?

    or are you trying to code a custom category template (as the used template file name suggests)??

    what theme are you using?

    what is the code of /template-parts/content-page.php?

    have you tried to add the category parameter to the query?
    https://codex.ww.wp.xz.cn/Class_Reference/WP_Query#Category_Parameters

    Thread Starter ivan76

    (@ivan76)

    Hello Michael Thanks for your help.

    Actually im’m trying to made four differents archive-page thant’s my functions.php. I’m using Genesis framework with mobile_first child theme.

    function create_posttype() {
    
    	register_post_type( 'portfolio',
    	// CPT Options
    		array(
    			'labels' => array(
    				'name' => __( 'portfolio' ),
    				'singular_name' => __( 'portfolio' )
    			),
    			'public' => true,
    			'has_archive' => true,
    			'rewrite' => array('slug' => 'portfolio'),
    		)
    	);
    }
    
    add_action( 'init', 'create_posttype' );
    
    function custom_post_type() {
    
    // Set UI labels for Custom Post Type
    	$labels = array(
    		'name'                => _x( 'portfolio', 'Post Type General Name', 'calduchstudio' ),
    		'singular_name'       => _x( 'portfolio', 'Post Type Singular Name', 'calduchstudio' ),
    		'menu_name'           => __( 'portfolio', 'calduchstudio' ),
    		'parent_item_colon'   => __( 'Parent portfolio', 'calduchstudio' ),
    		'all_items'           => __( 'All portfolio', 'calduchstudio' ),
    		'view_item'           => __( 'View portfolio', 'calduchstudio' ),
    		'add_new_item'        => __( 'Add New portfolio', 'calduchstudio' ),
    		'add_new'             => __( 'Add New', 'calduchstudio' ),
    		'edit_item'           => __( 'Edit portfolio', 'calduchstudio' ),
    		'update_item'         => __( 'Update portfolio', 'calduchstudio' ),
    		'search_items'        => __( 'Search portfolio', 'calduchstudio' ),
    		'not_found'           => __( 'Not Found', 'calduchstudio' ),
    		'not_found_in_trash'  => __( 'Not found in Trash', 'calduchstudio' ),
    	);
    
    // Set other options for Custom Post Type
    
    	$args = array(
    		'label'               => __( 'portfolio', 'calduchstudio' ),
    		'description'         => __( 'portfolio news and reviews', 'calduchstudio' ),
    		'labels'              => $labels,
    		// Features this CPT supports in Post Editor
    		'supports'            => array( 'title', 'editor', 'author', 'thumbnail', 'revisions', ),
    		// You can associate this CPT with a taxonomy or custom taxonomy.
    		'taxonomies'          => array( 'genres' ),
    		/* A hierarchical CPT is like Pages and can have
    		* Parent and child items. A non-hierarchical CPT
    		* is like Posts.
    		*/
    		'hierarchical'        => false,
    		'public'              => true,
    		'show_ui'             => true,
    		'show_in_menu'        => true,
    		'show_in_nav_menus'   => true,
    		'show_in_admin_bar'   => true,
    		'menu_position'       => 5,
    		'can_export'          => true,
    		'has_archive'         => true,
    		'exclude_from_search' => false,
    		'publicly_queryable'  => true,
    		'capability_type'     => 'page',
    	);
    
    	// Registering your Custom Post Type
    	register_post_type( 'portfolio', $args );
    
    }
    Thread Starter ivan76

    (@ivan76)

    First i use the “Genesis Portfolio Pro” plugin. The problem is it crop de pictures and one my categories is “Posters”. I don’t want to crop them in the archive-page. So I try to made my own archive-pages. The general archive-page is working fine, the problem is with subcategories.

    Thread Starter ivan76

    (@ivan76)

    Well I think i find the problem the category not’s added when i choose it to the Portfolio.

    Thread Starter ivan76

    (@ivan76)

    Unfortunately

    'taxonomies' => array( 'category' ),

    don’t solve the problem

    Thread Starter ivan76

    (@ivan76)

    Ok I resolved the problem adding this lines in functions.php

    //* Link portfolio CPT to categories taxonomy
    add_action( 'init', 'sk_add_category_taxonomy_to_portfolio' );
    function sk_add_category_taxonomy_to_portfolio() {
    	register_taxonomy_for_object_type( 'category', 'portfolio' );
    }
Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘category-archives’ is closed to new replies.