Posted in site documentation
12:10 am, June 11, 2021

hero widget header - creates a nice looking hero item from a target uid and class

this creates a "nice" looking hero widget, just wanted to create something that looked decent and had an attached background image, surprizingly annoying to link items together.

For some reason i keep just adding code to seperate pages rather than creating a single function for it, and then doing that is stuffs up some other random part of the site. I did a lazy way of loading the latest item from content and then it was not assigning the uid properly, so i changed the list function to assign uid's and then it broke half of the site assigning the wrong uid on view pages.

Anyway Lesson learned, always try and seperate things into stand alone re-usable functions or classes. 

Something like this:

Here it is with the default code background.

PHP - Usage

$content->hero_widget($t_uid = "Ud6Br",$t_class = "content");

Update: Added the category checking for default images per page type. 

Like the default if the class is content and the category for that item is rs3, it will show the following:

Update: 16 Jul 2021

I just realised you can add animated gifs as well, so they look extra .. animated. 


<div class='content-hero mb-3' style="background:linear-gradient( 155deg, rgb(1 1 1), rgb(0 0 0 / 35%) ), url([@hero_image_url]) center no-repeat;background-size:cover;">
  <div class="hero-cat mb-1">[@category]</div>
  <div class="hero-title">
    <h2><a href="[@url]">[@title]</a></h2>


.content-hero {
  border:1px solid #333;
.hero-title h2 {
  /* position:absolute;
  bottom:0px; */
.hero-cat {
  text-transform: uppercase;
  font-family: 'Montserrat', sans-serif;
.hero-title h2 a {
  text-transform: capitalize;
  text-shadow:0px 1px 2px #000;


// creates a nice looking hero item from a target uid and class.
    public function hero_widget($t_uid,$t_class) {

      $links = new links;
      $links->add_to_menu = false;

      $imgur = new imgur;
      $imgur->add_to_menu = false;

      $t_class_loaded = new $t_class;
      $t_class_loaded->add_to_menu = false;

      // load the target item
      if(!$t_class_loaded->load_from_uid($t_uid)) {
        return false; // nothing found.

      // search for a linked hero image
      $content_find_load_linked = $links->find_load_linked(
        $linked_uid = $t_uid,
        $linked_class = $t_class

      $show_home_hero_content = false;

      foreach($content_find_load_linked as $c_class => $c_uid) {
        if(is_array($c_uid)) {
          foreach($c_uid as $cc_class => $cc_uid) {
            if($cc_class == "imgur") {
              if($imgur->load_from_uid($cc_uid)) {
                // check if the hero is set as the category
                if($imgur->category == "hero") {
                  // we have found the hero image finally.
                  $show_home_hero_content = true;
                  $hero_image_url = $imgur->image_link;

      // rather than just returning blank, why not add a placeholder or default image here instead, depending on the class type.
      // code background for code items, not sure for content.
      if(!$show_home_hero_content) { // dont overwrite a linked hero image.
        if($t_class == "code") {
          // matrix style background.. ;)
          $show_home_hero_content = true;
          $hero_image_url = "";
        if($t_class == "content") {
          $show_home_hero_content = true;
          $hero_image_url = "";
        if( ($t_class == "content") && ($t_class_loaded->category == "rs3") ) { // default rs3 category background.
          $show_home_hero_content = true;
          $hero_image_url = "";

      if($show_home_hero_content) {
        //$content = new content();
        //$content->add_to_menu = false;

        $content_hero = new template("content-hero.html");
        $content_hero_html = $content_hero->output();
        return $content_hero_html;

      return false;
      // load related linked items and find an image with the hero category set.


No Items Found.

Add Comment
Type in a Nick Name here
Related Search Terms
Page Views

This page has been viewed 916 times.

Search Code
Search Code by entering your search text above.

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.


Random Quote
Our brains are wired to find things we are looking for - if your always cynical or waiting for things to go wrong, then your life will reflect that. On the other hand, having a positive outlook on life will bring you joy and provide you with inspiration when you least expect it ☀️🍉🌴