Site logo

[Resolved] Custom Post Type

Home Forums Support [Resolved] Custom Post Type

Home Forums Support Custom Post Type

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #991727
    Patrick

    Hehe yes thats my ticket, I’ve asked they this morning ๐Ÿ˜†

    I give them a try this evening ๐Ÿ‘

    #991826
    Patrick

    Hi Tom,

    we getting closer, but there is one problem with featured images and pagination. The last 3 adverts have featured images:

    If I use the following code as archive-adverts.php it looks good, the pagination works, but the featured Images are not shown.

    <?php
    /**
     * The template for displaying Archive pages.
     *
     * @package GeneratePress
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.
    }
    
    get_header(); ?>
    
    	<div id="primary" <?php generate_do_element_classes( 'content' ); ?>>
    		<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
    			<?php
    			/**
    			 * generate_before_main_content hook.
    			 *
    			 * @since 0.1
    			 */
    			do_action( 'generate_before_main_content' );
    
    			if ( have_posts() ) :
    
    				/**
    				 * generate_archive_title hook.
    				 *
    				 * @since 0.1
    				 *
    				 * @hooked generate_archive_title - 10
    				 */
    				do_action( 'generate_archive_title' );
    
    				while ( have_posts() ) : the_post();
    
    					/*
    					 * Include the Post-Format-specific template for the content.
    					 * If you want to override this in a child theme, then include a file
    					 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    					 */
    					get_template_part( 'content', get_post_format() );
    
    				endwhile;
    
    				/**
    				 * generate_after_loop hook.
    				 *
    				 * @since 2.3
    				 */
    				do_action( 'generate_after_loop' );
    
    				generate_content_nav( 'nav-below' );
    
    			else :
    
    				get_template_part( 'no-results', 'archive' );
    
    			endif;
    
    			/**
    			 * 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();
    

    If I use the following code for the archive-advert.php, the columns and masonry not working correct, but the featured images are shown.

    <?php
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.
    }
    
    get_header(); ?>
    
    	<div id="primary" <?php generate_do_element_classes( 'content' ); ?>>
    		<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
    			<?php
    			/**
    			 * generate_before_main_content hook.
    			 *
    			 * @since 0.1
    			 */
    			do_action( 'generate_before_main_content' );
    
    			$args = array('post_type' => 'advert');
    			$myQuery = new WP_Query($args);
    			
    			if ( $myQuery->have_posts() ) :
    
    				while ( $myQuery->have_posts() ) : $myQuery->the_post();
    
    					/* Include the Post-Format-specific template for the content.
    					 * If you want to override this in a child theme, then include a file
    					 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    					 */
    					get_template_part( 'content', 'advert' );
    
    				endwhile;
    
    				/**
    				 * generate_after_loop hook.
    				 *
    				 * @since 2.3
    				 */
    				do_action( 'generate_after_loop' );
    
    				generate_content_nav( 'nav-below' );
    
    			else :
    
    				get_template_part( 'no-results', 'index' );
    
    			endif;
    
    			/**
    			 * 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();

    => Like to have the first one WITH featured images, than I’m happy

    Admin credentials which i send you yesterday already working ๐Ÿ™‚

    #991972
    Tom
    Lead Developer
    Lead Developer

    Can we try replacing the get_template_part() again?:

    get_template_part( 'content', 'advert' );

    The necessary hooks to display the featured images should be in there.

    Let me know ๐Ÿ™‚

    #991978
    Patrick

    sure, i’ve changed it again, but there are also no featured images.
    They only visible if I use the custom loop. WPAdverts uses featured images something strange.

    you can everytime change what you want on the site i send you the credentials ๐Ÿ™‚

    #993052
    Tom
    Lead Developer
    Lead Developer

    Let’s try this:

    add_filter( 'generate_featured_image_output', function( $output ) {
        if ( is_post_type_archive( 'advert' ) && function_exists( 'adverts_get_main_image' ) ) {
            $output = sprintf( // WPCS: XSS ok.
                '<div class="post-image">
                    <a href="%1$s">
                        <img src="%2$s" alt="" />
                    </a>
                </div>',
                esc_url( get_permalink() ),
                adverts_get_main_image( get_the_ID() )
            );
        }
    
        return $output;
    } );

    Let me know ๐Ÿ™‚

    #993061
    Patrick

    Hey Tom,

    Thank you very much, this looks good.

    Best regards
    Patrick

    #993334
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

Viewing 7 posts - 16 through 22 (of 22 total)
  • You must be logged in to reply to this topic.