@kaiser answer gives you the solution. I see from your comment that you don’t understand, so I upvoted his answer and translate it in code:
<?php
$bannerimg = 'home.jpg';
$post = is_singular() ? get_queried_object() : false;
if ( ! empty($post) && is_a($post, 'WP_Post') ) {
if ( 'about' == $post->post_name || '2' == $post->post_parent ) {
$bannerimg = 'about.jpg';
} elseif ( 'learning' == $post->post_name || '56' == $post->post_parent) ) {
$bannerimg = 'teaching.jpg';
} elseif ( 'admissions' == $post->post_name || '15' == $post->post_parent ) {
$bannerimg = 'admissions.jpg';
}
}
Related Posts:
- Stop WordPress Wrapping Images In A “P” Tag
- How to add an admin notice upon post save/update
- How to mark articles as read?
- Ajax Load More Posts in Category Page
- How does one reduce the number of stored revisions?
- How to Group Posts by the First Letter or Number?
- posts page – different lengths of excerpt
- Comments are assigned to wrong or related post
- Post X of Y in single.php / sidebar.php
- How can I get a list of latest posts outside of my WP install?
- WordPress Posts Out Of Order after 3.1 Update
- Paragraphs removed when using get_post_custom()?
- How to customize read more link
- First hook to use current page post id
- Post taxonomy from exif data
- Underscores.me retrieve next / previous post thumbnail in post_nav function
- How can a guest view the “Pending Review” Post?
- Adding a text link under the post title in the lists of posts
- Count to how many categories a post belongs to
- WP_Query: offset ignored when posts_per_page is -1?
- Create cron job without a plugin?
- Post Filter by Date and time
- WordPress version 3.8 – Preview button not working for editor
- Which URL to enter into browser to show all posts in archive.php?
- Using wp_list_categories like the the_category (showing just current categories of a post)
- add new post default view
- How to filter my search in post if contains a word in title, content or excerpt?
- Posts list in custom taxonomy
- Genesis + Ajax + Jquery | Failling to call action
- Need help with category listing!
- Random ajax load only works with posts_per_page set to -1
- MySql query to get posts with all meta and terms
- Query posts and return XML
- A friend wants to make a comment on one of my articles, she has to be logged to wordpress?
- How to display only feautured/sticky listings on the homepage
- Can’t update old posts 3.5.2
- Is it possible to paste a link without tags and make it directly a link in a post?
- Shortcode to display the latest news article within a page
- How to make the first post in the loop be styled like a “new / featured” post?
- Adding a blog archive with pagination using WP_Query
- How to get Tags with specific post id
- Help diagnosing scheduled post problem with transition_post_status
- Archiving posts in wordpress
- User Selectable Delete of Pages
- Get post content with all filters applied, knowing post id
- Is it possible to customize the post according to post format in single.php?
- query post limits
- is_page() and is_page_template() not being differentiated
- Post type no single page
- How to show content without excerpt?
- Get attachments only for this post
- How can I list posts by author?
- Add hero image to home page (blog format) via the dashboard
- Querying another post category to match current post and display in loop
- Having pages after specifying post_type post
- I want to show my post for limited time, how is it possible?
- Query function not executed between element [closed]
- Microformats in a single post – layout conflict
- Conditional css for custom post type
- Get author posts count after excluding a category
- How to edit the ‘
- How to add PHP code snippet to all Post pages?
- How Can I Always Display A Particular Post First Using WP_Query?
- MySQL: Possible to replace all of wp_posts.post_content(id#) via UPDATE + REPLACE + SELECT?
- Different background colors for posts with WordPress
- I want to add another search box on posts page in dashboard
- Move position in post list for a custom checkbox column
- How to preserve HTML from posts in RSS feed
- Menu does not foward to the linked posts
- WordPress Post ids big increment
- How to get post creation date?
- How to set the post permalink using the WordPress REST API?
- Multiple post in One Loop in wordpress
- Order posts inside bootstrap card columns
- Save ACF with a save button on a post
- Delete attached images from posts
- Unable to edit or post after enabling SSL
- How do I customize the post page
- Clicking on a Post takes 10+ seconds for the server to respond, Pages will respond immediately
- Schedule image post on download
- Show posts in a parent directory [duplicate]
- How can we print out total number of posts filtered by post type and category?
- WordPress infinite post cycle problem
- All my posts don’t show, only the headline is displayed on the homepage
- show latest authors blog post
- How to prevent people from seeing an attachment to a scheduled post that’s released in future?
- How can I access my posts on my wordpress site, now I’ve lost the domain name for it?
- Page not loading content – Body archive – page
- External link not showing on post but showing on comment
- standard wpGallery for post won’t work
- Why is $_POST Empty in Profile Edit Admin?
- TCPDF and permalinks
- How can i show only 30% of the “the_content(“More…”)”?
- How do i put a dropdown list of ALL my post in the sidebar menu?
- How remove “recent comments” title without modifying code? [closed]
- Return All Post from publish to draft [duplicate]
- Get posts after calculating meta key
- Articles show some of text [duplicate]
- How to make post stick to its own div
- How to monitor the first publish date?