Forum Index
RegisterSearchFAQMemberlistUsergroupsLog in
How can I numbering news ?

 
Reply to topic    Forum Index » Suggestions View previous topic
View next topic
How can I numbering news ?
Author Message
al3loo



Joined: 04 Aug 2007
Posts: 60

Post How can I numbering news ? Reply with quote
Hi All,

I want my news auto numbered i.e:
{id-num} | {title} | {views}
1 | news1 | 25
2 | news2 | 45
3 | news3 | 21


I tried to configure some code in template and add {id-num} code and edit show.news.php but I failed, hope someone know a little in php do it for me Wink




Regards,
Wed Jul 23, 2008 8:42 pm View user's profile Send private message
Guest








Please login to hide the ads.

scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post Reply with quote
Use something like this for your php news include:

Code:
<ol><?php
$number = "5";
$template = "numbered";
include("admin/show_news.php");
?></ol>


Use something like this in your 'numbered' or similar template:

Code:
<li> | {title} | {views}</li>


p.s. Did you mean you just wanted them numbered like 1, 2, 3, 4, 5, etc? Or did you want the actual news ID # to the left of the news? My method is for generic numbering.

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Thu Jul 24, 2008 12:40 am View user's profile Send private message Visit poster's website AIM Address
al3loo



Joined: 04 Aug 2007
Posts: 60

Post Reply with quote
Thank you for your help my dear ..
But, I'm facing one little problem with this nice method. if I have more than one page, that numbering will be just like decoration ..

Now, I noticed something in comment could help me in this code, what we need is a php code..

I tried this code of numbering comments and change it to be compatible with the news numbering

What I did was copying the code from show.comments.php to show.news.php

Here is the last adjusting of the code:
Code:
/*----------------------------------------------------------*/
      if ($config_reverse_news == 'yes'){
            $csort = array('date', 'DESC');
         } else {
            $csort = array('date', 'ASC');
         }
         
         if (!$number){
            $number = $sql->table_count('news');
         }
      $query = $sql->select(array(
             'table'   => 'news',
             'where'   => array("category = $id"),
             'orderby' => $csort,
             'limit'   => array(($skip ? $skip : 0), $number)
       ));
      
       $count = count($sql->select(array('table' => 'news', 'where' => array("category = $id"))));
      if ($config_reverse_news == 'yes'){
         $cjnumber = ($skip ? (($count + 1) - $skip) : $count + 1);
      } else {
         $cjnumber = (($skip and $skip != 0) ? $skip : 0);
      }      
      $output = str_replace('{id-num}', $cjnumber, $output);
/*-------------------------------------------------*/


Also, I add this:
Code:
$config_reverse_news = "no";

in config.php

I hope you can help me to adjust it, I think there is a problem in connecting with the Database
Also, there is one variable I didn't know how to change it ($id) ..
I'm very poor in php and sql Embarassed


Regards,
Fri Jul 25, 2008 2:21 am View user's profile Send private message
eberswine



Joined: 26 Apr 2007
Posts: 131

Post Reply with quote
al3loo

if all you are after is to make your website present the following:
Code:
I want my news auto numbered i.e:
{id-num} | {title} | {views}
1 | news1 | 25
2 | news2 | 45
3 | news3 | 21


Then just go to the "manage templates" section and put this :
Code:
{id} | {title} | {views}


*** thats it | make sure to clear your CACHE ***
Sat Jul 26, 2008 3:43 pm View user's profile Send private message
al3loo



Joined: 04 Aug 2007
Posts: 60

Post Reply with quote
Laughing thank you for your try!

But be sure it's not what I mean .. Wink
I mean: I want every {title} in every category numbered with generic numbers but I want it continue counting when I go to another page, just like the comments.
The scottdallas idea was incredible !

If you asked me why this {id} not what you need?
I'm saying, because this ID number is an auto increment number in data, and if I delete one of the articles the number will be missing as well as the muddle of the numbers (ID) shown in each category.


I need someone knows a little in php Rolling Eyes
Sat Jul 26, 2008 4:14 pm View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post Reply with quote
Oh I see.. when you hit page 2 and above it's going to start numbering from 1, 2, 3, 4, 5, 6, etc all over again and it isn't going to make sense to the visitor.

Hmmm I don't know how to do this but I'm sure someone will figure this out.

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Sun Jul 27, 2008 3:05 pm View user's profile Send private message Visit poster's website AIM Address
FI-DD
Admin


Joined: 22 Sep 2005
Posts: 2736
Location: Germany

Post Reply with quote
1. In inc/show.news.php change this:
Code:
foreach ($query as $bg => $row){


to this:
Code:
$news_number = (($skip and $skip != 0) ? $skip : 0);

foreach ($query as $bg => $row){

   $news_number++;


2. Find this:
Code:
$output = str_replace('{id}', $row['id'], $output);


and add below:
Code:
$output = str_replace('{news_number}', $news_number, $output);


Now you can use {news_number} in your template.
Tue Jul 29, 2008 5:37 pm View user's profile Send private message
scottdallas



Joined: 04 May 2006
Posts: 1843
Location: US

Post Reply with quote
Oh that is awesome. Of course you'd figure it out FI-DD... I had this feeling Razz I'm going to add that to my cnr when I get home just to have it Wink

_________________
www.scottdizzle.com uses cnr Smile
last update: 07-22-08: 8:30 pm
Wed Jul 30, 2008 5:12 pm View user's profile Send private message Visit poster's website AIM Address
al3loo



Joined: 04 Aug 2007
Posts: 60

Post Reply with quote
I just did it with the old code, I was just should move the code to the top and its done !!
But this code really nice man, thank you very very much Very Happy

Cool You are dangerous !
Wed Aug 06, 2008 10:03 pm View user's profile Send private message
Display posts from previous:    
Reply to topic    Forum Index » Suggestions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to: 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Powered by phpBB © 2001, 2005 phpBB Group
Design by Freestyle XL / Music Lyrics.