| Author |
Message |
al3loo
Joined: 04 Aug 2007 Posts: 60
|
|
How can I numbering news ? |
|
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
Regards,
|
|
| Wed Jul 23, 2008 8:42 pm |
|
 |
Guest
|
|
|
Please login to hide the ads.
|
|
|
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1843 Location: US |
|
|
|
Use something like this for your php news include:
 |  | <ol><?php
$number = "5";
$template = "numbered";
include("admin/show_news.php");
?></ol> |
Use something like this in your 'numbered' or similar template:
 |  | <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
last update: 07-22-08: 8:30 pm |
|
| Thu Jul 24, 2008 12:40 am |
|
 |
al3loo
Joined: 04 Aug 2007 Posts: 60
|
|
|
|
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:
 |  | /*----------------------------------------------------------*/
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:
 |  | $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
Regards,
|
|
| Fri Jul 25, 2008 2:21 am |
|
 |
eberswine

Joined: 26 Apr 2007 Posts: 131
|
|
|
|
al3loo
if all you are after is to make your website present the following:
 |  | 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 :
 |  | {id} | {title} | {views} |
*** thats it | make sure to clear your CACHE ***
|
|
| Sat Jul 26, 2008 3:43 pm |
|
 |
al3loo
Joined: 04 Aug 2007 Posts: 60
|
|
|
|
thank you for your try!
But be sure it's not what I mean ..
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 
|
|
| Sat Jul 26, 2008 4:14 pm |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1843 Location: US |
|
|
|
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
last update: 07-22-08: 8:30 pm |
|
| Sun Jul 27, 2008 3:05 pm |
|
 |
FI-DD
Admin

Joined: 22 Sep 2005 Posts: 2736 Location: Germany |
|
|
|
1. In inc/show.news.php change this:
 |  | foreach ($query as $bg => $row){ |
to this:
 |  | $news_number = (($skip and $skip != 0) ? $skip : 0);
foreach ($query as $bg => $row){
$news_number++; |
2. Find this:
 |  | $output = str_replace('{id}', $row['id'], $output); |
and add below:
 |  | $output = str_replace('{news_number}', $news_number, $output); |
Now you can use {news_number} in your template.
|
|
| Tue Jul 29, 2008 5:37 pm |
|
 |
scottdallas

Joined: 04 May 2006 Posts: 1843 Location: US |
|
|
|
Oh that is awesome. Of course you'd figure it out FI-DD... I had this feeling I'm going to add that to my cnr when I get home just to have it 
_________________ www.scottdizzle.com uses cnr
last update: 07-22-08: 8:30 pm |
|
| Wed Jul 30, 2008 5:12 pm |
|
 |
al3loo
Joined: 04 Aug 2007 Posts: 60
|
|
|
|
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
You are dangerous !
|
|
| Wed Aug 06, 2008 10:03 pm |
|
 |
|