Forum Replies Created

Viewing 15 replies - 16 through 30 (of 48 total)
  • Thread Starter mike.chiv

    (@mikechiv)

    Okay so now I have this in functions.php:

    function infinite_scroll_render() {
    	$args = array(
    		'post_type' => 'post',
    	);
    	$post_query = new WP_Query($args);
    	if( $post_query->have_posts() ) : while( $post_query->have_posts() ) : $post_query->the_post(); 
    
    		get_template_part('entry');				
    
    	endwhile; endif;
    }
    
    add_theme_support( 'infinite-scroll', array(
        'type'           => 'scroll',
        'footer'         => false,
        'footer_widgets' => false,
        'container'      => 'blog-posts',
        'wrapper'        => true,
        'posts_per_page' => 5,
        'render'         => 'infinite_scroll_render'
    ) );

    And this in my blog template:

    $args = array(
    					'post_type' => 'post',
    				);
    				$post_query = new WP_Query($args);
    				if( $post_query->have_posts() ) : while( $post_query->have_posts() ) : $post_query->the_post(); 
    
    					get_template_part('entry');				
    
    				endwhile; endif; ?>
    				<?php if( $post_query->max_num_pages > 1 ) {
    					previous_posts_link('&laquo; Newer posts');
    	    			next_posts_link( 'Older posts &raquo;', $post_query->max_num_pages );
    	    		}
        			wp_reset_postdata();

    Instead of using the parameter for posts_per_page set in functions.php for infinite-scroll theme support, the blog page is now using my theme’s set value for posts_per_page, and infinite scroll is still not loading new posts.

    I have tried using the standard loop, but for some reason this only outputs the current page (blog.php) rather than all of my posts.

    Thread Starter mike.chiv

    (@mikechiv)

    Okay I tried adding the whole custom query to no avail.

    Here is my full code in functions.php:

    function infinite_scroll_render() {
    	$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    	$args = array(
    		'post_type' => 'post',
    		'posts_per_page' => 5,
    		'paged' => $paged
    	);
    	$post_query = new WP_Query($args);
    	if( $post_query->have_posts() ) : while( $post_query->have_posts() ) : $post_query->the_post(); 
    
    		get_template_part('entry');				
    
    	endwhile; endif;
    }
    
    add_theme_support( 'infinite-scroll', array(
        'type'           => 'scroll',
        'footer'         => false,
        'footer_widgets' => false,
        'container'      => 'blog-posts',
        'wrapper'        => true,
        'posts_per_page' => false,
        'render'         => 'infinite_scroll_render'
    ) );

    I still have the working “older posts” link, but infinite scroll does not kick in.

    Thread Starter mike.chiv

    (@mikechiv)

    Okay I tried a couple of variations for render:

    function infinite_scroll_render(){
    
    while( $post_query->have_posts() ) : $post_query->the_post();
    	get_template_part('entry');
    endwhile;
    
    }

    and:

    function infinite_scroll_render(){
    
    get_template_part('entry');
    
    }

    Neither worked. I’m not sure if this is because I am using a custom loop…tbh, I have no clue what to try to fix it!

    Mike

    Thread Starter mike.chiv

    (@mikechiv)

    Hi Jeremy,

    Thanks for your reply. I tried this already. I’ll give it another go just in case I did it wrong, though. If it doesn’t work I’ll post what I added for you to assess.

    Mike

    Thread Starter mike.chiv

    (@mikechiv)

    Never mind, I stumbled across the solution as soon as I posted this! Turns out that the email address I had set as the “sender” in my list settings in MailChimp had not been verified. I was warned of this in the “Campaigns” tab of the AutoChimp settings by an error message entitled “Recent campaign activity”

    Thread Starter mike.chiv

    (@mikechiv)

    Updated to 1.7.7 and everything is working fine again. Weird!

    Thread Starter mike.chiv

    (@mikechiv)

    Okay I tried on my phone. Logged into admin account and the issue persists.

    Thread Starter mike.chiv

    (@mikechiv)

    It is possible that my laptop has decided to log in as someone else. It shouldnt, but it’s possible. I’ll test today and report back.

    Thread Starter mike.chiv

    (@mikechiv)

    The latest version I believe. I can’t remember the number but I thought to try and update yesterday and there was no option to do so, so I can only assume it is up to date.

    Luckycharm1978, you’re a f***ing lifesaver! I was searching for ages for some of the code you posted above to no avail. You’re right, the Sportspress documentation should include much more information about refined customisation of pages. I have had similar issues with lack of responses to forum posts, and have had to do a lot of the legwork myself, which is why detailed responses including usable code such as yours are invaluable!

    Many thanks ??

    Thread Starter mike.chiv

    (@mikechiv)

    Plugin author/s, do you have any suggestions for point 2 in the OP?

    Thread Starter mike.chiv

    (@mikechiv)

    …or if you don’t want to cram in a huge block of unnecessary code, you can set up your calendars properly and use the very simple Sportspress shortcodes as described in this post.

    D’oh!

    mike.chiv

    (@mikechiv)

    Well my method suddenly looks massively long-winded now! I will probably change over to the shortcode!

    mike.chiv

    (@mikechiv)

    Hi there,

    I recently posted a very similar question and have had some success in solving it. My solution does not have all the simplicity of a shortcode unfortunately, but here it is just in case it helps. Screenshot of the results (Next matches are off-screen).

    In short, I ran several instances of WP_Query on my existing Sportspress Events, based on the desired team and whether or not the posts were published or scheduled, giving me latest and upcoming matches.

    It’s not quite grabbing the data from calendars as you requested, but you may be able to use Events in the same way. Or even modify the code to work for calendars…

    Anyway, hope this helps.

    Thread Starter mike.chiv

    (@mikechiv)

    Point 1 is now solved. Code:

    <?php
    // Relevant data for every match query
    $args = array(
    	'post_type' => 'SP_Event',
    	'orderby' => 'date',
    	'showposts' => 1,
    	'meta_key' => 'sp_team',
    	'meta_compare' => '='
    );
    
    // Add data to get previous matches only and prepare arrays for first and reserve team latest matches
    $args_l = $args;
    $args_l['post_status'] = 'publish';
    $args_l['order'] = 'desc';
    $args_fl = $args_l;
    $args_rl = $args_l;
    
    // Add data to get next matches only and prepare arrays for first and reserve team next matches
    $args_n = $args;
    $args_n['post_status'] = 'future';
    $args_n['order'] = 'asc';
    $args_fn = $args_n;
    $args_rn = $args_n;
    
    // Apply team ID to each recent match array (to make meta compare work) and run WP_Query on each
    $args_fl['meta_value'] = 172;
    $args_rl['meta_value'] = 213;
    $first_team_latest_result = new WP_Query($args_fl);
    $reserves_latest_result = new WP_Query($args_rl);
    
    // Apply team ID to each upcoming match array (to make meta compare work) and run WP_Query on each
    $args_fn['meta_value'] = 172;
    $args_rn['meta_value'] = 213;
    $first_team_next_match = new WP_Query($args_fn);
    $reserves_next_match = new WP_Query($args_rn);
    
    // Merge all team queries into one array
    //For some reason the_loop() won't work on $matches, so I had to use a for loop and various functions to get the data
    //required. See below.
    $matches = new WP_Query();
    
    $matches = array_merge( $first_team_latest_result->posts, $reserves_latest_result->posts, $first_team_next_match->posts, $reserves_next_match->posts);
    
    $matches->post_count = $first_team_latest_result->post_count + $reserves_latest_result->post_count;	
    
    ?>
    <section id="latest-results" class="fixtures">
    		<header>
    			<h1 class="column-title">Latest results</h1>
    			<hr>
    		</header>
    		<?php for($i=0; $i<2; $i++){
    			if( !$matches[$i] ) { continue; };
    			$current_id = $matches[$i]->ID;
    			$teams = sp_get_teams($current_id);
    			$logos = null;
    			foreach($teams as $team){
    				$logos[] = sp_get_logo($team);
    			}
    			$match_date = mysql2date("l, jS M Y", $matches[$i]->post_date) . " - " . sp_get_time($current_id);
    			$scores = sp_get_main_results($current_id);
    			$link = get_the_permalink($current_id);
    			?>
    			<section class="match-container">
    				<a href="<?php echo $link; ?>" class="anchor-overlay"></a>
    				<h2><a href="<?php echo $link; ?>"><?php echo get_the_title($matches[$i]); ?></a></h2>
    				<p class="match-date"><?php echo $match_date; ?></p>
    				<div class="group match-result-and-logos">
    					<div class="logo1"><?php echo $logos[0]; ?></div>
    					<h3 class="match-score"><span class="match-score-number"><?php echo $scores[0]; ?></span><span class="match-score-delimeter">-</span><span class="match-score-number"><?php echo $scores[1]; ?></span></h3>
    					<div class="logo2"><?php echo $logos[1]; ?></div>
    				</div>
    			</section>
    		<?php } ?>
    	</section><!-- latest results -->
    	<section id="next-matches" class="fixtures">
    		<header>
    			<h1 class="column-title">Next matches</h1>
    			<hr>
    		</header>
    		<?php for($i=2; $i<4; $i++){
    			if( !$matches[$i] ) { continue; };
    			$current_id = $matches[$i]->ID;
    			$teams = sp_get_teams($current_id);
    			$logos = null;
    			foreach($teams as $team){
    				$logos[] = sp_get_logo($team);
    			}
    			$match_date = mysql2date("l, jS M Y", $matches[$i]->post_date) . " - " . sp_get_time($current_id);
    			$link = get_the_permalink($current_id);
    			?>
    			<section class="match-container">
    				<a href="<?php echo $link; ?>" class="anchor-overlay"></a>
    				<h2><a href="<?php echo $link; ?>"><?php echo get_the_title($matches[$i]); ?></a></h2>
    				<p  class="match-date"><?php echo $match_date; ?></p>
    				<div class="group match-result-and-logos">
    					<div class="logo1"><?php echo $logos[0]; ?></div>
    					<p class="versus"><strong>VS</strong></p>
    					<div class="logo2"><?php echo $logos[1]; ?></div>
    				</div>
    			</section>
    		<?php } ?>
    	</section><!-- next matches -->

    Still need help with point 2, though.

Viewing 15 replies - 16 through 30 (of 48 total)