Skip Navigation

[Resolved] Show the main category name/title pull image as background

This support ticket is created 4 years, 5 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Author
Posts
#1855609
category image.jpg
banner image.jpg
Category layout.jpg
Top header issue.jpg

1 ----------

hidden link - this is the category page and you will see it has the top header (attached image Top header issue).

I need the the top one one to pull through the main category name its just pulls through the parent - Arts and Craft (see attached "Category layout")

the shortcode i am using on the toolset is [wpv-archive-title] I just need the shortcode that shows the main category please.

2 ----------

In the categories i have added a image field (see attached banner image)

Is there a way to set that image as the background image of "Cover" section on the archive template page (see attached category image)

-----------------------

#1855709

Hi, please keep in mind this is a public forum. For your security, I have removed the login information from this post. If you would like to share private information in the future, a supporter can open private reply fields so the information is not shared publicly.

I need the the top one one to pull through the main category name its just pulls through the parent - Arts and Craft (see attached "Category layout")...the shortcode i am using on the toolset is [wpv-archive-title] I just need the shortcode that shows the main category please.
If you want to display the title of the current archive term (i.e. on /categories/arts-and-crafts/frame-maker/ you want to display "Frame Maker"), you can use the shortcode wpv-taxonomy-title: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-taxonomy-title
If you want to display the title of the current archive term's parent, that is a bit different. Unfortunately there is no Toolset shortcode available to get the title of the current archive term's parent term. Instead, I have a custom shortcode you can use to get that parent term name. This code can be added in your child theme's functions.php file, or to a new custom code snippet in Toolset > Settings > Custom Code:

function get_term_parent_func($atts) {
  $a = shortcode_atts( array(
      'taxonomy' => '',
      'return' => 'title'
  ), $atts );
  $taxonomy = $a['taxonomy'];
  $parent_id = 0;
  if( is_tax( $taxonomy ) ) {
    $taxObj = get_queried_object();
    $tax = isset($taxObj->taxonomy) ? $taxObj->taxonomy : 0;
    $term = isset($taxObj->term_id) ? $taxObj->term_id : 0;
    $parent_slug = get_term_parents_list( $term, $tax, array('format'=>'slug', 'link'=>FALSE, 'inclusive'=>FALSE, 'separator'=>''));
    if( $a['return'] == 'id' ) {
      $parent = get_term_by( 'slug', $parent_slug, $tax );
      $parent_id = isset($parent->term_id) ? $parent->term_id : $taxObj->term_id;
      return $parent_id;
    }

    if( $a['return'] == 'slug' ) {
      return $parent_slug;
    }

    if( $a['return'] == 'title' ) {
      $parent = get_term_by( 'slug', $parent_slug, $tax );
      $parent_title = isset($parent->name) ? $parent->name : $taxObj->name;
      return $parent_title;
    }
  }
  return $parent_id;
}

If no parent term exists, the code will display the current archive term title. If you would like something else displayed when no parent term exists in the current archive, please explain.

After you add the code above, you can display the parent term title using the custom shortcode in your archive design like this:

[get_term_parent taxonomy='your-taxonomy-slug' return='title'][/get_term_parent]

Replace your-taxonomy-slug with the slug of the categories taxonomy. You can find the taxonomy slug in Toolset > Taxonomies when you edit the categories taxonomy.

Let me know if I've misunderstood what you want to accomplish.

#1856461
Shortcode.jpg
Mainpage.jpg
Functions.jpg

Hello,

thanks for getting back to me.

So i have added the code into the functions (see attached "Functions")

hidden link - But it only shows the shortcode and not the title (see attached "Mainpage")

I went into Toolset > Taxonomies and got the slug from this page - hidden link

my short code is - [get_term_parent taxonomy='categories' return='title'][/get_term_parent] - (See attached "Shortcode")

thanks so much

#1856669

Oh it looks like I made a copy + paste error when I included the custom shortcode in my previous reply. There should be one more line of code to initialize the shortcode:

add_shortcode("get_term_parent", "get_term_parent_func");

Please add this to the end of your functions.php file and test again.

#1856799

Thanks so much that works now! perfect.

did you get a chance to look at point 2 that i sent, image are above in the first post 🙂

2 ----------

In the categories i have added a image field (see attached banner image)

Is there a way to set that image as the background image of "Cover" section on the archive template page (see attached category image)

-----------------------

New threads created by Christian Cox and linked to this one are listed below:

https://toolset.com/forums/topic/use-taxonomy-custom-image-field-as-background-in-taxonomy-archive/

#1856825

I've split that question into a separate ticket to help keep things organized. I will follow up in the new ticket shortly.