Display site icon in results?

Post Reply
munoz
Posts: 7
Joined: Fri May 27, 2016 12:44 pm

Display site icon in results?

Post by munoz »

User avatar
mark
Site Admin
Posts: 5504
Joined: Tue Apr 25, 2000 6:56 pm

Display site icon in results?

Post by mark »

The walker doesn't record site favicons. You could use XSL results style and modify the style sheet to grab the favicon directly from each site.
munoz
Posts: 7
Joined: Fri May 27, 2016 12:44 pm

Display site icon in results?

Post by munoz »

Yeah, that might be good.
Could you maybe guide me to how do do that?
A reference page or something?
User avatar
mark
Site Admin
Posts: 5504
Joined: Tue Apr 25, 2000 6:56 pm

Display site icon in results?

Post by mark »

Something like this will construct the img tag for favicon.ico:

<img height="16" width="16" alt="">
<xsl:attribute name="src">
<xsl:value-of select="substring-before(Url,'://')"/>
<xsl:text>://</xsl:text>
<xsl:choose>
<xsl:when test="substring-before(substring-after(Url, '://'),'/')=''">
<xsl:value-of select="substring-after(Url, '://')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before(substring-after(Url, '://'),'/')"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>/favicon.ico</xsl:text>
</xsl:attribute>
</img>

You'll probably want to add that somewhere in the ResultTitle template.
munoz
Posts: 7
Joined: Fri May 27, 2016 12:44 pm

Display site icon in results?

Post by munoz »

Oh thank you!!!! That works!!!

For most of the URLS, and of course I have one where the ico is not in the root.
How can I add something to address that?

The .ico is under "URL/wp-content/themes/nabsd/"

(I have never used .xsl before in my life, so all this is new to me)
User avatar
mark
Site Admin
Posts: 5504
Joined: Tue Apr 25, 2000 6:56 pm

Display site icon in results?

Post by mark »

You'd have to compare Url to your prefix and do different behavior based on match/nomatch. Something like below (untested) before <xsl:text>/favicon.ico</xsl:text>

<xsl:if test="contains(Url,'/wp-content/themes/nabsd/')">
<xsl:text>/wp-content/themes/nabsd</xsl:text>
</xsl:if>

A handy XSL reference is http://www.w3schools.com/xsl/
Post Reply