wannalearnthis
Forum Replies Created
-
Forum: Fixing WordPress
In reply to: Get Attachment outside the LoopI 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.
Forum: Fixing WordPress
In reply to: Get Attachment outside the LoopThanks 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.
Forum: Fixing WordPress
In reply to: Get Attachment outside the LoopI 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();Forum: Fixing WordPress
In reply to: Get Attachment outside the Loop$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);Forum: Fixing WordPress
In reply to: Get Attachment outside the LoopThis is the code I have before the main loop: