Advanced tricks

How can I allow my users to edit their own favorite links?

Scenario:
"I am running a Nucleus site with users who each have their own blog. I want to let them change the links on the main page to whatever they want through the Nucleus admin area without giving them full admin access or having to do it myself."

Solution:
This can be done with if conditionals in 2 ways:
(a) through NP_ExtraSkin
(b) individual blog entries

Original forum thread and post:
http://forum.nucleuscms.org/viewtopic.php?t=4816
http://forum.nucleuscms.org/viewtopic.php?p=23359#23359

Method 1:

  1. Create a new blog for every user you have.
  2. Using NP_ExtraSkin, create an ExtraSkin for every user you have (this will be their link file, with all of their links). Call the skin _links.
  3. Find where the main page links are and change it to this:
    <%if(blogsetting,bnumber,***)%>
      <%ExtraSkin(<username>_links)%>
    <%endif%>

    For Nucleus v3.1 using the grey skin, this will be in the Main Index skinpart. For Nucleus v3.2 using the default skin, this will be in the file sidebar.inc located in /skins/default/.

  4. Replace the "***" with the blogid of a particular user's blog. So if you have a user called Steve, and the blogid for his blog is 5, you would then have <%if(blogsetting,bnumber,5)%>.
  5. Repeat this for every user you have. So if you have 3 users called Steve (blogid = 5), Amanda (blogid = 7) and Rory (blogid = 8 ), you would end up with something like this:
    <%if(blogsetting,bnumber,5)%>
      <%ExtraSkin(Steve_links)%>
    <%endif%>
    <%if(blogsetting,bnumber,7)%>
      <%ExtraSkin(Amanda_links)%>
    <%endif%>
    <%if(blogsetting,bnumber,8)%>
      <%ExtraSkin(Rory_links)%>
    <%endif%>

    How this works is every time Nucleus gets to that part in your Main Index skin, it will check to see which blog is selected. If it's Steve's blog, then it will only show Steve's links. If it's Amanda's blog, it will only show Amanda's links. If it's Rory's blog, it will only show Rory's links.

    Whatever piece of code you end up with, just place it in the skin part of any pages you want it to appear on, as before. If the users want to change one of their links then they will have to edit their ExtraSkin.

Method 2:

Another way of doing it would be to get each user to create a blog entry in their own blog, in a category called Links (they each should have a category called "Links", so in our example, there should be 3 categories with the same name of "Links" total).

Then, you would use the same code as above, but instead of having <%ExtraSkin(<username>_links)%>, you need to put the following instead:

<%blog(template,1,catid)%>

This will cause Nucleus to display the most recent entry in the category with catid "catid" of the selected blog, using the template "template". This way, your users can edit their links without having to FTP, know HTML, or muck around with ExtraSkins, since their "Links file" will be part of their blogs.

So if Steve's "Links" category has a catid of 17, Amanda's has catid = 21 and Rory has catid = 23, your final code will look like this:

<%if(blogsetting,bnumber,5)%>
  <%blog(template,1,17)%>
<%endif%>
<%if(blogsetting,bnumber,7)%>
  <%blog(template,1,21)%>
<%endif%>
<%if(blogsetting,bnumber,8)%>
  <%blog(template,1,23)%>
<%endif%>

HOWEVER, you must be careful that they put ALL of the links they want to appear in the SAME blog entry, or else not all of them will show up (only those in the most recent entry will).

Warning:
For more complicated sites that have lots of users, this code will be very long and hard to maintain.

section: Advanced tricks | submitted by Leng on 2005.Apr.23 | 5292 views

item rate
Total votes: 9 - Rating: 2.89

Please tell us how useful this answer was to you (0 = useless, 10 = very very helpful):

10