1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum is for release discussion only. Discussions that do not relate specifically to the resource release should be discussed in another, more appropriate forum.
    Dismiss Notice
  3. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

How To Add A Sidebar To Any Forum Page

Discussion in 'Template Modifications [Archive]' started by Jake Bunce, Nov 10, 2010.

  1. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    This guide is for adding a sidebar to any forum page. It will be like the one that is already on the index page:

    Screen shot 2010-11-10 at 10.01.40 AM.png

    The first question is, on what page do you want to display the sidebar? Then you need to find the root template for that page. See this guide for help finding the root template of a page.

    For example, thread_view is the root template for all thread pages. If we want to add a sidebar to that page then edit this template:

    Admin CP -> Appearance -> Templates -> thread_view

    Then add this code to the bottom of the template:

    Code:
    <xen:sidebar>
    
    </xen:sidebar>
    
    That will create an empty sidebar that contains only the user block (which is part of the default sidebar). Then you can add your own content to the sidebar by inserting your code between those sidebar tags.

    To add formatted content blocks to the sidebar like those seen on the index page (see above picture) you can add code like this:

    Code:
    <xen:sidebar>
    	<div class="section">
    		<div class="secondaryContent">
    			YOUR CONTENT HERE
    		</div>
    	</div>
    </xen:sidebar>
    
    You can add multiple instances of that code if you want to create multiple content blocks:

    Code:
    <xen:sidebar>
    	<div class="section">
    		<div class="secondaryContent">
    			YOUR CONTENT HERE
    		</div>
    	</div>
    
    	<div class="section">
    		<div class="secondaryContent">
    			EVEN MORE CONTENT HERE
    		</div>
    	</div>
    </xen:sidebar>
    
    If you want to add the same sidebar content to multiple pages then you can put that content into a new template:

    Admin CP -> Appearance -> Templates -> Create New Template

    Give the template a name (e.g. my_sidebar_content). Then to call on that template you would use code like this when editing the root template:

    Code:
    <xen:sidebar>
    	<xen:include template="my_sidebar_content" />
    </xen:sidebar>
    
    There are different ways to organize the sidebar code using templates, but this gives you the general idea. The only other thing I would note is that the user block that is contained in the sidebar by default is contained within this template:

    Admin CP -> Appearance -> Templates -> sidebar_visitor_panel

    So, for example, if you don't want that user block to appear in your custom sidebar, but you still want it to appear on the index page, then you can cut that code from sidebar_visitor_panel and paste it into forum_list between its sidebar tags.
     
    maszd, Webby, popowich and 10 others like this.
  2. simbolo

    simbolo Well-Known Member

    Cool Jake, Thanks for the info.
     
  3. Nenad Plavsic

    Nenad Plavsic New Member

    What is the code to have all the side bar elements from the home page appear on all of the pages?

    Thanks.
     
  4. Brogan

    Brogan XenForo Moderator Staff Member

    This is the relevant code from the forum_list template:

    HTML:
    <xen:sidebar>
    
        <xen:edithint template="sidebar.css" />
    
        <xen:include template="sidebar_online_users" />
    
        <div class="section">
            <div class="secondaryContent statsList" id="boardStats">
                <h3>{xen:phrase forum_statistics}</h3>
                <div class="pairsJustified">
                    <dl class="discussionCount"><dt>{xen:phrase discussions}:</dt>
                        <dd>{xen:number $boardTotals.discussions}</dd></dl>
                    <dl class="messageCount"><dt>{xen:phrase messages}:</dt>
                        <dd>{xen:number $boardTotals.messages}</dd></dl>
                    <dl class="memberCount"><dt>{xen:phrase members}:</dt>
                        <dd>{xen:number $boardTotals.users}</dd></dl>
                    <dl><dt>{xen:phrase latest_member}:</dt>
                        <dd><a href="{xen:link members, $boardTotals.latestUser}" class="username">{$boardTotals.latestUser.username}</a></dd></dl>
                </div>
            </div>
        </div>
    
    </xen:sidebar>
     
  5. Nenad Plavsic

    Nenad Plavsic New Member

    Perfect, thank you!
     
  6. Nenad Plavsic

    Nenad Plavsic New Member

    Sorry, one last question. I try the code above and place it in thread_list. The side bar shows all except "Staff Online Now". How do I bring that module over too?

    Thanks
     
  7. Brogan

    Brogan XenForo Moderator Staff Member

    The Staff Online is in the sidebar_online_users template and is this code:

    HTML:
    <xen:if hascontent="true">
        <div class="section staffOnline avatarList">
            <div class="secondaryContent">
                <h3>{xen:phrase staff_online_now}</h3>
                <ul>
                    <xen:contentcheck>
                        <xen:foreach loop="$onlineUsers.records" value="$user">
                            <xen:if is="{$user.is_moderator} OR {$user.is_admin}">
                                <li>
                                    <xen:avatar user="$user" size="s" img="true" />
                                    <a href="{xen:link members, $user}" class="username">{xen:helper richUserName, $user}</a>
                                    <div class="userTitle">{xen:helper userTitle, $user}</div>
                                </li>
                            </xen:if>
                        </xen:foreach>
                    </xen:contentcheck>
                </ul>
            </div>
        </div>
    </xen:if>
    However, there's an IF statement related to "hascontent=true" so that is probably why it isn't showing up on your template.
    I haven't tried it myself, I'm just guessing based on the code.
     
  8. Nenad Plavsic

    Nenad Plavsic New Member

  9. TNCclubman

    TNCclubman Well-Known Member

    quick question. If I add this, do i have to keep doing it everytime i upgrade?
     
  10. Axmant Brahaj

    Axmant Brahaj Member

    Most probably, yes! I had to update some templates we changed.

    What is the fastest way to include some RSS Feed in the Sidebar?
     
  11. Brogan

    Brogan XenForo Moderator Staff Member

  12. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    Not usually.

    Template modifications like this are preserved during the upgrade. Sometimes custom templates are incompatible with new versions, but that generally only happens with major upgrades, not with regular point releases.
     
  13. qak01ok

    qak01ok New Member

    If I want to add a sidebar with the newest members and the highest-posting members on the main page what would that code look like?
     
    erich37 likes this.
  14. Brogan

    Brogan XenForo Moderator Staff Member

    You would need an add-on for that as that data is not available on the main forum page.

    Look in the add-on releases forum, there are a few add-ons which do that.
     
  15. qak01ok

    qak01ok New Member

    What about adding the Forums Top Posters or the Most Liked Members on the main page is this possible?
     
  16. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    That also requires an addon to fetch the information.

    If you are a programmer then you can post in the Development Questions forum for help with this. Or post an Add-on Request and some one may be able to write this for you.
     
  17. qak01ok

    qak01ok New Member

    Brogan I'm confused let me ask my question a different way. If I go to my "Members Page" that list all of the members for my site, I see a side bar on the right hand side of the page showing the "Newest Members" and the "Highest Posing Members" being displayed. How can I get these two sidebars displayed on the Forums Main Page (index.php) ?
     
  18. Brogan

    Brogan XenForo Moderator Staff Member

    You can't, as I explained above.

    That data is not exposed for the forum home, it requires an add-on.
     
  19. qak01ok

    qak01ok New Member

  20. Brogan

    Brogan XenForo Moderator Staff Member

    Yes.

    Or you can check the add-on releases forum to see if someone has already created an add-on which does what you want.
     

Share This Page