Reorder forums
To reorder forums, you must perform the following:
- Change the ordinal of the specified forum.
Query the specified forum and modify the value of itsOrdinalproperty. For more information, see For developers: Modify forums. - Update the ordinals of the other forums.
Update the values of theOrdinalproperties of the other sibling forums according to the new ordinal of the specified group.
Here is a code example:
C#
using System;
using System.Linq;
using Telerik.Sitefinity.Forums;
namespace SitefinityWebApp
{
public class ReorderForums_MoveForum
{
public static void MoveForum(Guid forumId, int newOrdinal)
{
ForumsManager forumsManager = ForumsManager.GetManager();
var forumToMove = forumsManager.GetForum(forumId);
var forums = forumsManager.GetForums().Where(f => f.Group != null && f.Group.Id == forumToMove.Group.Id);
//Validate new ordinal
if (newOrdinal < 0 || newOrdinal == forumToMove.Ordinal)
{
return;
}
else if (newOrdinal > forums.Count())
{
newOrdinal = forums.Count();
}
//Preserve the old ordinal value
var oldOrdinal = forumToMove.Ordinal;
//Assign the new ordinal value
forumToMove.Ordinal = newOrdinal;
//Reorder the other forums.
foreach (var forum in forums)
{
if (forum.Equals(forumToMove))
{
continue;
}
//Moving up
if (newOrdinal < oldOrdinal)
{
//Update only the items between the new and the old position
if (forum.Ordinal >= newOrdinal && forum.Ordinal < oldOrdinal)
{
forum.Ordinal++;
}
}
//Moving down
else
{
//Update only the items between the new and the old position
if (forum.Ordinal <= newOrdinal && forum.Ordinal > oldOrdinal)
{
forum.Ordinal--;
}
}
}
forumsManager.SaveChanges();
}
}
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.
Foundations of Sitefinity ASP.NET Core Development
The free on-demand video course teaches developers how to use Sitefinity ASP.NET Core and take advantage of its decoupled architecture and modern development model.