[Resolved] Custom Post Type

Home Forums Support Custom Post Type

Viewing 15 posts - 1 through 15 (of 22 total)
  • Author
    Posts
  • #988089
    Patrick

    Hi Tom,

    I’ve created a new custom page template, which should be usable like a blog page. For this I have build the page with the following code and named the page template page-advert.php

    <?php
    /* Template Name: Adverts-Listing-Page */
    
    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', 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', '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();

    Also I have created a page called contend-advert.php with the following code:

    <?php
    /**
     * The template for displaying posts within the loop.
     *
     * @package GeneratePress
     */
    
    if ( ! defined( 'ABSPATH' ) ) {
    	exit; // Exit if accessed directly.
    }
    ?>
    <article id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php generate_do_microdata( 'article' ); ?>>
    	<div class="inside-article">
    		<?php
    		/**
    		 * generate_before_content hook.
    		 *
    		 * @since 0.1
    		 *
    		 * @hooked generate_featured_page_header_inside_single - 10
    		 */
    		do_action( 'generate_before_content' );
    		?>
    
    		<header class="entry-header">
    			<?php
    			/**
    			 * generate_before_entry_title hook.
    			 *
    			 * @since 0.1
    			 */
    			do_action( 'generate_before_entry_title' );
    			
    			the_title( sprintf( '<h2 class="entry-title" itemprop="headline"><a href="%s" rel="bookmark">', esc_url( get_permalink() ) ), '</a></h2>' );
    
    			/**
    			 * generate_after_entry_title hook.
    			 *
    			 * @since 0.1
    			 *
    			 * @hooked generate_post_meta - 10
    			 */
    			do_action( 'generate_after_entry_title' );
    			?>
    		</header><!-- .entry-header -->
    
    		<?php
    		/**
    		 * generate_after_entry_header hook.
    		 *
    		 * @since 0.1
    		 *
    		 * @hooked generate_post_image - 10
    		 */
    		do_action( 'generate_after_entry_header' );
    
    		if ( generate_show_excerpt() ) : ?>
    
    			<div class="entry-summary" itemprop="text">
    				<?php the_excerpt(); ?>
    			</div><!-- .entry-summary -->
    
    		<?php else : ?>
    
    			<div class="entry-content" itemprop="text">
    				<?php
    				the_content();
    
    				wp_link_pages( array(
    					'before' => '<div class="page-links">' . __( 'Pages:', 'generatepress' ),
    					'after'  => '</div>',
    				) );
    				?>
    			</div><!-- .entry-content -->
    
    		<?php endif;
    
    		/**
    		 * generate_after_entry_content hook.
    		 *
    		 * @since 0.1
    		 *
    		 * @hooked generate_footer_meta - 10
    		 */
    		do_action( 'generate_after_entry_content' );
    
    		/**
    		 * generate_after_content hook.
    		 *
    		 * @since 0.1
    		 */
    		do_action( 'generate_after_content' );
    		?>
    	</div><!-- .inside-article -->
    </article><!-- #post-## -->

    Within my functions.php of my child theme, i have added the following code:

    // GP Columns
    add_filter( 'generate_blog_columns','adverts_list_columns' );
    function adverts_list_columns( $columns ) {
        if ( is_page_template( 'page-advert.php' ) ) {
            return true;
        }
        return $columns;
    }
    	
    // GP Masonry
    function adverts_list_masonry( $masonry ) {
    	if ( is_page_template('page-advert.php') ) :
    		return 'true';
    	endif;
    	return $masonry;
    }
    add_filter( 'generate_blog_masonry','adverts_list_masonry' );

    What I like to have is, that the adverts page looks like the blog page. Could you help me please?

    Also the page doesn’t show the featured images of the ‘advert’ post-type. the archive does (linked on right side, use “Anzeigenkategorie-3” for example with posts with featured image)

    Hope you can help me. Thanks and regards
    Patrick

    The adverts plugin i use is “WPAdverts”.

    #988374
    Tom
    Lead Developer
    Lead Developer

    Hmm, it looks like the <article> elements aren’t getting the correct classes.

    One thing I’m seeing is you need to replace this:

    get_template_part( 'content', get_post_format() );

    With this:

    get_template_part( 'content', 'advert' );

    Does that make a difference?

    #988463
    Patrick

    Hi Tom,

    Thanks for your fast reply, but the change to
    get_template_part( 'content', 'advert' );
    does not make a difference.

    do you have any other idea?

    #989013
    Tom
    Lead Developer
    Lead Developer

    Instead of your adverts_list_columns function, can you try this?:

    add_filter( 'generate_blog_columns', function( $columns ) {
        if ( is_page_template( 'page-advert.php' ) ) {
            return true;
        }
    
        return $columns;
    }, 50 );

    It seems like columns aren’t activated on that page as of right now.

    #989035
    Patrick

    Hi Tom,

    thanks again for your reply. I’ve changed to your last code, but the result is the same as before 🙁

    #989296
    Tom
    Lead Developer
    Lead Developer

    Do you have any other custom functions? Something might be overwriting the filter.

    #989375
    Patrick

    Hi Tom,

    no, I have no other changes within the functions.php. Also there are all other plugins deactivated. Only GP Premium, and WPAdverts are active.

    Best regards
    Patrick

    #989391
    Patrick

    If I change page-advert.php to index.php, than the design looks good. But I do not like to have this page as index.

    Think there is anywhere a problem between columns/masonry with pages. hmmmm

    #989894
    Tom
    Lead Developer
    Lead Developer

    Let’s try this:

    add_filter( 'generate_blog_columns', function( $columns ) {
        if ( is_page_template( 'page-advert.php' ) || 'advert' === get_post_type() ) {
            return true;
        }
    
        return $columns;
    }, 50 );

    Hopefully that does the trick 🙂

    #990034
    Patrick

    Hi Tom,

    Unfortunately, the change did not help 🙁

    I have setup a fresh installation with my child theme. Is it possible, that I give you the admin Informations?
    Maybe that helps with troubleshooting?

    How can I send these Informations in private mode?

    Thanks and best regards
    Patrick

    #990164
    Tom
    Lead Developer
    Lead Developer

    That sounds good – you can send the details through our form here: https://generatepress.com/contact

    Just be sure to mention this topic 🙂

    Thanks!

    #990170
    Patrick

    Thanks, send some seconds ago 🙂

    #991227
    Tom
    Lead Developer
    Lead Developer

    Ah, I think I see what’s wrong.

    Our code that adds the post classes check so to make sure we’re not on a singular post/page. In this case, we’re on a singular page (with a template), so the classes aren’t being added.

    There’s a way around it, but it’s not super backward-compatible.

    What if you used a standard custom post type archive instead of a page template? The adverts custom post type should have an archive created automatically.

    Let me know 🙂

    #991239
    Patrick

    Hi Tom,

    This would be ok for me too. But can you help me with that? I had no luck with creating an advert archive because it redirects everytime to the standard listing page from wpadverts.

    Best regards Patrick

    #991721
    Tom
    Lead Developer
    Lead Developer

    You might need to check with their support how to access the archives. I did some searching and found this: https://wordpress.org/support/topic/custom-theme-archive-for-advert/#post-11859653

    If it doesn’t work, it looks like their support is super responsive, so it may be worth asking.

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