Support

Account

Home Forums General Issues archive page

Solved

archive page

  • Hello this is my first time with ACF and archives. I try to create a portfolio. First I create a custom post type in “functions.php” (this works). Then I create an archive page “archive-portfolio.php” but i don’t know how check if this works. I try to acces to direction.com/portfolio.php but a 404 error apears.

    This is my custom type in functions.php

    
    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 );
    
    }
    
    /* Hook into the 'init' action so that the function
    * Containing our post type registration is not 
    * unnecessarily executed. 
    */
    
    add_action( 'init', 'custom_post_type', 0 );
    

    —————————————————————————-
    This is my archive-portfolio.php

    
    /**
     *
     * @author  Ivan Ortiz & Xavier Calduch
     */
    
    //* Template Name: Portfolio
    //* The template for displaying the portfolio of our website.
    
    get_header(); ?>
    
    <div id="primary" class="content-area">
    	<main>
    		
    		<?php
    
    		while (have_posts() : the_posts()): 
    
    			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();
    		?>
    			
    			<div class="portfolio-item">
    				<div class="portfolio-image">
    					<?php the_post_thumbnail();>
    
    				</div>
    
    				<h2>
    					<a href ="<?php echo( get_post_meta ( get_the_ID(), 'live_url', true))?>" ><?php the_title(); ?></a>
    				</h2>
    				<h3>Date: <?php the_field('date'); ?> || Published At: <?php the_field('publication'); ?> </h3>
    
    			</div> 
    
    		<?php endwhile; ?>
    		<?else: ?> <?endif; ?>
    
    	</main>
    </div>
    
    <?php get_footer(); ?>

    —————————————————————————-

  • The URL for the archive page should be direction.com/Portfolio/ it may be with a lower case p, but you used an upper case letter as the post type so I’m not sure it that matters.

  • Thanks for your help John.

    I put the post type with the p in lowercase. Then I write the url “direction.com/portfolio/” and the 404 error is there again.

  • Does an admin menu appear for your post type?

    Visit the page Settings => Permalinks, this will reset the rewrite rules on the site and may fix the problem.

  • Thanks John!! Thank solves the problem.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘archive page’ is closed to new replies.