Skip Navigation

[Resolved] Adding an Image and a Link to the main Categories

This thread is resolved. Here is a description of the problem and solution.

Problem:
The user is using a 3rd party plugin to add an image to each taxonomy term. He would like to build a link around the image.

Solution:
Because of how the 3rd party plugin stores the image(in options table), it must be done using custom code. Toolset does not have built-in way to query the options table.
Check the custom code here https://toolset.com/forums/topic/adding-an-image-and-a-link-to-the-main-categories/#post-2199021

This support ticket is created 3 years, 11 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 7 replies, has 2 voices.

Last updated by Brian Smith 3 years, 10 months ago.

Assisted by: Jamal.

Author
Posts
#2196923
Screen-Shot-2021-10-15-at-11.22.15-AM.jpg

Tell us what you are trying to do?
I am trying to create a way for my main categories to have an image and a URL link to go to other than the archive pages. We have it hardcoded into an HTML template as of now but want to utilize Toolset to do it.
Is there any documentation that you are following? We are using a plugin called Categories Images to allow us to create the images and links, but cannot seem to locate them within the toolset loop.

Is there a similar example that we can see?
The template that is already working as of now can be seen here: hidden link
The links for the mouthpieces and accessories have their own unique link back to a product page.

What is the link to your site?
hidden link

I have a staging site that I been working with here: hidden link

#2197515

Hello and thank you for contacting Toolset support.

I am sorry, but I don't understand what did you mean. The page that you provided as an example is a single post page. It is for the post "edmar-colon" from the custom post type "Endorser". And it seems to use a content template "Endorser template".

I can't see any relation to categories. Can you give more details? Or screenshots to help me understand this better?
Would you allow me temporary access to check this further? Your next reply will be private to let you share credentials safely.

As a side note, I am sure the "Categories Images" plugin stores the images and links in a term field, you can check them and add them to Toolset dashboard from Toolset->Settings->Front-end Content. This way, you can use them in Toolset dashboards.

#2197669

Thank you for your feedback, and for the credentials. I logged in to the staging site and you have put the taxonomy shortcode there.

Unfortunately, the taxonomy shortcode wpv-post-taxonomy is not enough to get term fields. You will need to use a taxonomy view, or develop your own custom shortcode.

With Toolset, you can create a taxonomy view, the pulls the terms from the current post. Currently, Toolset Blocks do not support taxonomy views. The view needs to be built using the legacy editor. Check this screenshot hidden link
You can edit the view here: hidden link

At this stage, I assumed that the plugin stores the image and links in a term field, but it turns out that it stores the data as site options in "options" table instead of the "termmeta" table. I installed phpMyAdmin plugin to be able to browse the database.

I searched the plugin's website and I could not find a shortcode that we could use. The plugin offers some functions to use. Like "z_taxonomy_image_url" and "z_taxonomy_image". You can build your own shortcodes to get the information using the plugin's functions.

Otherwise, I would suggest using only Toolset. But you will have to enter the data again for all the categories.
You can create a Term field group in Toolset, with an Image field, and a URL field. Then you can use them inside the view that I have created.

After that, get to the Endorser content template, and in the Fields&Text block, use the views button to select the taxonomy view.

I hope this makes sense. Let me know if you have any questions.

#2198903

Thank you Jamal,
If you could show me how to create our own shortcode, by using the plugin's functions and not having to go through and add in all the information again, that would be perfect for this situation.
" The plugin offers some functions to use. Like "z_taxonomy_image_url" and "z_taxonomy_image". You can build your own shortcodes to get the information using the plugin's functions."

#2199021

Sure. Take the following code as an example:

add_shortcode('taxonomy-image-url', 'my_taxonomy_mage_url');
function my_taxonomy_mage_url($atts, $content){
	$term_id = do_shortcode( $content );
	return z_taxonomy_image_url( $term_id );
}

And you can use this shortcode inside the loop of the taxonomy view like this:

[taxonomy-image-url][wpv-taxonomy-id][/taxonomy-image-url]

I hope this gives you an idea on how to use the plugin's functions in a shortcode. Read more about the plugin's functions here hidden link

Read more about shortcodes in general here:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/how-to-create-a-custom-shortcode/
- https://codex.wordpress.org/Shortcode_API

#2199071

Do we add the code to the child theme functions page? Or is there a place within Toolset to add in the function code?
This is the code I am using now:

<div class="endorser-mouthpiece-wrapper x-column x-sm x-2-3">
                      <?php 
                        $url = site_url(); 
                        foreach($mouthpieces as $mouthpiece) { 
                          $t_id = $mouthpiece->term_id;
                          $mouthpiece_image = z_taxonomy_image_url($t_id);
                          $cat_data = get_option("category_$t_id");

                          if ($mouthpiece_image) { 
                          echo '<div class="endorser-mouthpiece">'; 
                          if (isset($cat_data['category_mouthpiece_link'])) {
                          	if ($cat_data['category_mouthpiece_link'] == "") { 
                          		echo "<a href=\"$url/saxophone-mouthpieces/\">";   
                          	} else { 
                          		$mouthpiece_link = $cat_data['category_mouthpiece_link'];
                          		echo "<a href=\"$mouthpiece_link\">";   
                          	}
                          } 
                          echo '<div class="endorser-mouthpiece-image">';
                          z_taxonomy_image($mouthpiece->term_id);
                          echo '</div>';
                          echo '<div class="endorser-mouthpiece-name">';
                          echo '<h6>' . $mouthpiece->name . '</h6>';
                          echo '</div>';
                          echo '</a>';
                          echo '</div>';
                          }
                        }
                      ?>   
         </div>  

How can I get this into the Toolset?

#2199719
Screen Shot 2021-10-19 at 10.11.00 AM.png

Ok got the images to show thank you so very much!!! I put the shortcode into my functions page 🙂

Now I need to create another shortcode that pulls out a URL that we place on the category page as we see on the image below.
I have the code we work it with through the hard code, but can you guide me to see how I can use it in toolset as the overall URL link? I just figured it would be pulled into toolset automatically.

#2200079

My issue is resolved now. Thank you! I am gonna just follow Jamals first statement to create a new taxonomy with a new field group.