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.

Pages: [1] 2 3

Author Topic: [MOD] The Body ID, for sNews 1.6  (Read 11213 times)

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
[MOD] The Body ID, for sNews 1.6
« on: September 04, 2007, 04:51:08 am »

Preamble: Back in the day, e.g. v1.5, there was some demand for a mod that allowed us to change styling of pages on the fly. The simplest, most dynamic way of doing that for the webmaster (note: not the visitors, not the site admin when that is different from the webmaster) is by assigning an id to the <body> tag, based on the active page name. So I created such a mod for v1.5 with much help from philmoz. Here is the same code for v1.6.

1. In snews.php add this function somewhere (I have placed mine directly after the title function)
Quote
// BODY ID FUNCTION
function bodyname() {
$categorySEF = get_id('category');
$pageSEF = get_id('article');
$pageId = (empty($categorySEF)) ? 0 : retrieve('position', 'articles', 'seftitle', $pageSEF);
$catList = explode(',',l('cat_listSEF'));
$pageList = in_array($categorySEF,array('home','archive','contact','sitemap'))?true:'';
$categorySEF2= in_array($categorySEF,$catList)?true:'';
switch (true){
    case empty($categorySEF)||$categorySEF==s('home_sef') && empty($pageSEF) : $id= s('home_sef'); break;
    case !empty($categorySEF)&& empty($pageSEF)||$pageId!=3 : $id=$categorySEF; break;
    case !empty($pageSEF)&&$pageId==3 : $id=$pageSEF; break;
    default:$id=s('home_sef');
}
if($_SESSION[db('website').'Logged_In'] == token()){
    switch(true){
        case !$pageSEF&&$categorySEF2==true&&$pageList!=true: $id="administration";break;
        case $_GET['action']:$id="administration";break;
        default:$id;
    }
}echo '<body id="'.$id.'">';
}

2. Usage -- In index.php, exchange the opening <body> tag with this code:
Quote
<?php bodyname(); ?>

3. What it does
With this mod in place, the generated body tag for Home, when not logged in, will look like this:

Quote
<body id="home">

For a category named Test, like this:
Quote
<body id="test">

For a page named Testpage, like this:
Quote
<body id="testpage">

4. Considerations
Naming conventions. Since you will get body id's with same names as your home sef title, category names, page names and administration, make sure to not use those names for other id's on your site -- it will break validation and can upset styling in unwanted ways.

If you use this mod and like it, please feel free to donate a beer or chocolate chip cookie to philmoz...

:D
« Last Edit: September 04, 2007, 09:30:11 am by philmoz »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: [MOD] The Body ID, for sNews 1.6
« Reply #1 on: November 16, 2007, 09:27:10 pm »

I have a question Agentsmith... is this "Everything the <BODY> needs"?  ;D
Seriously... I was thinking of revving this one up for a run... but I was also thinking of implementing a "Show me some more" expandable panel approach to making Admin Tips in the Admin Panels... done by Stu Nicholls. It works quite simple, really, but it uses a small jscript function... and the body-tag needs to contain the jscript's onload trigger:

Quote
<body onload="clickMenu('outer','div','more')">

... and I am assuming that there is no way to use this and the <?php bodyname(); ?> function string at the same time. Could you confirm whether my assumption is correct or not?
« Last Edit: November 16, 2007, 09:34:46 pm by Keyrocks »
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
Re: [MOD] The Body ID, for sNews 1.6
« Reply #2 on: November 17, 2007, 04:36:35 am »

of course you could use both body id and onload in one fell swoop, you just need to add the onload string to the bodyname function in snews.php -- at least that's how I see it. I haven't tested it though.

Try changing
Quote
}echo '<body id="'.$id.'">';

to
Quote
}echo '<body id="'.$id.'" onload="clickMenu('\outer'\,'\div'\,'\more'\)">';
(I'm never sure where to put those backslashes to make the single quotes work as they should. Hopefully you get the idea.)

The generated body tag would then become:
Quote
<body id="'pagename.'" onload="clickMenu('outer','div','more')">

But, harkening back to your original question ... the ID mod is not it. sNews is. ;D 8)
« Last Edit: November 17, 2007, 04:40:20 am by Fred K (agentsmith) »
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] The Body ID, for sNews 1.6
« Reply #3 on: November 17, 2007, 09:25:15 am »

Hello mates
one question: how to use the Mod with separate templates?
I don't get it. ???

Joost

  • Guest
Re: [MOD] The Body ID, for sNews 1.6
« Reply #4 on: November 17, 2007, 09:44:20 am »

Good morning Phillipe.

Then you would have to include <?php bodyname(); ?> in every template.

Logged

brauck

  • Hero Member
  • *****
  • Karma: 18
  • Posts: 556
    • http://www.hbw-webdesign.nl/
Re: [MOD] The Body ID, for sNews 1.6
« Reply #5 on: November 17, 2007, 10:28:34 am »

@Keyrocks; watch out for de onload event trapper Doug, read this post. I'ts on my worklist, but sjeez, it's so long :(
Logged
Confidence is reduced complexity.
brauck.nl for free css templates

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] The Body ID, for sNews 1.6
« Reply #6 on: November 17, 2007, 11:26:15 am »

Good morning Phillipe.

Then you would have to include <?php bodyname(); ?> in every template.


:P
okay! I'm awake now.
Note to myself: never never ask questions before 11:00.

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] The Body ID, for sNews 1.6
« Reply #7 on: November 17, 2007, 12:36:51 pm »

Frederik,
I went on your website (has it change recently?): you did a really great job on it.
And I have a question: how do you manage differents h1 on each page?

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] The Body ID, for sNews 1.6
« Reply #8 on: November 17, 2007, 01:25:05 pm »

Good morning Phillipe.

Then you would have to include <?php bodyname(); ?> in every template.


:P
okay! I'm awake now.
I go back to sleep (I had a dreadful night): I still don't get how to assign a different template to a category, a page and so on... ???

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 940
Re: [MOD] The Body ID, for sNews 1.6
« Reply #9 on: November 17, 2007, 01:31:43 pm »

Sven, there are two mods for assigning templates depending on what is being shown:
Different templates wherever you want
Multiple layouts (templates) for sNews (ver.1.6, 1.5.31)

This Body ID will help with styling; but You need another one as well to get into different template.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: [MOD] The Body ID, for sNews 1.6
« Reply #10 on: November 17, 2007, 01:48:24 pm »

of course you could use both body id and onload in one fell swoop, you just need to add the onload string to the bodyname function in snews.php -- at least that's how I see it. I haven't tested it though.
OK... yes... that's what I was thinking when I woke up this a.m. so I'll give it a whirl later on this weekend. Thanks Fred.
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
Re: [MOD] The Body ID, for sNews 1.6
« Reply #11 on: November 17, 2007, 05:04:55 pm »

Quote from: Sven
I went on your website (has it change recently?): you did a really great job on it.
And I have a question: how do you manage differents h1 on each page?

Thanks, Philippe. No, it's been this way since April. But it is changing soon. :P

The different <h1> outputs on the main, sNews and Templates sections come from having the site divided up in three sections with three different tables, using prefixes. (See the post "One database to rule them all" in the sNews section for more detail.) In other words: I'm faking it.

To get different templates on page, follow Joost and codetwist's advice. They know their stuff. The body id mod is a way of changing looks for different pages using the same stylesheet, basically.
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] The Body ID, for sNews 1.6
« Reply #12 on: November 17, 2007, 05:38:02 pm »

Thanks Codie.
Hello Mr Keyrocks.
Thanks Fred.

Quote from: Fred K (agentsmith)
The different <h1> outputs on the main, sNews and Templates sections come from having the site divided up in three sections with three different tables, using prefixes. (See the post "One database to rule them all" in the sNews section for more detail.) In other words: I'm faking it.
:P Seems pretty tricky.
What was your idea?
<h1> is so important for SEO I use page description to have different h1 for each article.
To have a page description AND a h1 tag for each page should be better for semantics.
I need to see that but I didn't find the related thread you're talkin about..

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: [MOD] The Body ID, for sNews 1.6
« Reply #13 on: November 17, 2007, 08:21:23 pm »

The article I mentioned is here, but it doesn't talk about how to pull in the category/page/article description on each page. What I do use is the call "echo s(website_title)" in my h1 tags,  to bring in the site name defined in each database. You can easily change that to "echo s('website_description'), to call in the site's global meta_description, but to do what you want, you should use something like <h1><?php echo page_desc(); ?></h1> (page_desc is a pseudo function, it isn't real). I think there's a mod already, somewhere, for this but I'm not sure.

The body id mod is about presentation, not content. Just so it's clear.
« Last Edit: November 17, 2007, 08:31:18 pm by Fred K (agentsmith) »
Logged

Sven

  • ULTIMATE member
  • ******
  • Karma: 88
  • Posts: 2029
  • Chasing MY bugs!
    • hiseo.fr - rédacteur Web
Re: [MOD] The Body ID, for sNews 1.6
« Reply #14 on: November 18, 2007, 02:12:49 pm »

Hello Fred

The article I mentioned is here, but it doesn't talk about how to pull in the category/page/article description on each page. What I do use is the call "echo s(website_title)" in my h1 tags,  to bring in the site name defined in each database. You can easily change that to "echo s('website_description'), to call in the site's global meta_description, but to do what you want, you should use something like <h1><?php echo page_desc(); ?></h1>
That's what I'm using (with Philmoz and Mika's help).
Code: [Select]
function page_description(){
    $articleSEF = get_id('article');
    if (!empty($articleSEF)) {
        $query = "SELECT description_meta FROM ".db(prefix)."articles WHERE seftitle = '$articleSEF'";
        $result = mysql_query($query);
        while ($r = mysql_fetch_array($result)) {$dmeta = $r['description_meta'];}
    }echo $dmeta;
}
But, recently, I made a mistake: I gave to 2 articles (in fact 2 articles cut in 2 parts) the same page description and guess what's happened?
Google fired out both pages from the index. >:(

I'm wondering if one of our PHP chefs can cook a Semantic Mod for our beloved sNews.
Purpose: to have in the admin backend a New field to be filled with an extra h1 tag sayin why the reader must read this article.
So, we gonna have:
- the page description (already existing) but used by spiders and not showned to humans
- the h1 tag with a claim for visitors (have a look here)
- the h2 tag for the title (same as the SEF Url)

So if some sNews Chefs think it would be useful for all...  ;)
Quote from: Fred K (agentsmith)
The body id mod is about presentation, not content. Just so it's clear.
I still don't get how to use the Body Id Mod with ONE template. ???
« Last Edit: August 20, 2008, 08:00:06 am by Sven »
Logged
Pages: [1] 2 3