1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How To Setup "Master Forums" AKA "All Topic"

Discussion in 'Styling and Customization Questions' started by BirdOPrey5, May 30, 2012.

  1. BirdOPrey5

    BirdOPrey5 Well-Known Member

    I have been receiving multiple requests on how to make "Master Forums" on XenForo. I have a vB mod that basically allows you to show the threads from multiple forums in a "Master" Forum. When you click on a thread title it will take you to the thread in its native forum, so you may want to set up some sort of quick link back to your Master Forum- that is not part of this tweak though.

    Unfortunately it does not look like I will have time anytime soon to figure out how the XF mod system works and publish this as an actual modification.

    However it is not too difficult a file edit- I have it working on my test forum and on DRE's (ethos?) forum it works well too.

    The file in question is Thread.php in /library/XenForo/Model/

    Based on the XF 1.1 code you need to edit the function prepareThreadConditions

    Find the code:

    PHP:
            if (!empty($conditions['node_id']))
            {
                if (
    is_array($conditions['node_id']))
                {
                    
    $sqlConditions[] = 'thread.node_id IN (' $db->quote($conditions['node_id']) . ')';
                }
                else
               {
                    
    $sqlConditions[] = 'thread.node_id = ' $db->quote($conditions['node_id']);
                }
            }
    Edit it to something like:

    PHP:
     //All Topic Edit by BOP5
            
    if (!empty($conditions['node_id']))
            {
                if (
    is_array($conditions['node_id']))
                {
                    
    $sqlConditions[] = 'thread.node_id IN (' $db->quote($conditions['node_id']) . ')';
                }
                else
                {
                
    //All topic mod manual edit by BOP5
                
    if ($conditions['node_id'] == 3)
                  
    $sqlConditions[] = 'thread.node_id IN (3, 4, 5, 11, 15, 17, 18)';
                else
                    
    $sqlConditions[] = 'thread.node_id = ' $db->quote($conditions['node_id']);
                }
            }
    That edit will make Forum ID 3 into a "Master Forum" it will show ALL Threads for the forums with ids 3, 4, 5, 11, 15, 17, and 18. Do not forget to list the Master Forum itself in your list.

    If you truly want EVERY thread then you can stop here.

    If you want multiple Master Forums you simply need to add elseif statements for additional master forums, example:

    Code:
    //All Topic Edit by BOP5
            if (!empty($conditions['node_id']))
            {
                if (is_array($conditions['node_id']))
                {
                    $sqlConditions[] = 'thread.node_id IN (' . $db->quote($conditions['node_id']) . ')';
                }
                else
                {
                //All topic mod manual edit by BOP5
                if ($conditions['node_id'] == 3)
                  $sqlConditions[] = 'thread.node_id IN (3, 4, 5, 11, 15, 17, 18)';
               elseif ($conditions['node_id'] == 6) 
                  $sqlConditions[] = 'thread.node_id IN (6, 7, 8, 9)';
                else
                    $sqlConditions[] = 'thread.node_id = ' . $db->quote($conditions['node_id']);
                }
            }
    Now that would make Forum ID 6 also it's own "Master Forum" and show ALL threads from forums 6, 7, 8, and 9.

    And again if you want ALL threads (including sticky threads) you can stop here.

    However my personal choice was always to leave the sticky threads in their native forums and only show the non-sticky threads from "slave" (for lack of a better term) forums. So a Master Forum will show its own Stickies and non-sticky threads for its slave forums.

    To do this we need an additional edit, further down in the same function.

    Find:

    PHP:
            if (isset($conditions['sticky']))
            {
                
    $sqlConditions[] = 'thread.sticky = ' . ($conditions['sticky'] ? 0);
            }
    And edit it to something like:

    PHP:
            if (isset($conditions['sticky']))
            {
              
    //All topic manual edit by BOP5
              
    if ($conditions['forum_id'] == AND $conditions['sticky'] == 1)
                
    $sqlConditions[] = '(thread.sticky = 1 AND thread.node_id = 3)';
              elseif (
    $conditions['forum_id'] == AND $conditions['sticky'] == 1)
                
    $sqlConditions[] = '(thread.sticky = 1 AND thread.node_id = 6)';
              else
                  
    $sqlConditions[] = 'thread.sticky = ' . ($conditions['sticky'] ? 0);
            }
    In the above example I included the double Master Forum from above (Both 3 and 6 are Master Forums)

    If you only have one master forum delete the "elseif..." statement and the line of code directly below it.

    If you have additional master forums simply add more elseif statements.

    I hope you can follow along. I consider this public code- anyone is welcome to use it or make a mod of it, whatever you want to do.

    -Joe
     
    erich37, DRE, Cal and 2 others like this.
  2. DRE

    DRE Well-Known Member

    I have almost 100 modifications on my site and out of all of them, this is my favorite one.
     
  3. DRE

    DRE Well-Known Member

  4. DRE

    DRE Well-Known Member

    Doesn't work for me anymore. I mean it works but breaks the site.
     
  5. BirdOPrey5

    BirdOPrey5 Well-Known Member

    On 1.1.5? What exactly happens?
     
  6. DRE

    DRE Well-Known Member

    I was on 1.1.4. I'm on 1.1.5 now. I will try it again after I get off work sometime.
     
  7. BirdOPrey5

    BirdOPrey5 Well-Known Member

  8. Morgain

    Morgain Well-Known Member

    This is a bit like something I have wanted for along time. That is - virtual threads, or even virtual forums.
    Sometimes a thread does not fit neatly into a forum definition, or perhaps it does but it matches equally well with other forum sections.
    This is particularly true for our Newswatch for example where I would like to place a thread there, but also have it appear in other forums according to its topic.

    So for example an enabled author puts Thread X in Forum A.
    They can also select Forum B and C because of relevance.
    Thread X appears in all three Forums. But it only adds replies on the one root thread in Forum A.

    So the threads in Forum B and C are LinkThreads like LinkForums. But they look the same to the user as an ordinary thread, perhaps with a tiny marker to show which are LinkThreads.
     
  9. time

    time Active Member

    with xenforo 1.2 ?
     

Share This Page