0

Below is the code for my template-banner.php file. However depending on the post or page I want to display a custom banner. I have tried some plugins made for this however these do not work for my theme so it has to be manually coded.

Any ideas? Thanks!

<?php 
if(get_post_type()=='page'){
$inner_banner_title=get_the_title();
} else if(is_search())
{
$inner_banner_title = 'Search : '.esc_html( get_search_query() );
} else
{
if(is_category()){
$inner_banner_title = single_cat_title( '', false );
}
else
if( is_tag() ) {
$inner_banner_title = single_cat_title( '', false );
}else 
if( is_author() ) {
 $inner_banner_title =   get_the_author();
} else 
if( is_single() ) {
$inner_banner_title =  get_the_title();
$inner_banner_title2 = get_option('page_for_posts', true);
} else
if( is_archive() ) {
$inner_banner_title =  strtoupper(get_the_date('F-Y'));
} else {
$inner_banner_title = get_the_title( get_option('page_for_posts', true) );
}
}
?>

 <div class="banner inner-banner"<?php if($gaming['inner_banner_image_upload']['url']!=''){ ?> style="background:url(<?php echo $gaming['inner_banner_image_upload']['url'];?>) no-repeat;"<?php } ?> >
 <div class="container">
  <div class="row">
   <div class="col-md-12 col-sm-12 col-xs-12">
     <div class="inner-bannner-overlay">
      <img src="https://streamerthings.com/wp-content/uploads/2018/09/inner-page-image-3-1.jpg" alt="">
      <div class="inner-banner-text">
      <h1 class="inner-banner-title" style="visibility:visible; animation-name:fadeInRight;"><?php the_title();?></h1>
     </div><!--inner-banner-overlay-->
     </div><!--banner-text-->
   </div><!--col-md-12 col-sm-12 col-xs-12-->
  </div><!--row-->
 </div><!--container-->   
</div><!--banner-->
  • Could you add the banner image url (and link?) as a custom field, and then update them for each page? You could then edit your template file to look for that custom field, and echo it if found. You could set a default banner url if a specific one doesn't exist for the page / post. – Martin Jarvis Sep 7 '18 at 15:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.