Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
Stephan Schmied Posted March 10, 2023 Posted March 10, 2023 I've been trying for some time to implement the following and unfortunately just do not get on. There is simply a lack of skills 😉 {{if !isset( \IPS\Output::i()->metaTags['og:image'] )}}    {{$shareLogos = \IPS\Settings::i()->icons_sharer_logo ? json_decode( \IPS\Settings::i()->icons_sharer_logo, true ) : array();}}    {{foreach $shareLogos as $logo}}       <meta property="og:image" content="{file="$logo" extension="core_Icons" scheme="full"}">    {{endforeach}}  MISSING HERE elseif - it's a forum post, then it is <meta property="og:image" content="https://www.domain.tld/img/<<TOPICID>>.jpg" />  {{else}} <meta property="og:image" content="https://www.domain.tld/standardimage.jpg" /> {{endif}}  would be cool if someone here ne line for me 🙂 Thanks a lot! Stephan
Adriano Faria Posted March 10, 2023 Posted March 10, 2023 Not sure what you want. Either use {{elseif !$something}} or identify a forum post.
Stephan Schmied Posted March 10, 2023 Author Posted March 10, 2023 Hi, thanks for your reply. the code should make a difference if the og:image is set > output (works) == MISSING == elseif it is a forum post > output should be this including the postID<meta property="og:image" content="https://www.domain.tld/img/<<TOPICID>>.jpg" /> == /MISSING ==else og:image is standard (works)
Nathan Explosion Posted March 10, 2023 Posted March 10, 2023 I think this is what you are asking for... {{if !isset( \IPS\Output::i()->metaTags['og:image'] )}} {{$shareLogos = \IPS\Settings::i()->icons_sharer_logo ? json_decode( \IPS\Settings::i()->icons_sharer_logo, true ) : array();}} {{if request.app ==='forums' AND request.controller==='topic'}} <meta property="og:image" content="https://www.domain.tld/img/{expression='request.id'}.jpg" /> {{else}} {{foreach $shareLogos as $logo}} <meta property="og:image" content="{file="$logo" extension="core_Icons" scheme="full"}"> {{endforeach}} {{endif}} {{endif}} Â Stephan Schmied and Daniel F 2
Daniel F Posted March 10, 2023 Posted March 10, 2023 This would be the code but I'm not sure what you mean with postID. There's no separate page with a post, only topics, so I assumed you mean the topic id which I used in my code. {{if !isset( \IPS\Output::i()->metaTags['og:image'] )}} {{$shareLogos = \IPS\Settings::i()->icons_sharer_logo ? json_decode( \IPS\Settings::i()->icons_sharer_logo, true ) : array();}} {{foreach $shareLogos as $logo}} <meta property="og:image" content="{file="$logo" extension="core_Icons" scheme="full"}"> {{endforeach}} {{elseif \IPS\Request::i()->app == 'forums' AND \IPS\Request::i()->controller == 'topic'}} {{$id = \IPS\Request::i()->id;}} <meta property='og:image' content='https://www.domain.tld/img/{$id}.jpg'/> {{else}} <meta property='og:image' content='https://www.domain.tld/standardimage.jpg'/> {{endif}} Â That said, I'm also not sure if it will work at all, the condition looks weird and will probably always return the first part for topics. Â Â Stephan Schmied 1
Stephan Schmied Posted March 10, 2023 Author Posted March 10, 2023 14 minutes ago, Nathan Explosion said: I think this is what you are asking for... {{if !isset( \IPS\Output::i()->metaTags['og:image'] )}} {{$shareLogos = \IPS\Settings::i()->icons_sharer_logo ? json_decode( \IPS\Settings::i()->icons_sharer_logo, true ) : array();}} {{if request.app ==='forums' AND request.controller==='topic'}} <meta property="og:image" content="https://www.domain.tld/img/{expression='request.id'}.jpg" /> {{else}} {{foreach $shareLogos as $logo}} <meta property="og:image" content="{file="$logo" extension="core_Icons" scheme="full"}"> {{endforeach}} {{endif}} {{endif}} Â Thanks so much - nearly perfect. There is only one thing missing - if neigher the og: image is set, nor its a forum topic the std-image should be postet
Nathan Explosion Posted March 10, 2023 Posted March 10, 2023 (edited) I see no reason for that, to be honest. Just upload your "std-image" in the ACP (Default share images) and it handles that element of your request... Â Edited March 10, 2023 by Nathan Explosion Stephan Schmied 1
Stephan Schmied Posted March 10, 2023 Author Posted March 10, 2023 Yeah, thanks! - Works! Thanks a lot and have a nice weekend 🙂 Â
Recommended Posts