[Support request] custom post template editing

Home Forums Support [Support request] custom post template editing

Home Forums Support custom post template editing

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #523091
    Cristina

    Hi,

    I´m having trouble with the configuration od a custom post type for projects.

    My workflow so far:

    I’ve CPT UI and got the custom post type for projects . So a new category.
    I’ve a child theme for GP where in functions i’ve added all the code CPT UI tells us to add.
    I have made the following ”.php”s :
    1. archive-project.php
    2. content-project.php
    3. single-project.php

    all those above have been copied from main theme.
    I can see it is working: because there’s an archive for PROJECTS that shows all the projects page i’ve made.

    My question is why the single-project.php does not behave like single post?

    example post
    example project

    There’s no navigation or category in project as there is in post.
    The idea was to have the same layout as normal post, without the time and author, but still with the navigation bellow and the custom fields for the project.

    I’m still learning .php, so i’m not sure where to edit things now.
    If by any chance having the files named above could help tell me so i can upload them somewhere.

    This is still a test web-site, but i’d like to control this things before starting the real one!
    Ty

    GeneratePress 2.0.2
    #523161
    Cristina

    Anyone? …

    #523368
    Tom
    Lead Developer
    Lead Developer

    Hi Cristina,

    It can take up to 12 hours to get a response on most days, especially Sunday.

    By default that post meta will only display on regular posts.

    We can set it to display on your custom post types with a function:

    add_action( 'generate_after_entry_content', 'tu_custom_post_type_footer_meta' );
    function tu_custom_post_type_footer_meta() {
    	if ( 'projects' == get_post_type() ) : ?>
    		<footer class="entry-meta">
    			<?php 
    			generate_entry_meta();
    
    			if ( is_single() ) {
    				generate_content_nav( 'nav-below' );
    			}
    			?>
    		</footer><!-- .entry-meta -->
    	<?php endif;
    }

    Let me know if you need more info 🙂

    #523609
    Cristina

    Sorry about this, but i don’t really know where to put that bit of php.

    In functions nothing happens. I’ve tried in content-project.php and single-project.php, but the page goes all white. :/

    <?php
    /**
     * The Template for displaying all single posts.
     *
     * @package GeneratePress
     */
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.
    }
    get_header(); ?>
    	<div id="primary" <?php generate_content_class();?>>
    		<main id="main" <?php generate_main_class(); ?>>
    			<?php
    			/**
    			 * generate_before_main_content hook.
    			 *
    			 * @since 0.1
    			 */
    			do_action( 'generate_before_main_content' );
    
    			while ( have_posts() ) : the_post();
    
    				get_template_part( 'content', 'project' ); ?>
    				
    				<div class="field">
    				<hr/>
    				<h3>Client: 	<?php the_field('client'); ?></h3>
    				<hr/>
    				<h3>Author: 	<?php the_field('author'); ?></h3>
    				<hr/>
    				<h3>Year:   	<?php the_field('year'); ?></h3>
    				<hr/>
    				<h3>Location:	<?php the_field('location'); ?></h3>
    				</br> </br>
    				</div>
    				
    <?php
    				// If comments are open or we have at least one comment, load up the comment template.
    				if ( comments_open() || '0' != get_comments_number() ) : ?>
    
    					<div class="comments-area">
    						<?php comments_template(); ?>
    					</div>
    
    				<?php endif;
    
    			endwhile;
    
    			/**
    			 * generate_after_main_content hook.
    			 *
    			 * @since 0.1
    			 */
    			do_action( 'generate_after_main_content' );
    			?>
    		</main><!-- #main -->
    	</div><!-- #primary -->
    
    	<?php
    	/**
    	 * generate_after_primary_content_area hook.
    	 *
    	 * @since 2.0
    	 */
    	 do_action( 'generate_after_primary_content_area' );
    
    	 generate_construct_sidebars();
    	 
    get_footer();
    
    

    This is what i have in single-project. (By the way, any other way to pass code easier? )
    Please advice…i’m not sure where to put that part you gave me.
    Thank you

    #524206
    Tom
    Lead Developer
    Lead Developer

    One of these methods is preferred: https://docs.generatepress.com/article/adding-php/

    Let me know if it doesn’t work when you use one of those 🙂

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.