Help with Parsing error
-
Hi all,
I have created a custom post type called “members”.
I am using the free Kadence Theme with a child theme for my customisations and I want to add a widget area at the tope of the archive of this custom type. The widget is only for the archive page. Here’s what I’ve done so far:
1. Registered the widget area
// REGISTER NEW WIDGET AREA FOR THE TOP OF THE MEMBERS ARCHIVE function register_custom_widget_area() { register_sidebar( array( 'id' => 'members-map', 'name' => esc_html__( 'Top of Members Archive', 'theme-domain' ), 'description' => esc_html__( 'This is the area for the Members Map', 'theme-domain' ), 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>', 'before_title' => '<div class="widget-title-holder"><h3 class="widget-title">', 'after_title' => '</h3></div>' ) ); } add_action( 'widgets_init', 'register_custom_widget_area' );
2. I created an archive page template in the child theme under child-theme > template-parts > content which I named “archive.php” exactly as per the themes naming.
3. I opened this file and used the code below to add the widget area to the archive page:
<?php /** * The main archive template file for inner content. * * u/package kadence */ namespace Kadence; /** * Hook for Hero Section */ do_action( 'kadence_hero_header' ); ?> <div id="primary" class="content-area"> <div class="content-container site-container"> <main id="main" class="site-main" role="main"> <?php /** * Hook for anything before main content */ do_action( 'kadence_before_main_content' ); if ( kadence()->show_in_content_title() ) { get_template_part( 'template-parts/content/archive_header' ); } if ( have_posts() ) { ?> <?php if ( is_active_sidebar( 'members-map' ) ) : ?> <div id="membersmapsection" class="members-map"> <?php dynamic_sidebar( 'members-map' ); ?> </div> <?php endif; ?> <div id="archive-container" class="<?php echo esc_attr( implode( ' ', get_archive_container_classes() ) ); ?>"<?php echo ( get_archive_infinite_attributes() ? " data-infinite-scroll='" . esc_attr( get_archive_infinite_attributes() ) . "'" : '' ); ?>> <?php while ( have_posts() ) { the_post(); get_template_part( 'template-parts/content/entry', get_post_type() ); } ?> </div> <?php get_template_part( 'template-parts/content/pagination' ); } else { get_template_part( 'template-parts/content/error' ); } /** * Hook for anything after main content */ do_action( 'kadence_after_main_content' ); ?> </main><!-- #main --> <?php get_sidebar(); ?> </div> </div><!-- #primary -->
I now can see the widget area appear at the top of the custom post type archive page. The problem is that I can also see it at the top of the non-custom archive pages (such as the blog for example). What I want is for that widget area to appear only in the Members Archive page. and nowhere else.
The cose that makes the widget area appear is below:
<?php if ( is_active_sidebar( 'members-map' ) ) : ?> <div id="membersmapsection" class="members-map"> <?php dynamic_sidebar( 'members-map' ); ?> </div> <?php endif; ?>
So what I tried to do is to use is\_post\_type\_archive( $post\_types = ‘members’ ) as follows:
<?php ( is_post_type_archive( $post_types = 'members' ) && is_active_sidebar( 'members-map' ) ) : ?> <div id="membersmapsection" class="members-map"> <?php dynamic_sidebar( 'members-map' ); ?> </div> <?php endif; ?>
but I get an error saying Parse error: syntax error, unexpected ‘:’ in **/home/…/child-theme/template-parts/content/archive.php** on line **28** where line 28 is the linewith the is\_post\_type\_archive condition.
Can someone please help me with the correct syntax? I can’t understand what I am doing wrong.
- The topic ‘Help with Parsing error’ is closed to new replies.