New Post Button in Post

New Post Button in Post

MrGibbs

Member
MrGibbs submitted a new resource:

New Post Button in Post - New Post Button in XenForo 2 Post

ACP --> Template --> thread_view and find:

Code:
<xf:breadcrumb source="$forum.getBreadcrumbs()" />

Include this code below:

Code:
<xf:breadcrumb source="$forum.getBreadcrumbs()" />
<xf:pageaction if="$forum.canCreateThread()">
    <xf:button href="{{ link('forums/post-thread', $forum) }}" class="button--cta" icon="write">
        {{ phrase('post_thread') }}
    </xf:button>
</xf:pageaction>




View attachment 165367

Read more about this resource...
 
This will add a "reply" button next to the newthread button.

Go to: ACP --> Template --> thread_view and find:
<xf:breadcrumb source="$forum.getBreadcrumbs()" />

Add this code directly below that line:

PHP:
<xf:pageaction>
    <xf:if is="$xf.visitor.canCreateThread()">
        <xf:button href="{{ link('forums/create-thread', $forum) }}" class="button--primary" icon="write" overlay="true" rel="nofollow">
            {{ phrase('post_thread') }}
        </xf:button>
    </xf:if>
    <xf:if is="$thread.canReply()">
        <xf:button href="{{ link('threads/reply', $thread) }}" data-xf-click="overlay" class="button--primary" icon="reply">
            {{ phrase('post_reply') }}
        </xf:button>
    </xf:if>
</xf:pageaction>

This code checks if the visitor can create a thread in the current forum ($forum) and displays the "Post Thread" button. Additionally, if the visitor can reply to the current thread ($thread), it shows the "Reply to Thread" button.
 

Attachments

  • Screenshot (121).webp
    Screenshot (121).webp
    62.1 KB · Views: 11
Here is a modified Amp Html friendly version. What this does is the same as my last post but removes the "if is" checks. Both buttons now have nofollow attributes... Because robots do not need to waste resources trying to access these.


PHP:
<xf:pageaction>
    <xf:button href="{{ link('forums/create-thread', $forum) }}" class="button--primary" icon="write" overlay="true" rel="nofollow">
        {{ phrase('post_thread') }}
    </xf:button>
    <xf:button href="{{ link('threads/reply', $thread) }}" data-xf-click="overlay" class="button--primary" icon="reply" rel="nofollow">
        {{ phrase('post_reply') }}
    </xf:button>
</xf:pageaction>
 
Last edited:
Here is a modified Amp Html friendly version. What this does is the same as my last post but removes the "if is" checks. Both buttons now have nofollow attributes... Because robots do not need to waste resources trying to access these.


PHP:
<xf:pageaction>
    <xf:button href="{{ link('forums/create-thread', $forum) }}" class="button--primary" icon="write" overlay="true" rel="nofollow">
        {{ phrase('post_thread') }}
    </xf:button>
    <xf:button href="{{ link('threads/reply', $thread) }}" data-xf-click="overlay" class="button--primary" icon="reply" rel="nofollow">
        {{ phrase('post_reply') }}
    </xf:button>
</xf:pageaction>

What if the thread really set to not allow replies?
 
Hi, it will honor the settings that you have for user groups & forums. If not allowed it will send them the appropriate error message
 
Last edited:
Well that's just a quick edit that I whipped up for my personal use but I can edit it to add in user groups when I get back home for you. After a bit of troubleshooting tonight I came up with this which will hide the buttons for guests. I am still having trouble adding usergroup & forum permission checks to hide it when wanted.
 
Last edited:
You can use this to show it members of certain usergroups. Simply edit the "in_array" below to add usergroups to it.


PHP:
<xf:if is="{$xf.visitor.user_id} AND in_array({$xf.visitor.user_group_id}, [2, 3, 18, 4, 5])">
    <xf:pageaction>
        <xf:button href="{{ link('forums/create-thread', $forum) }}" class="button--primary" icon="write" overlay="true" rel="nofollow">
            {{ phrase('post_thread') }}
        </xf:button>
        <xf:button href="{{ link('threads/reply', $thread) }}" data-xf-click="overlay" class="button--primary" icon="reply" rel="nofollow">
            {{ phrase('post_reply') }}
        </xf:button>
    </xf:pageaction>
</xf:if>
 
Back
Top Bottom