How do I call the current post’s featured image in the sidebar? and if there is none, then a backup image?
Leave a Reply
You must be logged in to post a comment.
How do I call the current post’s featured image in the sidebar? and if there is none, then a backup image?
You must be logged in to post a comment.
I’m assuming you’re going to be outputting this on a singular page (Post, Page, Attachment)?
If so, the easiest thing to do is to put your post AND sidebar content inside the Loop, so that you have access to the
$post
global, and post-related template tags.Alternately, you could define a variable, inside the Loop, to hold
$post-ID
so that you can reference it outside of the Loop, i.e. in your sidebar.In either case, inside the Loop, you would have e.g.:
Then, in your sidebar:
Note: I’m assuming you’ll create a custom image size to output in the sidebar, e.g.
(which goes in
functions.php
, of course)