Tagged: 

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #5681
    EsansB
    Participant

    Hello,

    First, thank you for this awesome plugin very useful.

    My problem is quite simple by I can’t find the way !

    In my project of website, I’ve make a special page for each category of events, one for Shows and an other for Exhibitions, and I just want those pages to show a number of 15 event-posts.

    I’ve tried many times with the wP_Query in the archive-event.php page, and the filter of number is working, but the filter of event category is gone and all the events are mixed up together.

    So what should be the code ?

    Thank in advance,

    PS: Sorry for my english

    #5682
    Bartosz
    Keymaster

    Ok, are you using a pre_get_posts filter? I assume you should in this case.

    // Modify events query
    function df_custom_events_query($query) {
    	
    	if (is_admin() || !$query->is_main_query() && empty($query->query_vars['suppress_filters']))
            return $query;
    	
    	// apply modifications for evens archive and event taxonomies pages
    	if (is_post_type_archive('event') || is_tax('event-category', 'event-location', 'event-organizer', 'event-tag')) {
    		$query->set('posts_per_page', 15); // or any number you need
        }
    	return $query;
    }
    add_filter('pre_get_posts', 'df_custom_events_query');
    #5684
    EsansB
    Participant

    Thanks for answering so fast !
    I don’t thin so, but I am a absolute beginner !

    This is my initial code in archive-events.php :

    <div id="content">
            	<div id="cat-post-2">
    
    			<?php do_action('em_archive_description');
    			?>
    
    		<?php // start the loop
    		if (have_posts()) : ?>
    <?php do_action('em_before_events_loop');
    			?>
    
    			<?php
    			while (have_posts()) : the_post(); ?>
    				
    				<?php em_get_template_part('content', 'event'); ?>
                   
    
    			<?php endwhile; ?>
    			
    			<?php do_action('em_after_events_loop');
    			?>
                
    
    		<?php else : ?>
    
    		<div class="post" id="post">
    			
    			    <div id="post_content">
    			    	
    			        <p><?php _e('Apologies, but no events were found.', 'events-maker'); ?></p>
    			        
    			    </div>
    			
    			</div>
    
            <?php endif; ?>
            
    </div>
    <div id="sidebar-bloc">
    <?php get_sidebar('classic'); ?></div>
    </div>

    I’ve put your code in the functions.php of my theme, but it doesn’t work !

    Quite lost on the way !

    #5685
    Bartosz
    Keymaster

    Oh, I’m sorry.

    This:

    is_tax('event-category', 'event-location', 'event-organizer', 'event-tag')

    should be an array:

    is_tax(array('event-category', 'event-location', 'event-organizer', 'event-tag'))

    #5686
    EsansB
    Participant

    So, in functions.php :

    // Modify events query
    function df_custom_events_query($query) {
    	
    	if (is_admin() || !$query->is_main_query() && empty($query->query_vars['suppress_filters']))
            return $query;
    	
    	// apply modifications for evens archive and event taxonomies pages
    		if (is_post_type_archive('event') || is_tax( array( 'event-category', 'event-location', 'event-organizer', 'event-tag' )) {
    		$query->set('posts_per_page', 15);  // or any number you need
    	 }
    	 return $query;
    }
    
    add_filter('pre_get_posts', 'df_custom_events_query');

    The result : “Parse error: syntax error, unexpected ‘{‘ on line 107”

    It’s the line :
    if (is_post_type_archive('event') || is_tax( array( 'event-category', 'event-location', 'event-organizer', 'event-tag' )) {

    No result by trying differents syntax ! Any ideas ?

    #5687
    Bartosz
    Keymaster

    It should be working.

    Question, what does it mean: special pages for categories? How you are doing this? Are you doning a custom query?

    #5688
    EsansB
    Participant

    No, it’s means the archive-events.php is the template for 2 importants pages of this website, recensing the 2 biggest categories of events, Exhibitions & Shows to come.

    No special difficulty until then, just one to list a specific number of posts, which different of the homepage.

    #5689
    Bartosz
    Keymaster

    Please try again with that:

    
    // Modify events query
    function df_custom_events_query($query) {
    	
    	// apply modifications to events archive and event taxonomies pages
    	if (
    		!is_admin()
    		&& $query->is_main_query()
    		&& empty($query->query_vars['suppress_filters'])
    		&& (is_post_type_archive('event') || is_tax(array('event-category', 'event-location', 'event-organizer', 'event-tag')))
    	)
    	{
    		$query->set('posts_per_page', 15);  // or any number you need
    	}
    
    	 return $query;
    }
    add_filter('pre_get_posts', 'df_custom_events_query');
    
    #5690
    EsansB
    Participant

    Good news, I finally succeed by insert this code in archive-events :

    global $query_string; // récupère la requête initiale générée par WordPress
    query_posts( $query_string . '&posts_per_page=12' );
    if( have_posts() ) : while( have_posts() ) : the_post()
      // votre code
    endwhile; endif;

    Thank you for your help !

    #5691
    Bartosz
    Keymaster

    Yeah, but this not the most elegant solution – it may generate issues with pagination.

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