Code to use in template
-
Hi Ryan,
Thanks for your plugin, keep up the good work of updating it regularly!
I do miss one thing though in your instructions: how I can call the unique header field in a template.
I do have a website that has a header section and this uses the featured image of a post as header image:
<?php if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it. echo 'style="background-image: url(\''; the_post_thumbnail_url('post-background'); echo '\'); background-repeat: no-repeat; background-position: center center; -webkit-background-size: cover; -moz-background-size: cover; -o-background-size: cover; background-size: cover;"'; } ?>
But for one post type the features image is square and not suitable as header image. That’s why I want to add some code to the header, to check first if a custom header has been set.
I would like to use it something like this (don’t mind the ‘syntax’, I just describe the ‘if-then-else’ statements):
“if ‘page template = X’ ->
if isset(custom header) { return custom header image }
else ‘return default header image’ // (either enter url here manually or set default header image somewhere else for all posts, if possible)
else ‘do default code like shown above'”.So compared to my current code I’m looking for the ‘has_post_thumbnail()’ equivalent (to check if custom header is set) and the ‘the_post_thumbnail_url(‘post-background’)’ equivalent for your plugin. Could you add some code snippets for this to the description, like WP User Avatar did (scroll down to the ‘advanced settings’ in the descritpion)? Would appreciate it very much!
- The topic ‘Code to use in template’ is closed to new replies.