Icon before article title
AnsweredHi everyone!
I always seem to have a lot of questions. Maybe one day I can actually help someone else out!
We would like to add an icon before certain articles that show that an article is about a new feature or is updated. We can do that with text or adding an emoji, but I would like to use some of our branding instead. This would require a way to add a jpg, png, etc to the front of an article title. How can I do this?
See the icon on Twitter below. Thanks!
-
Hey Lisa :),
First, you need to add that image in the assets on the HC. See twitter.jpg image.
If you want to add icon or image (jpg, png, etc) to the front of the article title on article_page.hbs then add that icon or image to the front of article title code.
See line no. 38 :
See, the twitter image is added to the front of an article title.
If you need to add the different-different icons or images for every article title then follow this article. https://support.zendesk.com/hc/en-us/community/posts/360038804574-Sort-Articles-by-Label
OR
If you want to add icons or images to the front of the article list then same thing you can do on other pages e.g (section page, category page, etc.) add the image or icon to the front of {{title}}.
category page, see line no. 42
Section page, see line no. 46
If any query let me know.
Thank You
Team
-
Thanks!
I wanted something for different articles. So I figured it out using this code and another. This is what I have in category_page:
{{#if section.articles}}
<ul class="article-list">
{{#each section.articles}}
<li class="article-list-item {{#if promoted}} article-promoted{{/if}}">
{{#if promoted}}
<span data-title="{{t 'promoted'}}" class="icon-star"></span>
{{/if}}{{#is id 360038868131}} <img src="{{asset 'updatebutton50x21.png'}} "/>{{/is}}
For others, that number is a link to the article number.
I then added it to the section_page as well.
I then get this:
So now my next question is, how do I get that image to show up BEHIND the text. I am trying some CSS stuff to see what I can do, but any help is appreciated.
-
Hey Lisa,
You need to add code after the article title. Please see the given image line no. 45 to 50.
Result:
Twitter image is added behind the text.
This is on section template but same thing would be done on category page for showing the image behind the article text.
Add article IDs with images after {{title}} tag.
You can do this by CSS code using ::after or ::before.
If any issue let me know :)
Thank You
Team
-
That did it!
Thank you so much!
-
:D Enjoy
-
I have hit a new snag. I have some articles that link directly to an outside site - like Terms of Use links to the external page so I don't have to change the text all the time. That is interfering with the code above. Not sure how to fix. Here is the code and then what it looks like. It doubles the title.
<a href="{{url}}" class="article-list-link">
{{title}}
{{#is id 360038484732}} <img src="{{asset 'NewButton.png'}} "/>{{/is}}
{{#is id 360038868131}} <img src="{{asset 'updatebutton.png'}} "/>{{/is}} </a>
<a href="{{url}}" class="article-list-link"><a {{#is id 360039251672}} href="https://voice.com/legal/terms-of-use/" class="article-link" {{/is}}
href="{{url}}" class="article-link">{{title}}</a>
-
Hey Lisa,
You need to add this code in your script file after the document ready function:
$('a[href*="360038927171"]').attr('href','https://voice.com/legal/terms-of-use/');
$('a[href*="360039825452"]').attr('href','https://voice.com/legal/terms-of-use/');
$('a[href*="360038927151"]').attr('href','https://voice.com/legal/terms-of-use/');You just need to update IDs of articles here:
('a[href*="360038927171"]') //Update the article ID
Here add your external links:
('href','https://voice.com/legal/terms-of-use/') // Update the link
No need to add code for outside links on hbs template. Just paste that given code on your script file and update your article IDs and external links.
If any issue let me know :)
Thank You
Team
-
I am sending you virtual Girl Scout cookies! Thank you so much!
-
:)
-
What steps can I follow if I want to add an image before an article title that is just a normal article (not promoted or featured)?
Thanks!
-
Hi Lucy -
The solutions above should work whether the articles have been featured/promoted or not. I don't see anything in the solution that indicates you have to feature or promote the article in order to use this code to insert an icon.
-
Hi Lucy,
Nicole is right.
You just need to
upload image in the assets in hc
add image before {{title}} on article page
no need to check ID, promoted,featured and all
save and publish
It's doneIf any other query feel free to ask :)
Thank You
-
Thank you! So if I want to choose which articles I want to display the icon, then I will need to supply the article ID?
-
Is it possible to add icons to the search_results.hbs template? Specifically, I'm looking to add the lock fas icon to search results that are set to "internal."
-
Hi Danny,
Go to your search_results.hbs file.
Find for 'results-list-item-link'
Add the given code before the '{{title}}'
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" focusable="false" viewBox="0 0 16 16"
class="icon-lock {{#if is_external}} hide {{/if}}" title="{{t 'internal'}}">
<rect width="12" height="9" x="2" y="7" fill="currentColor" rx="1" ry="1"/>
<path fill="none" stroke="currentColor" d="M4.5 7.5V4a3.5 3.5 0 017 0v3.5"/>
</svg>
Screenshot for the same: -
Hi Ifra, thanks very much for the response.
I receive an error when using is_external - I'm guessing this may be because we are using a v1.0 API guide theme. Do you know if that might be the issue? If so, is there a way to reference internal/external articles in the search_results template using v1.0 API?
-
Danny Koss, I tried in V1 theme and it's not possible from my side.
Please sign in to leave a comment.
18 Comments