Default cover image for article thread

mcatze

Well-known member
If a have an article forum set up, there're maybe some threads without an attachment. It would be nice if there's an option to set a default cover for threads without attachments.

E.g. in the forum_view_type_article template.

Bildschirmfoto 2021-06-03 um 19.26.43.png

Maybe there is but i didn't seen it.. 🤓
 
Last edited:
Upvote 6

Kevin

Well-known member
I suggested to default to the metadata logo for the article image since everybody is likely to have that already set anyway.

 

mcatze

Well-known member
Thats not what i mean. I want a default image as cover in the forum_view_type_article if there is no attachment.
 
Last edited:

woody

Well-known member
Even better, I'd like to see an option to set that image based on forumname.01, forumname.02, etc.
 

Kevin

Well-known member
Even better, I'd like to see an option to set that image based on forumname.01, forumname.02, etc.
Yeah, having default images set at the node (forum) would be nice.
Thats not what i mean. I want an default image as cover in the thread view if there is no attachment.
Whoops, I thought you meant forum view listing (what my suggestion covers) but see now you are talking specifically thread view while viewing the article. 👍
 

Kevin

Well-known member
In my case, I use the Article layout for Classifieds, and the desktop view is a mess when there is no default.

Same thing I'm doing as well which led to that suggestion thread. I did a edit to use the metadata logo for threads that don't have an image in the first post. It was driving me nuts viewing the listing when there were no images.

 

mcatze

Well-known member
Whoops, I thought you meant forum view listing (what my suggestion covers) but see now you are talking specifically thread view while viewing the article. 👍
No, i wasn't correct. I mean the forum_view_type_article, the listing of all threads.
 

mcatze

Well-known member
After your edit with the screenshots... We're back to my first response. 😁
Not exactly. I don't want the metadata logo. I want an option in acp for a forum with article thread type where i can set/upload a default cover image that will shown if no attachment is uploaded to the thread.
 

Brogan

XenForo moderator
Staff member
It can be achieved with a simple template edit.

Edit the post_article_macros template.

Look for:
HTML:
<xf:if is="$thread.cover_image">
    <a href="{$linkUnread}" class="articlePreview-image" style="background-image: url('{$thread.cover_image}')" aria-hidden="true" tabindex="-1">&nbsp;</a>
</xf:if>

Replace with:
HTML:
<xf:if is="$thread.cover_image">
    <a href="{$linkUnread}" class="articlePreview-image" style="background-image: url('{$thread.cover_image}')" aria-hidden="true" tabindex="-1">&nbsp;</a>
<xf:else />
    <a href="{$linkUnread}" class="articlePreview-image" style="background-image: url('{{ {$xf.options.boardUrl}.'/styles/default/xenforo/xenforo-icon-large.png' }}')" aria-hidden="true" tabindex="-1">&nbsp;</a>
</xf:if>

You can then expand that as required to use conditional statements related to node IDs with a fallback to the generic icon:
HTML:
<xf:if is="$thread.cover_image">
    <a href="{$linkUnread}" class="articlePreview-image" style="background-image: url('{$thread.cover_image}')" aria-hidden="true" tabindex="-1">&nbsp;</a>
<xf:elseif is="$forum.node_id == 2" />
    <a href="{$linkUnread}" class="articlePreview-image" style="background-image: url('{{ {$xf.options.boardUrl}.'/styles/default/xenforo/node-2-icon.png' }}')" aria-hidden="true" tabindex="-1">&nbsp;</a>
<xf:elseif is="$forum.node_id == 8" />
    <a href="{$linkUnread}" class="articlePreview-image" style="background-image: url('{{ {$xf.options.boardUrl}.'/styles/default/xenforo/node-8-icon.png' }}')" aria-hidden="true" tabindex="-1">&nbsp;</a>
<xf:else />
    <a href="{$linkUnread}" class="articlePreview-image" style="background-image: url('{{ {$xf.options.boardUrl}.'/styles/default/xenforo/xenforo-icon-large.png' }}')" aria-hidden="true" tabindex="-1">&nbsp;</a>
</xf:if>
 
Top