- This topic has 21 replies, 2 voices, and was last updated 4 years, 8 months ago by Tom.
-
AuthorPosts
-
August 19, 2019 at 9:13 am #988089Patrick
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
PatrickThe adverts plugin i use is “WPAdverts”.
August 19, 2019 at 4:27 pm #988374TomLead DeveloperLead DeveloperHmm, 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?
August 19, 2019 at 8:52 pm #988463PatrickHi 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?
August 20, 2019 at 8:38 am #989013TomLead DeveloperLead DeveloperInstead 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.
August 20, 2019 at 8:54 am #989035PatrickHi Tom,
thanks again for your reply. I’ve changed to your last code, but the result is the same as before π
August 20, 2019 at 5:13 pm #989296TomLead DeveloperLead DeveloperDo you have any other custom functions? Something might be overwriting the filter.
August 20, 2019 at 10:45 pm #989375PatrickHi 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
PatrickAugust 20, 2019 at 11:36 pm #989391PatrickIf 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
August 21, 2019 at 9:14 am #989894TomLead DeveloperLead DeveloperLet’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 π
August 21, 2019 at 12:32 pm #990034PatrickHi 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
PatrickAugust 21, 2019 at 4:32 pm #990164TomLead DeveloperLead DeveloperThat sounds good – you can send the details through our form here: https://generatepress.com/contact
Just be sure to mention this topic π
Thanks!
August 21, 2019 at 4:51 pm #990170PatrickThanks, send some seconds ago π
August 22, 2019 at 8:49 pm #991227TomLead DeveloperLead DeveloperAh, 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 π
August 22, 2019 at 8:58 pm #991239PatrickHi 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
August 23, 2019 at 9:23 am #991721TomLead DeveloperLead DeveloperYou 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.
-
AuthorPosts
- You must be logged in to reply to this topic.