Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Header in Categories only  (Read 1450 times)

bobcat

  • Jr. Member
  • **
  • Karma: 1
  • Posts: 67
    • ESL Jobs by Country
Header in Categories only
« on: December 31, 2007, 12:13:49 pm »

Again have searched the forums for hours but couldn't find any answer..

How would you go about showing a heading <h1>XXXXX</h1> at the top of the category page. But do not see it on home or the articles page.

I have tried including it in the //CENTER function but, it appears in both category and articles.
How to make it only showing in categories.

Thanks  :)

centered

  • Guest
Re: Header in Categories only
« Reply #1 on: December 31, 2007, 03:18:16 pm »

Where do you want it?  In place of the header logo or in center?

Haven't fully tested these but it wrks on my test install

If you want it in center..
add a new function:
Code: [Select]
function cat_desc() {
$catSEF = get_id('category'); $artSEF = get_id('article');
$desc = retrieve('description','categories','seftitle',$catSEF);
if (empty($artSEF) && !empty($desc)) { echo '<h1>'.$desc.'</h1>'; }
}

Then call it in center...
Code: [Select]
default:
// added new line here
cat_desc();
$article = get_id('article');
$title_not_found = '<h2>'.l('not_found').'</h2>';
$currentPage = strpos($article, l('paginator')) === 0 ? str_replace(l('paginator'), '', $article) : '';

What it does:
If you are in domain.com/category/ it will show the category description in an h1, if it was entered. Otherwise, it won't show anything


if you want it in header:
New function (DONT USE THE ABOVE it is not the same)
Code: [Select]
function cat_desc() {
$catSEF = get_id('category'); $artSEF = get_id('article');
$desc = retrieve('description','categories','seftitle',$catSEF);
if (empty($artSEF) && !empty($desc)) { echo '<h1>'.$desc.'</h1>'; }
elseif (empty($desc) || empty($artSEF) && empty($catSEF) || check_category($catSEF) == True) {
echo '<h1>'.s('website_title').'</h1>'; }
}

In index.php
Replace your h1 logo
Code: [Select]
<div class="wrap">
<div id="logo">
<!-- REPLACED LINE HERE -->
<?php echo cat_desc(); ?>
</div>

What this does is replaces your h1 logo to this mod.  If the category description is present and your on a category, it will show the category description, otherwise it will show the website title
« Last Edit: December 31, 2007, 03:42:30 pm by equilni »
Logged

bobcat

  • Jr. Member
  • **
  • Karma: 1
  • Posts: 67
    • ESL Jobs by Country
Re: Header in Categories only
« Reply #2 on: January 01, 2008, 08:20:52 am »

Thanks equilni. I am using the top of of the options you have posted.

Have finally got it working but am having a problem:

If i include into Center function:
Code: [Select]
default:
// added new line here
cat_desc();
$article = get_id('article');
$title_not_found = '<h2>'.l('not_found').'</h2>';
$currentPage = strpos($article, l('paginator')) === 0 ? str_replace(l('paginator'), '', $article) : '';

I get the following error:
Parse error: syntax error, unexpected T_DEFAULT in /home/feed/public_html/news/snews.php on line 780

If i take away the 'default:', it appears to work, but then on the category pages it breaks the [break]. So all articles are listed in full on the category pages.

Have i done anything wrong? or is there a solution to the above. Thanks.

centered

  • Guest
Re: Header in Categories only
« Reply #3 on: January 01, 2008, 09:15:37 am »

Dumb question... did you add the function above the center function example?

Second, the new line in CENTER is cat_desc(); AFTER the default line. 

What is line 780?

I just tested option one on a fresh install and it works fine for me
Logged

bobcat

  • Jr. Member
  • **
  • Karma: 1
  • Posts: 67
    • ESL Jobs by Country
Re: Header in Categories only
« Reply #4 on: January 01, 2008, 09:29:48 am »

line 780 is the 'default:' if i leave that line in.
Yes the new function is just above // CENTER

The part of // CENTER with the new code is below: This is the only place i could find which inserts the h1 where i want it (In Center, and above all articles in the category page only)
Code: [Select]
$result = mysql_query($query_articles);
$numrows = mysql_num_rows($result);
if (!$result || !$numrows) {echo $title_not_found;}
else {


// h1 function start

default:
// added new line here
cat_desc();
$article = get_id('article');
$title_not_found = '<h2>'.l('not_found').'</h2>';
$currentPage = strpos($article, l('paginator')) === 0 ? str_replace(l('paginator'), '', $article) : '';

// h1 function end

$link = '<a href="'.db('website');

while ($r = mysql_fetch_array($result)) {
$infoline = $r['displayinfo'] == 'YES' ? true : false;

centered

  • Guest
Re: Header in Categories only
« Reply #5 on: January 01, 2008, 03:48:05 pm »

Ahh I see, you added the whole section I pasted, instead of finding the lines before and after to place the one line

Do you see where this is supposed to go?

Find the sections above and below the commented line and ADD ONLY THE ONE LINE in that spot

Code: [Select]
switch ($action) {
case 'archive': archive(); break;
case 'sitemap': sitemap(); break;
case 'contact': contact(); break;
case 'login': login(); break;
case '404': error404(); break;
default:

//  ADD THIS LINE HERE AND ONLY HERE
cat_desc();
        //  THIS LINE ONLY

$article = get_id('article');
$title_not_found = '<h2>'.l('not_found').'</h2>';
$currentPage = strpos($article, l('paginator')) === 0 ? str_replace(l('paginator'), '', $article) : '';
$home = l('home_sef'); $categorySEF = get_id('category');
$categorySEF = empty($categorySEF) ? $home : $categorySEF;
$use_cat_id = $categorySEF == $home ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
$query_articles = "SELECT * FROM ".db('prefix')."articles WHERE published = 1 AND SUBSTRING(position, 1, 1) != '2'";
  if (!empty($article) && empty($currentPage)) {$query_articles .= " AND seftitle = '$article'";}
else if ($categorySEF == $home && s('display_page') <> 0) {$id_page = s('display_page'); $query_articles .= " AND id = '$id_page'";}
  else {
if (s('display_new_on_home') == 'on') {$query_articles .= $use_cat_id != 0 ? " AND category = $use_cat_id" : '';}
else {$query_articles .= " AND category = $use_cat_id";}
$query_articles .= " AND position <> 3 ORDER BY date DESC";
$result_articles = mysql_query($query_articles);
$numrows_articles = mysql_num_rows($result_articles);
if (!$result_articles || !$numrows_articles) {echo $title_not_found; return;}
else {
$articleCount = s('article_limit');
« Last Edit: January 01, 2008, 03:51:10 pm by equilni »
Logged

bobcat

  • Jr. Member
  • **
  • Karma: 1
  • Posts: 67
    • ESL Jobs by Country
Re: Header in Categories only
« Reply #6 on: January 02, 2008, 12:44:53 am »

Thanks. Stupid mistake on my part!

It's working good now, and i have a custom title and description on the top of the category pages. Should be better for SEO now. :)