[Resolved] Image after the title in a cpt

Home Forums Support [Resolved] Image after the title in a cpt

Home Forums Support Image after the title in a cpt

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #801724
    Guillem

    I love generatepress Congratulations to all of the team. I am sorry for my English, I am Catalan and I do not speak English.

    I have created a CPT (professors) and I want to show the image after the title in the archive file. I have created archive-professors.php and content-professors-php. For the moment I have only changed to archive-professors:
    get_template_part (‘content-professors’, get_post_format ());

    The problem is that I do not understand much code and I do not find where I need to modify the order as and how the elements (image, title and excerp) are displayed.

    the link is as follows:

    I do not want to use the customize of generatepress, because I want it to be different from the entries.
    Can you help me? I know it must be a very simple thing but I do not find it.

    Thank you very much and forward !!

    #802227
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Are you wanting to move the featured image below the title, only in the archives of that custom post type?

    If so, you shouldn’t need custom template files. Try something like this:

    add_filter( 'option_generate_blog_settings', function( $options ) {
        if ( is_post_type_archive( 'professors' ) ) {
            $options['post_image_position'] = ''; // Empty is below title by default
        }
    
        return $options;
    } );

    Adding PHP: https://docs.generatepress.com/article/adding-php/

    #802771
    Guillem

    Thanks for the quick reply,

    Ok, I understand. But I wanted to put the image on top of the title. I did not express myself very well.

    What I did and what I did was write the code in file-professors.php. This makes it easier for me to personalize with specific css.

    The code is correct or I have done something wrong.

    <?php
    /**
     * The template for displaying professors Category pages.
     *
     * Learn more: http://codex.wordpress.org/Template_Hierarchy
     *
     * @package GeneratePress
     */
     
    // No direct access, please
    if ( ! defined( 'ABSPATH' ) ) exit;
    
    get_header(); ?>
    
        <section id="primary" <?php generate_content_class(); ?>>
            <main id="main" <?php generate_main_class(); ?>>
            <?php do_action('generate_before_main_content'); ?>
            <?php if ( have_posts() ) : ?>
                <?php do_action( 'generate_archive_title' ); ?>
                
                <div class="inside-article">
    
                <?php /* Start the Loop */ ?>
                <?php while ( have_posts() ) : the_post(); ?>
    
                    <div class="teachers-loop">
                        <div class="teachers-loop-img">
                            <?php the_post_thumbnail();?>
                        </div>
                        <div class="teachers-loop-text">
                            <h2><?php the_title(); ?></h2>
                            <h4><?php the_field('materies'); ?></h4>
                            <p><?php the_content(); ?></p>
                        </div> 
                    </div>
                
                <?php endwhile; ?>
                </div>
    
                <?php generate_content_nav( 'nav-below' ); ?>
    
            <?php else : ?>
    
                <?php get_template_part( 'no-results', 'archive' ); ?>
    
            <?php endif; ?>
            <?php do_action('generate_after_main_content'); ?>
            </main><!-- #main -->
        </section><!-- #primary -->
    
    <?php 
    do_action('generate_sidebars');
    get_footer();
    #803269
    Tom
    Lead Developer
    Lead Developer

    That will definitely work as well – especially if you want the custom classes etc.. 🙂

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