Site logo

Archived topic

Customized template means that the Sidebar Layout is ignored

5 replies · Started by Henry on December 7, 2021

Viewing posts 1–6 of 6

I have a customized PHP template for a page that acts as our home page.

The reason it has been customized is that it has a fairly complex operation with the ACF plugin.

Anyways - what has happened is that the template defaults to the right-hand side widget column, and if I set it to any other option the sidebar remains where it is...

If I remove this line:

do_action( 'generate_after_primary_content_area' );
//generate_construct_sidebars();
get_footer();

And comment out the //generate_construct_sidebars(); does that mean that I will force the template to just have one column or should I create a one-page column in the elements option using GeneratePress Pro?

Thanks! Hope that makes sense...

Here's the template:

<?php

/**
 * Template Name: Home List
 * Template Post Type: page,list
 *
 * @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 ( generate_has_default_loop() ) {
				while ( have_posts() ) :

					the_post();

					generate_do_template_part( 'page' );

				endwhile;
			}

			/**
			 * generate_after_main_content hook.
			 *
			 * @since 0.1
			 */

			do_action( 'generate_after_main_content' );

			?>

		<?php
			$args = [
			    'post_type'=> 'event-series',
			    'orderby' => 'meta_value_num',
  				'order' => 'ASC',
			    'meta_query'=>[
			        [
			            'key'=>'event_loop_0_event_start_date',
			            'compare'=>'EXISTS'
			        ]
			    ]
			];

			$eventsQuery = new WP_Query($args);

			?>
			<div class="section-event-items inside-article">

					<h2>All Events</h2>

			    <?php
			        $allEvents=array();
			        $currentDate=time();
			        while($eventsQuery->have_posts()):

			        	$eventsQuery->the_post();
			        	 $mainLink = get_the_permalink();

			        	//$monthYear=

			         	if( have_rows('event_loop') ):
    						while( have_rows('event_loop') ) : the_row();
                            if(strtotime(get_sub_field('event_start_date')) < $currentDate)
                            	continue;
			        	    $monthYear= date("01-m-Y",strtotime(get_sub_field('event_start_date')));
			        	       if(!isset($allEvents[$monthYear])){
			        	       		$allEvents[$monthYear]=array();
			        	       }
			        	       $row=get_row(true);
			        	       $row['mainLink']=$mainLink;

			        	       $allEvents[$monthYear][]= $row;

    						endwhile;
						endif;

			    	endwhile;

			    	 uksort($allEvents, function($a,$b){

								 return strtotime($a) - strtotime($b);
							});

			    	if(!empty($allEvents)):
			    		foreach($allEvents as $events):
			    			 //$month =

							usort($events, function($a,$b){
								 return strtotime($a['event_start_date']) - strtotime($b['event_start_date']);
							});
			    			$eventDate=strtotime($events[0]['event_start_date']);
			    			 echo '<div class="event-list-wrap"><h2  class="month-name">'.date("F Y",$eventDate).'</h2>';
			    			 foreach($events as $event):
                             $event_country = $event['country'];
    							$event_address = "<span class='acf-country-flag-icon famfamfam-flags ".strtolower($event_country['value'])."'></span>".$event_country['label'].' | ';
    							if($event_country['value'] == "US")
    								$event_address.= $event['us_state']['label'].', ';

    							$event_address.= $event['city'];

		        				echo  '
									<div class="event-post-item-row" style="padding-bottom:16px;">
										<span class="event-title">
											<a href="'.$event['mainLink'].'" target="_blank">
											'.$event['event_title'].' </a>
										</span>

										<br />

										<span class="event-date">
											'.$event_address.'
										</span>

										<br />

										<span class="event-date">'.$event['event_start_date'].'</span>

		        					</div>';
			    			 endforeach;
			    			 echo '</div>';
			    		 endforeach;
			    	else :
			    	       echo '<div class="no-event-found">Event Not Found </div>';
			    	endif;
			    ?>

<!-- https://www.advancedcustomfields.com/resources/taxonomy/ -->

			</div>

		</main>

	</div>
	<?php

	/**
	 * generate_after_primary_content_area hook.
	 *
	 * @since 2.0
	 */
	do_action( 'generate_after_primary_content_area' );
	generate_construct_sidebars();
	get_footer();

Hi there,

if you remove ( or comment out as you have ) the generate_construct_sidebars(); then you should just have the main content container ie. a single column layout.

Thanks very much

You're welcome

Hi David

I just thought I'd follow up on this ticket before I create a new one.

In the same breath, is it possible to force the sidebar in a PHP template, regardless of the customizer sidebar settings and any GP layout elements defined?

I want to be able to show the sidebar on the right of my single-used-car.php custom post type at the PHP level, without having to create a GP element or edit the customizer settings.

Please let me know if this is possible?

This archived topic is closed to new replies.