Advanced tricks

How do I use Nucleus to manage my static content?

Static content:
"Content that is purely text/html and not generated by a script such as php contact page."

Why use Nucleus to manage static content:

  • Manage the actual static content through Nucleus, instead of having to edit an html or php file every time you want to modify it.
  • Have all the pages of your site look uniform, using the same template and css (although you can also use altogether different layout and css if you wanted, this is quite flexible).

Original forum thread (thanks, utterplush!):
http://forum.nucleuscms.org/viewtopic.php?t=6394

Method:

  1. Setup "Static" Blog

    This is done just once to setup this method for use.

    We need a blog to hold all our static content. You can create a new blog, or use an already existing one. Give it a name like "Static" so that you will remember what it is for.

  2. Create/Edit the Item to Hold the Content

    If you created a new blog, Nucleus supplies a starting item for you within it. Rather than delete it, you can edit it. Else if you need to, create a new item within your "Static" blog.

    Change the item as appropriate. Since we're making an "about" page, let's give it a new Title "About". We'll also enter "About me." for the "Body" for now, and you can come back and further edit this item later.

  3. Find the Item ID

    On the main page of Nucleus' admin interface, we have a list of our blogs and ways to manage them ("Action").

    Choose "Edit/Delete Items" for your "Static" blog. Here we see a list of the items for our static blog, which will only be one if we created a new blog earlier.

    A simple way to obtain the id is available via a tiny plugin: NP_ShowPostID. If you choose to use the plugin, simply click the "Edit" link, and scroll to where the id number is shown. Make note of the number, and continue to the next step ("Create A PHP File").

    To do this without a plugin,
    Go to your item, right-click on the "Edit" link, and choose:
    - if you're using Internet Explorer: "Copy Shortcut"
    - if you're using Firefox: "Copy Link Location"
    - should be similar for other browsers

    Open up a new document/file in any text editor, like Notepad, for example.

    Right-click and choose "Paste". You'll see a url like this:
    http://yourdomain.com/nucleus/index.php?action=itemedit&itemid=4

    itemid is your item's id number. In my example, the number 4. This is an important number we need to remember. You can now right-click and "Select All" and delete this url (but remember the id number).

  4. Create A PHP File

    This is the file that people will access to get at your content. You can name it anything you want.

    You can give it a .php extension or you can make it extension-less, just like Nucleus' "Fancy urls". If you want to go the extensionless route, consider that an extra: you need to know what you're doing. Remember this is somewhat of a hack, not supported.

    We'll create a file "about.php". Inside it, we add some PHP code.

    <?php
    $CONF['Self'] = 'index.php';
    include('./config.php');
    $itemid = 1;
    selector();
    ?>

    The first line tells Nucleus to treat "about.php" just like "index.php". This way, if you have a sidebar showing category links [1] and other blog specific things, it will look just like your main blog, instead of your content blog. $itemid needs to be the item's id discussed above. In my example above, that number was 4, so our code is:

    <?php
    $CONF['Self'] = 'index.php';
    include('./config.php');
    $itemid = 4;
    selector();
    ?>
  5. All Done, Almost

    If you view about.php, you should see the page with the content we entered.

    This file will use the Skin (and it's associated templates) you assigned to your Static blog.

    If this also happens to be a default or downloaded Skin, that means it will have other stuff in it you my not desire, such as the comments area, or perhaps formatting that you want to be different.

    One easy way to make a new Skin for your Static blog to use is to "Clone" the default skin. You can then rename it (to maybe "Static", just so we don't get anything confused) and then take out the parts you don't like, change anything, or add other things. Don't forget do do the same thing for Templates, if you want different templates used for your static page.

    Others have done better work explaining Skins and Templates, so I recommend you make yourself very familiar with the Skins and Templates areas, and make use of the excellent documentation already available, some of which I linked to above.

    Because of Skins and Templates, you can get very creative with this method.

  6. Override Static Skin?

    What if you make your Skin for your Static blog, but then you get just one page that you want to look different? You do not have to make another blog. Instead, make another skin, and your php file needs only a little modification

    <?php
    $CONF['Self'] = 'index.php';
    include('./config.php');
    $itemid = 4;
    selectSkin('your-skin-name');
    selector();
    ?>
  7. New Pages?

    When it comes time to do this again for another page, repeat the steps for
    - creating the item within your already existing static blog
    - obtain its id
    - create the php file and include the item's id within it

Footnotes:
1. If you want to keep the same category list on your static blog as your main blog, you will need to modify how it is displayed. Find where the code <%categorylist%> is being generated in your skin (it is inside the file sidebar.inc for the default skin) and replace it with the following code:

<%if(blogsetting,bnumber,X)%>
  <%categorylist(templatename)%>
<%else%>
  <%categorylist(templatename,static)%>
<%endif%>

where "X" is the blogid of your main blog, "templatename" is the name of your template and "static" is the name of your static blog.

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

item rate
Total votes: 61 - Rating: 5.97

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

10