In your wp_query loop you’ll want to check the page template of the current post object. You’ll be able to set that to a string and use it however you want
Close to this:
while ( $query->have_posts() ) : $query->the_post();
if (is_page) {
$pageTemplate = basename( get_page_template() );
echo "<p class=\"" . $pageTemplate . "\">" . get_the_title() . "</p>";
}
endwhile;
Refer to the codex page for more info on the function
Related Posts:
- Single page theme
- add_filter(‘query_vars’) not working in custom template
- How to generate feed for custom template
- Fetching $_POST from Page Template into functions.php
- Passing query variables to a custom page template
- Page template query with WP_Query
- How to display page content in a page template?
- How to prevent execution of default query, while preserving ability to use WP_Query in template?
- How to stop wordpress to make the default query?
- $wp_query initiation?
- Check if a menu is empty?
- Executing Queries in tag.php
- ajax category filter
- WordPress 4.9.5 PHP intermittent warning trim() expects parameter 1 to be string, array given
- Pagination custom query
- Order by two meta keys
- New WP_Query calls Pre_get_posts filter twice
- how to access query string in wordpress?
- Is there a better way to pull in custom content without querying posts?
- Adding wrapper elements in the_date() like in the_title()?
- Pass $page_id to new WP_Query
- Merge two search functions for custom post type
- Make a SQL query with wpdb in WordPress
- how to use pre_gets_posts to exclude one queried ID from homepage loop
- Error with function in functions.php?
- WordPress Custom Search Form Displaying Unexpected Results
- Is there a way to make this kind of loop shorter and nicer?
- Pagination on template page for custom query redirecting to index.php
- Utilising an existing page while using the “s” query parameter
- Create a page template for “top rated posts” but show full content and not just a list
- Exclude authors IDs from WP_Query
- Loading two different AJAX requests on two different pages
- Getting the post terms ‘wp_get_post_terms’ per post when within the functions.php file
- WP_Query returns different results from get_posts() [closed]
- How to load a script code only in posts?
- inserting content of 1 Post to in another with a template hierarchy
- Get posts in taxonomy randomly
- Multiple meta_key ordering with pre_get_posts
- How do I fit WP_Query arguments into a function?
- Create a notification for post field
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- Add URL Rewrite Rule To WordPress
- wp_query on page template not working (Genesis framework)
- Pagination for custom loop on custom page template is not displaying anything
- Trying to get property of non-object in: $wp_query
- WordPress dynamic AJAX query
- How to create Page templates for showing Blog posts in different layouts?
- relation OR instead of AND – Filtered term ID’s in loop
- Unable to paginate a custom page query
- How to stack name list in non-alphabetical order?
- odd behaviours from template tags
- Page template doesn’t display simple HTML if inserted into other page?
- problem with the loop
- get_children() Archive Template
- In a WP_Query can I force the results’ is_singular() to be set to false?
- How to separate two columns from one content on a page template?
- What’s the best way to make a blog page on WordPress?
- How to use custom page for all posts with custom url, call another directory?
- Pagination repeating posts on search results
- How to check if logged in user have pending custom post?
- Custom WordPress post query for displaying time-released content on website
- INNER JOIN custom tables – SQL Query
- SEARCH QUERY PLEASE HELP | call_user_func_array() expects parameter 1 to be a valid callback php
- How to display a post(by id) along with css in a page?
- Custom query for custom post type not getting correct post ID
- Finding post ID dynamically on click
- Pagination Shows Up But Won’t Work on Custom Gallery Page
- how to move a page from one drop down menu to another drop down menu
- How to upload 3 attachments to current post?
- Global page ID variable empty error
- ACF: using two loops, the_field returns field content from another loop
- How to exclude posts by ID within a category/archive loop
- WP_Query & shortcode : Return 3 articles from a category WordPress
- Get post Number with local loop and template
- Save query in function for custom gallery
- Search Filter With Custom Taxonomy and Custom Fields : How do I handle it via plugin?
- Seach and categories not working when ignoring sticky posts in main loop
- Problem with custom WP_Query and underlying pagination/posts_per_page
- Calling a function with WP_Query only ever brings the first result
- How can I use a specific wordpress page template if certain words are used in page title [closed]
- What argument does my function need to echo get_results() query results
- Using URL variables on a custom WP_Query
- Declare inline background image in functions.php
- I wan to process the following js to process the AJAX Request on my function to calculate author Total Post views
- Hiding all posts/products/pages from a site based on a custom taxonomy/domain name
- Pagination is not working on custom query inside a custom home page template
- ordering and optimizing functions
- Why WP_Query in functions.php is not working when get_posts works?
- When importing a database any page with a wp_query in doesn’t work
- Having trouble using this post category query on multiple pages?
- WordPress pagination returns the same posts
- WP_Query and DES sort for Custom Taxonomy based upon a meta field?
- How to write a query-function as a query-shortcode?
- Loop on a wordpress Page instead of content coming from the WP text editor
- 1500+ duplicate queries via get_option function (query monitor)
- Variations as Single Products [closed]
- on attachment.php, how to display previous and next attachment links that follow the same order as a custom WP Query
- Excluding a category from frontpage but not from WP_Query
- How WP determines archive page vs single page?
- How to prevent random 302 canonical-ish redirect on custom template