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
- 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
- Order by two meta keys
- Finding all results from database within 500 miles of the given latitude and longitude [closed]
- Function to check if author has posted within the last x days
- Calling a custom excerpt function in a local loop
- Single page theme that uses pages for the content
- How to get any tag ID
- Trying to list out child pages with WP_Query
- Dynamically Override Fancy Title – Part II
- query posts in functions.php and update a field
- Get posts using WP_Query
- Finding post content that begins with a specific character
- Pass the same object to multiple widgets in a template with one query
- What are the differences between “Latest Posts” and “Static Page”?
- Adjust which tempalte a page uses with a function?
- Best practice custom function, where to echo the variables?
- How to get user_id from wordpress database inside ajax function?
- WP_Query doesn’t get sticky post at the top, when used in a page template
- Have functions work outside the loop with 404 override
- Multiple Loops Inside a Function
- How to enable template page only for a post id page
- Show all post for a given category
- Display posts from only one post form in custom query and exclude in main query
- Get pagination working for custom loops within page templates
- How is WP_Query parsed to determine which template to request?
- Category applied to pages, creates multiple breadcrumb entries after a search query (On the translated site)
- How to filter, restrict and return posts based on custom user meta information
- WP Query using tax_query & meta_query
- wordpress search word, “hello world” ===> ‘hello+world’ ===> ‘hello’, ‘world’
- meta_query not working as expected
- 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
- Is there a way to make this kind of loop shorter and nicer?
- Pagination on template page for custom query redirecting to index.php
- Create a page template for “top rated posts” but show full content and not just a list
- Exclude authors IDs from WP_Query
- 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
- 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
- Pagination for custom loop on custom page template is not displaying anything
- WordPress dynamic AJAX query
- 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?
- 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?
- 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
- INNER JOIN custom tables – SQL Query
- How to display a post(by id) along with css in a page?
- Custom query for custom post type not getting correct post ID
- 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
- How to exclude posts by ID within a category/archive loop
- WP_Query & shortcode : Return 3 articles from a category WordPress
- 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
- 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
- Pagination is not working on custom query inside a custom home page template
- ordering and optimizing functions
- 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?
- 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