Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3691358
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:08:20+00:00 2026-05-19T04:08:20+00:00

I have a Drupal site that needs to display a unique header image based

  • 0

I have a Drupal site that needs to display a unique header image based on the path. I have found some helpful code. It gets me close to where I need to be, but not all the way. I have pasted it at the end of this post.

The issue I am having is that it bases the banner image off of the characters after the first “/” after example.com in the URL. For example, example.com/forum returns a banner of header-FORUM.png.

I need it to work a little differently. I would like it to base the banner returned off the characters after the second “/” after example.com in the URL. For example, example.com/category/term should return a banner of header-TERM.png.

Any help that you can offer with this is much appreciated.

Here’s the code I mentioned earlier via AdaptiveThemes (FYI, there is a comment on that page that attempts to solve a similar issue to mine but I can’t get it to work).

    <?php
// Return a file based on the URL alias, else return a default file
function unique_section_header() {
  $path = drupal_get_path_alias($_GET['q']);
  list($sections, ) = explode('/', $path, 2);
  $section = safe_string($sections);
  $filepath = path_to_theme() . '/images/sections/header-' . $section .'.png';
  if (file_exists($filepath)) {
    $output = $filepath;
  }
  else {
    $output = path_to_theme() . '/images/sections/header-default.png';
  }
  return $output;
}

//Make a string safe
function safe_string($string) {
  $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
  return $string;
}
?>

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:08:21+00:00Added an answer on May 19, 2026 at 4:08 am

    Not exactly sure what the output of drupal_get_path_alias is, but try this:

    <?php
    // Return a file based on the URL alias, else return a default file
    function unique_section_header() {
      $path = drupal_get_path_alias($_GET['q']);
      $pathSegments = explode('/', $path, 3);
      $section = safe_string($pathSegments[2]);
      $filepath = path_to_theme() . '/images/sections/header-' . $section .'.png';
      if (file_exists($filepath)) {
        $output = $filepath;
      }
      else {
        $output = path_to_theme() . '/images/sections/header-default.png';
      }
      return $filepath;//$output;
    }
    
    //Make a string safe
    function safe_string($string) {
      $string = strtolower(preg_replace('/[^a-zA-Z0-9_-]+/', '-', $string));
      return $string;
    }
    

    The only changes made were to the usage of explode. explode will separate the path based on the /, so you just need to access a different element in that array. The last parameter of explode is the maximum number of elements to be returned and may also need to be tweaked

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Flash application that is hosted from within a Drupal page. Some
I have Drupal 5 site where a button is clicked and it calls a
I am finishing up a Drupal site and I have attached a word document
I have a Drupal module page where I am populating a form with a
I want to accomplish the following scenario in Drupal: You have 2 content-types. Lets
I need a very quick fix in a mod_rewrite expression for drupal we have
I have the occasion to produce Drupal web sites using development, staging, and production
Have just started using Google Chrome , and noticed in parts of our site,
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have you ever seen any of there error messages? -- SQL Server 2000 Could

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.