title: Getting Sitecore Siblings From Another Branch
body: <p>We have a data structure in sitecore that features the same templates at the same 'depth'. We are making classroom content that features units, lessons, and activities in the following structure:</p>
  
  <pre><code>Unit 1
  -- Lesson 1
  ---- Activity 1
  ---- Activity 2
  -- Lesson 2
  ---- Activity 3
  ---- Activity 4
  Unit 2
  -- Lesson 3
  ---- Activity 5
  ---- Activity 6
  -- Lesson 4
  ---- Activity 7
  ---- Activity 8
  </code></pre>
  
  <p>and so on. When I am on an <code>activity</code> item, I want to return the next <code>activity</code> item in that particular <code>unit</code>, and return null if there are no more activities in that unit. </p>
  
  <p>The best I have been able to do so far is to target the current activities <code>unit</code> ancestor (easily found) and get all <code>activities</code> that are under it, then loop through all of them to get prev/next activities. It seems like there must be a better way to accomplish this, so I thought I'd throw it out here for ideas.</p>
  
  <p><strong>Current Code</strong></p>
  
  <pre><code>Item unit = Sitecore.Context.Item.Axes.SelectSingleItem("ancestor-or-self::*[@@templatename='Unit']");
  Item[] allActivities = unit.Database.SelectItems("ancestor-or-self::*[@@templatename='Activity']");
  
  foreach(Item thisitem in allActivities){
      //Process here
  }
  </code></pre>
  
  <p>Siblings ("Following" &amp; "Preceeding") dont work because it only returns direct siblings underneath the same <code>lesson</code>, not the <code>unit</code> as needed.</p>