You won’t get anything back from your template simply because the loop returns what is in the main query object for that specific page. To see what is actually in the main query object, you should do var_dump( $wp_query );
outside the loop.
To display custom content on a page template, you will need to run a custom query to pull in the required posts. pre_get_posts
does not work on page templates, so you will need WP_Query
or get_posts
to run a custom query
EXAMPLE:
$args = [
'posts_per_page' => 6,
// Add any extra query parameters here according to https://codex.wordpress.org/Class_Reference/WP_Query
];
$q = new WP_Query( $args );
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
$q->the_post();
if ( has_post_thumbnail() ) {
the_post_thumbnail();
}
}
wp_reset_postdata();
}
Related Posts:
- Jquery Slider for profile template
- if ( is_home() && ! is_front_page() )
- Is including the loop necessary for page.php? [duplicate]
- What is best way passing variables to theme templates and using them different places like widgets?
- Page template not displaying
- Loop through pages with specific template
- How to get_template_part using AJAX?
- Customize WooCommerce Product Images (Placement and size) [closed]
- wp alchemy multiple image uploader output images to template
- code suddenly appearing from my tempate second loop
- Get search.php results in header.php?
- WordPress Loop inside Loop?
- Template structure
- How to show “teaser” posts on blog / archive pages, otherwise full posts
- Order archive results by post id in custom taxonomy template
- Default ‘post’ post type archive slug?
- show random image in loop if image is not set
- How do I make a variable available inside partials?
- 404 Template customization | Want 10 recent Post on the 404.php error page apart from the error Notice
- Second Loop Showing Only One Post on Single Post Page
- How do I put my frontpage featured image in a page template for home.php?
- Closing the loop…featured image variable based on post id
- using wp_get_attachment_image_src in foreach loop
- How to print redux gallery feilds id? [closed]
- Multiple instances of Featured Image Thumbnail As A Background On Homepage
- Get markup for post without loading into the template
- How to render the single post template with the post name?
- excerpt not showing up
- new custom theme – posts displaying on top of one another
- How do i create a list-posts-page?
- How to sort a loop after most viewed
- Thumbnail Image Rounded Corners w CSS (or any other good method)
- How to loop specific Category menu from archive page?
- How do I set the Stewart Search Template to return only published posts in the result
- Is it possible to set archive.php instead of index.php to display blog?
- Using is_page_template inside loop
- Get gallery in loop through ajax
- Get a specific size from wp_get_attachment_image_src
- is it bad to copy the loop for a template?
- Is “the loop” a template tag?
- Return only one post format in index.php [duplicate]
- Deeply Nested Menu Loop with Twig using Timber [closed]
- WordPress with woocommerce custom query
- Alternative layout the loop
- Template included with plugin doesn’t return all posts for custom taxonomy
- Creating a archive for taxonomy terms, not the term results
- Secondary loop cuts off at 10 posts?
- Need a conditional to test if title of parent page matches title of child page
- Get gallery and product gallery images full size
- Building theme so user can change header image [closed]
- Is there a way to target only images within the loop?
- Change the way wordpress outputs images or image galleries
- get all page templates
- Load featured article once in a loop
- wordpress showing all posts instead of date range
- Loop doesn’t give the thumbnail the right parent (or class)
- How to implement template file and the loop
- Same posts within a paginated page
- How can I create an entirely new, separate display of posts?
- How to split a loop into multiple columns
- Cleanest Way to Select Every Second Element in a Loop?
- Get post by page name or slug
- save_post + insert_post = infinite loop
- ACF Repeater loops and resets – where is the reset_rows() documentation? [closed]
- Why do themes have `while( have_posts() )` in templates like single.php?
- Apply styling only to first page sticky posts
- Loop through child images of a parent for a Nivo Slider
- pop-up lighbox with AJAX
- Load comments per post on click with AJAX
- taxonomy tags 404 to custom post types
- A smarter way to display multiple loops inside a page template
- How to print out menu names in the foreach loop?
- How do I style the first two posts of a loop
- How to get the role id from the role name?
- How do I paginate a get_posts() request inside another page loop (Paginating childpages)
- How to insert category list into post creation page, and retrieve chosen categories?
- How to create a multidimensional array with multiple loops
- How to create custom popup in shop page on every loop products?
- How do you output an unknown number of images in a custom post type with desired markup?
- Getting posts link in WordPress
- Loop through an array inside a class using foreach [closed]
- query_posts clarification needed
- Adding first and last classes to three column layout in Bones boilerplate
- Does search.php autofilter The Loop?
- “the_excerpt” in loop just keeps repeating first post?
- wpdb inside foreach loop only returns first result – 2 other similar cases found [closed]
- Add 2 values to post__not_in
- get_children() Archive Template
- How can I pass additional params to a shortcode while in a loop?
- Hover a css icon width other color inside wp_get_attachment_image
- Add all category as classes in foreach loop
- How to avoid appending “null” in Ajax?
- Adding pagination to WP_Query [duplicate]
- Insert/sticky multiple posts in multiple positions
- Stuck with conflicting loops on page template
- How to get current page id and compare it to looped pages inside the same page?
- Show amount of posts created today above loop?
- How to create WordPress loop with combination of 4 and 2 columns twitter-bootstrap?
- posts_nav_link() not working on index.php
- How to add custom HTML markup and classes to the_content()?