Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Using category SEF title in static content (sNews 1.4)  (Read 2609 times)

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Using category SEF title in static content (sNews 1.4)
« on: August 26, 2006, 06:00:05 pm »

Not sure if this qualifies as a mod, it's more of an extension of the index.php construction, but I thought I would show how you can do more with your static bits by a simple php code snippet. I've only tested it with sNews 1.4, not 1.3 or txtdb versions. And, because I'm no PHP expert, usual rules apply.

************************
Back up your files.
************************

The extension makes use of the find_category_id trick Luka showed in this thread. I'm not really sure it's required because the first time I tried the following trick I didn't have Luka's code in place in my snews.php and it worked anyway, but it can't hurt.

What the extension is good for
Let's say that you want to use image replacement to put a nice header image on your page, so you make an

header in the index.php and style it accordingly.

Here's a simple code example:
Quote

Hello World!


yada yada yada...
Now let's say you want to display different header images (or just plain old header text) for each category. This is where the extension comes in.

Using the extension
Following the example above, instead of the previous html code, we input this php snippet:
Quote

$categorySEF = get_id('category');
if ($categorySEF) {
echo "

" .$categorySEF. "

\n";
} else {
echo "

Hello World!

\n";
}
?>

yada yada yada
The CSS for the example above looks like this:
Quote
(Malarkey's Image Replacement)
.mir { letter-spacing: -1000em; }
/* Just for Opera, but hide from MacIE */
/*\*/html>body .mir { letter-spacing: normal; text-indent: -999em; overflow: hidden; }
/* End of hack */

h1.mir {
   width: 810px;
   height: 160px;
   font-size: 1px;
   line-height: 160px;
   margin: 0 auto 15px auto;
   padding: 0;
}

.home { background: url(img/backgrounds/topbg.jpg) no-repeat center top; }
.design_issues { background: url(img/backgrounds/designhead.jpg) no-repeat center top; }
.about { background: url(img/backgrounds/abouthead.jpg) no-repeat center top; }
.showroom { background: url(img/backgrounds/showhead.jpg) no-repeat center top; }
.clients { background: url(img/backgrounds/clienthead.jpg) no-repeat center top; }
.tutorials { background: url(img/backgrounds/guidehead.jpg) no-repeat center top; }
And that will give us a different header image replacement for each category, as can be seen on this test site (use the top navigation bar to go to categories). Note that this extension isn't restricted to static categories or any specific item -- you can use it just about any way you like. At least I think so.

Extension inspired by get_category_id by Luka and array based modules mod by keyrocks/mika
;D

Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Using category SEF title in static content (sNews 1.4)
« Reply #1 on: August 26, 2006, 08:20:28 pm »

Well done there Agent Smith! From what I see on your demo site... I have a feeling this could easily be worked into the custom modules add-on I ended up with using Mika's 'starter' scripts which... by the way... is now fully documented as a tutorial on snews.ca in the add-ons (module) now in use there. ( see the update on the original post - http://www.solucija.com/forum/viewtopic.php?id=1486. I'll make a point of keeping posted on this one and - perhaps - try it out on an upcoming project. :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Using category SEF title in static content (sNews 1.4)
« Reply #2 on: August 26, 2006, 08:37:19 pm »

key -- sorry, I forgot about that thread and had missed the update. I've edited the link in my original post here to point to the proper thread. Thanks for the heads-up.

As for rolling my extension into your custom modules mod, that should be perfectly doable. I haven't tested it yet so currently my demo page only listens for top-level categories, not subcategories. I'll run a few tests to see what happens (have to set up subcategories anyways... ;D ). PHP experts should have no problems with it though, as far as I can see.
Logged

Mika

  • Hero Member
  • *****
  • Karma: 9
  • Posts: 1377
    • http://www.ni5ni6.com/
Using category SEF title in static content (sNews 1.4)
« Reply #3 on: August 26, 2006, 11:38:46 pm »

Quote from: agentsmith
...because I'm no PHP expert...
liar :D
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version