Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter wannalearnthis

    (@wannalearnthis)

    I would say both, because I modified the query to display only one post, so next post is also next page.

    However, yes, I am referring to a paginated post.

    The code doesn’t necessarily break as of to give me an error, the outcome of going to the next page (paginated post) is that the background ($posts[0]) simply disappears.

    Thread Starter wannalearnthis

    (@wannalearnthis)

    Thanks s_ha_dum!

    using $posts[0] helps me to get the image and other content in the first page, but the code breaks after going to the next page.

    MAYBE I FORGOT TO WRITE AN IMPORTANT PIECE OF INFORMATION: I AM WORKING ON THE INDEX PAGE, NOT SINGLE OR STATIC PAGE.

    I want the function to be dynamic and update with the loop, including pagination.

    Thread Starter wannalearnthis

    (@wannalearnthis)

    I ended up doing something like this:

    (However, I feel like the function is redundant, if anyone has a better idea, please share)

    $grid_src = get_bloginfo('stylesheet_directory') . '/library/images/ergos_grid_01.svg';
    $dynamic_grid = 'style="background-image:url(' . $grid_src . ');"';
    
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $the_query = new WP_Query('posts_per_page=1'.'&paged='.$paged); //display X posts per page
    
    	// The Loop
    	if ($the_query->have_posts()) : while ( $the_query->have_posts()) : $the_query->the_post();
    
    		$thumbnail_src = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
    		$dynamic_background = 'style="background-image: url(' . $grid_src . '), url(' . $thumbnail_src . ') ;"';
    		echo $dynamic_background;
    
    	endwhile;
    
    	else:
    		echo 'no backgrounds found';
    	endif;
    
    // Reset Post Data - Best used after custom or multiple loops created with WP_Query
    	wp_reset_postdata();

    Thread Starter wannalearnthis

    (@wannalearnthis)

    $post_args = array(
    
    	'posts_per_page' => 1,
    	'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
    	'orderby' => 'date',
    		);
    
    query_posts($post_args, $wp_query->query);
    Thread Starter wannalearnthis

    (@wannalearnthis)

    This is the code I have before the main loop:

Viewing 5 replies - 1 through 5 (of 5 total)