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: Question: How to get sNews NOT to display article text in categories?  (Read 1452 times)

WizaJ

  • Newbie
  • *
  • Karma: 0
  • Posts: 5

Hi,
I recently took interest in HTML/PHP/MySQL and website development and I'm learning much about this and it's all pretty interesting. I would like help in changing my core snews.php file so that it only displays links to articles whenever someone clicks a category on my front page. I dont want it to display article text from different articles in one page, just the links alone. I'm using sNews for a mobile website because it's pretty easy to use and manage and renders wonderfully on mobile devices. Any assistance would be greatly appreciated,
Wiza.
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Question: How to get sNews NOT to display article text in categories?
« Reply #1 on: November 18, 2010, 04:59:41 PM »

Hi,
I recently took interest in HTML/PHP/MySQL and website development and I'm learning much about this and it's all pretty interesting. I would like help in changing my core snews.php file so that it only displays links to articles whenever someone clicks a category on my front page. I dont want it to display article text from different articles in one page, just the links alone. I'm using sNews for a mobile website because it's pretty easy to use and manage and renders wonderfully on mobile devices. Any assistance would be greatly appreciated,
Wiza.

Welcome to the sNews fold Wiza.
I think... but correct me if I am wrong... that you are looking for a function that would work like an expandable vertical menu so that when you click a category name, it will reveal text links to article titles within it. If so, the modified functions below - for sNews 1.7 versions only - should do it.

Locate the categories and sub-categories functions in your snews.php file - searching for // CATEGORIES will bring you to the spot - comment both functions out (disable them) and copy in the two functions below.

Code: [Select]
<?php // DO NOT COPY THIS TAG


// CATEGORIES - For Expandable Categories Menu - replaces default function (Keys).
function categories() {
$qwr = !_ADMIN ' AND a.visible=\'YES\'' '';
if (s('num_categories') == 'on') {
$count ', COUNT(DISTINCT a.id) as total';
$join 'LEFT OUTER JOIN '._PRE.'articles'.' AS a ON (a.category = c.id AND a.position = 1 AND a.published = 1'.$qwr.')';
} else { $count =''$join=''; }
$result mysql_query('SELECT c.seftitle, c.name, description, c.id AS parent'.$count.' FROM '._PRE.'categories'.' AS c '.$join.'
WHERE c.subcat = 0 AND c.published = \'YES\' GROUP BY c.id ORDER BY c.catorder,c.id'
);
echo '<ul>';
if (mysql_num_rows($result) > 0){
          while (
$r mysql_fetch_array($result)) {
    $category_title $r['seftitle'];
    $r['name'] = (s('language')!='EN' && $r['name'] == 'Uncategorized' && $r['parent']==1) ? l('uncategorised') : $r['name'];
    $class $category_title == $categorySEF ' class="current"' '';
    if (isset($r['total'])) { $num='('.$r['total'].')'; }
    # List expandable category title-links
    echo '<li><a'.$class.' title="'.$r['name'].' - '.$r['description'].'" onclick="toggle(\''.$r['name'].'\')" style="cursor: pointer;">'.$r['name'].$num.'</a>';
    $art_result mysql_query("SELECT * FROM "._PRE."articles WHERE position IN (1,3) AND category = '".$r['parent']."' AND published = 1");
    $num_rows mysql_num_rows($art_result);
    $subcats_published retrieve('published','categories''subcat'$r['id']); // Retrieve published subcats if they exist
    if ($num_rows 0) { // If content exists
echo '<ul id="'.$r['name'].'" style="display: none;">';
# list article text-links by category, fetched in $art_result query
while ($art mysql_fetch_array($art_result)) {
    echo '<li>'.l('divider').' <a href="'._SITE.$category_title.'/'.$art['seftitle'].'/" title="'.$art['title'].'">'.$art['title'].'</a></li>';
}
$parent $r['parent'];
# If published subcats exist, include function subcategories.
if ($subcats_published 'YES') { subcategories($parent); }
echo '</ul>';
    } else { echo '<ul id="'.$r['name'].'" style="display: none;"><li>'.l('article_not_exist').'</li></ul>'; } // End: Insert F
    echo '</li>';
  }
} else { echo '<li>'.l('no_categories').'</li>'; }
echo '</ul>';
}

// SUB CATEGORIES - For Expandable Categories Menu - replaces default function (Keys).
function subcategories($parent) {
    
$qwr = !_ADMIN ' AND a.visible=\'YES\'' '';
    if (
s('num_categories') == 'on') {
$count ', COUNT(DISTINCT a.id) AS total';
$join ='LEFT OUTER JOIN '._PRE.'articles'.' AS a ON (a.category = c.id AND a.position = 1 AND a.published = 1'.$qwr.')';
    } else { 
$count ='';  $join=''; }
    
# added: c.id AS sub_id, subcat, | using: $s['sub_id'] for category match in $sub_art query
    
$subresult mysql_query('SELECT c.seftitle AS subsef, c.id AS sub_id, subcat, description, name'.$count.' FROM '._PRE.'categories'.' AS c '.$join.' WHERE c.subcat = '.$parent.' AND c.published = \'YES\' GROUP BY c.id ORDER BY c.catorder,c.id');
    if (
mysql_num_rows($subresult) !== 0) {
echo '<ul>';
while ($s mysql_fetch_array($subresult)) {
    $subSEF $s['subsef'];
    $class $subSEF == $subcatSEF ' class="current"' '';
    if (isset($s['total'])) { $num=' ('.$s['total'].')'; }
    # List expandable subcategory title-links
    echo '<li class="subcat"><a'.$class.' title="'.$s['name'].'" onclick="toggle(\''.$s['name'].'\')" style="cursor: pointer;">'.$s['name'].$num.'</a></li>';
    echo '<ul id="'.$s['name'].'" style="display: none;">';
    # Query articles by subcat ID
    $subart_result mysql_query("SELECT * FROM "._PRE."articles WHERE position IN (1,3) AND category = '".$s['sub_id']."' AND published = 1");
    $sub_num_rows mysql_num_rows($subart_result);
    $subcat_id $s['sub_id']; // pulls current subcat's 'id'
    $subcat_num $s['subcat']; // pulls current subcat's 'subcat' number
    $cat_id retrieve('id','categories''subcat',$subcat_num); // pulls current subcat's id as: $cat_id
    $subcat_SEF retrieve('seftitle','categories','seftitle',$cat_id); // pulls current subcat's seftitle
     
    $cat_SEF retrieve('seftitle','categories'id,$subcat_num);
     
    if ($sub_num_rows 0) { // If sub-cats exist, show sub-cat titles as expandable text-links
while ($s_art mysql_fetch_array($subart_result)) {
    # list subcat's article text-links, fetched in #subart_result query
    echo '<li>'.l('divider').' <a href="'._SITE.$cat_SEF.'/'.$subSEF.'/'.$s_art['seftitle'].'" title="'.$s_art['title'].'">'.$s_art['title'].'</a></li>';
}
    }
            echo 
'</ul>';
echo '</li>';
        }
echo '</ul>';
    }
}

// DO NOT COPY THIS TAG ?>


These two functions were working fine in one of my sNews 1.7 projects but I was not able to test these specific copies as my server is not active at the moment.
« Last Edit: November 28, 2010, 04:45:22 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

WizaJ

  • Newbie
  • *
  • Karma: 0
  • Posts: 5
Re: Question: How to get sNews NOT to display article text in categories?
« Reply #2 on: November 28, 2010, 12:32:11 PM »

Welcome to the sNews fold Wiza.
I think... but correct me if I am wrong... that you are looking for a function that would work like an exandable vertical menu so that when you click a category name, it will reveal text links to article titles within it. If so, the modified functions below - for sNews 1.7 versions only - should do it.

Hi Keyrocks,
First of all thank you for your reply. Your time and effort is much appreciated, but this is not exactly what I am looking for.
What I wanted was that when someone clicks on any category on the website, only the links to articles contained within that category should be displayed rather than a link to the article and the article text as well. I've taken a screenshot of an example where I have a practical use for this.

Currently, this is what sNews does when you click on a category


This is what I would like sNews to do (I made this in Photoshop, for illustration purposes)


I hope I am clearer now and that you would be able to help me :-)

Cheers,
Wiza

By the way, you can view this live site on http://www.communitypolicing.mw (I've made it live specifically for you)
« Last Edit: November 28, 2010, 12:33:45 PM by WizaJ »
Logged

Fred K

  • Still trying to learn stuff
  • ULTIMATE member
  • ******
  • Karma: 130
  • Posts: 2728
    • Personal
Re: Question: How to get sNews NOT to display article text in categories?
« Reply #3 on: November 28, 2010, 03:48:26 PM »

Wiza, it's quite easy to do. All you need is to put [break] at the beginning of each article. That way the category listings will only print the linked title (and the info line contents, assuming you use the info line, e.g post date, readmore link etc).
Logged

WizaJ

  • Newbie
  • *
  • Karma: 0
  • Posts: 5
Re: Question: How to get sNews NOT to display article text in categories?
« Reply #4 on: November 28, 2010, 03:59:23 PM »

Wiza, it's quite easy to do. All you need is to put [break] at the beginning of each article. That way the category listings will only print the linked title (and the info line contents, assuming you use the info line, e.g post date, readmore link etc).

 :-[ I feel like an idiot!
Should've seen that one coming, I guess I didn't really explore sNews that much to figure this out.
Uh, however I noted that inserting a [break] tag right at the beginning of an article doesn't have any effect so you still need to show one or two lines I guess? But anyway thanks a lot! I'll make do with this. sNews forever! 8)
Logged