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 from a sNews newbie  (Read 4768 times)

bongda

  • Newbie
  • *
  • Karma: 0
  • Posts: 6
Question from a sNews newbie
« on: July 23, 2008, 11:21:27 pm »

First, this is the best CMS I think I will ever find. Kudos to all of you for such great works!
Hopefully, the new version of sNews will have a WYSIWYG text editor to make it even more awesome. (just my wish!!!)

After playing with it for a few weeks, I ran into a few problems; and I really hope that I can find out the answers from you guys.
1) On the home page of my company’s web site , we have a “Latest news” section, where we want to display the latest article in ONE specific category. (remember NOT just a latest article, BUT a latest article in one specific category)
Is there anyway for us to do that? I tried to scan through the codes in the engine; but it looks really confusing right now (didn’t work with PHP for a while)

I’m sorry if somebody else has already asked this question. I searched in the forum but couldn’t find it…
Thank you all
« Last Edit: July 24, 2008, 01:35:56 am by bongda »
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: Question from a sNews newbie
« Reply #1 on: July 24, 2008, 12:38:38 am »

I have few questions because I don't understand what you mean exactly:

First article from every category?
First article from only one category?
Recent articles from only ONE category?
Recent articles from every category?

I have something here.
Logged

bongda

  • Newbie
  • *
  • Karma: 0
  • Posts: 6
Re: Question from a sNews newbie
« Reply #2 on: July 24, 2008, 01:04:10 am »

ok , I have a Category called "ABC". I want to display ONLY the latest article in this category on the front page.  (You know, so we can do a quick update to our employees)
I don't know if there's anyway that I can do that
Does it make sense?
ALso, your site does look really nice, but it's not what I want

I guess my problem is to break down the function center () of sNews
« Last Edit: July 24, 2008, 01:28:30 am by bongda »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Question from a sNews newbie
« Reply #3 on: July 24, 2008, 03:42:23 am »

I have not tried this... but this is how I would try doing it.
For example... if your category has an ID of 3...

I would take a copy of function menu_articles (search for // MENU ARTICLES ) and paste it in below it, then re-name the function to function cat_three_articles.

Then I would modify the function so that it would return only the article links from category ID 3... adding the red part to the query string in the function... so it will now select articles (position = 1) that are published and have category ID of "3".

Quote
$query = "SELECT * FROM ".db('prefix')."articles WHERE position = 1 AND published = 1 AND category = 3 ORDER BY date DESC LIMIT $start, $size";

Then... where you want these articles listed in your template... just insert your new function-name:
     <?php cat_three_articles(0,3); ?>

There is one drawback with this... you must never delete this category or do anything to it that would change its ID number.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

Joost

  • Guest
Re: Question from a sNews newbie
« Reply #4 on: July 24, 2008, 03:45:21 am »

I guess my problem is to break down the function center () of sNews

I am not eager to work on function center either, so here is a nice workaround:

First: In index.php change center(); to $center();

Second: In snews.php, past the following code somewhere, somehow as long as it is after snews_startup();

Code: [Select]
<?php 

//===========================================================================
$center ='center';
if(empty(
$_GET) && empty($_POST)) $center 'front_page';

#FUNCTION FRONT_PAGE (paste it somewhere)
function front_page($cat=1){
 
$sql 'SELECT title, text, `date` FROM '.db('prefix').'articles WHERE category = '.$cat.' AND published = 1 ORDER BY `date`DESC LIMIT 1'
$r=mysql_fetch_row(mysql_query($sql));
$output =
'<h2>%s</h2>
%s
<p  class="date">%s</p>'
;
$text str_replace('[break]'''$r[1]);
$date date(s('date_format'), strtotime($r[2]));
printf$output$r[0], $text$date);}
//===========================================================================

?>

EXPLANATION:

Center (in index.php) has become a variable function. If no $_GET request is send (pretty uris, admin things) or $_POST
(login, search, updates) function front_page() is executed instead of function center
This implies, that you can tweak the frontpage content anyway you want (css styling, data display,  etc.).

I kept it very simple, so you have to look up the category id in the database (table categories) and add it manually in the function.
function front_page($cat=1).
« Last Edit: July 25, 2008, 02:34:07 am by Keyrocks »
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: Question from a sNews newbie
« Reply #5 on: July 24, 2008, 03:53:56 am »

OR,

You must apply to your sNews this mod first.


Then, you must create a static page then set it as front page. Then edit the page and insert the Joost function [func]front_page:|:id_of_your_category[/func]

This way, your front page can contain your wanted article plus anything you want.
Logged

bongda

  • Newbie
  • *
  • Karma: 0
  • Posts: 6
Re: Question from a sNews newbie
« Reply #6 on: July 24, 2008, 09:19:17 am »

first of, thanks a lot guys
That was a lot of helps there

I tried Joost way; but it didn't do anything..it just displayed a blank page. (i do want to display the article in the Cateogry 1 by the way)
it seemed like the SQL query to fetch the article was not working...
Logged

Joost

  • Guest
Re: Question from a sNews newbie
« Reply #7 on: July 24, 2008, 04:33:17 pm »

first of, thanks a lot guys
That was a lot of helps there

I tried Joost way; but it didn't do anything..it just displayed a blank page. (i do want to display the article in the Cateogry 1 by the way)
it seemed like the SQL query to fetch the article was not working...

Did you change it to category needed? Lacking accurate info, I used category one as an example.
Logged

bongda

  • Newbie
  • *
  • Karma: 0
  • Posts: 6
Re: Question from a sNews newbie
« Reply #8 on: July 24, 2008, 06:38:12 pm »

I didn't have to change the code; because the category that I want is Category #1. I checked that in the PHP-MyAdmin...Was I doing sth wrong ?
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Question from a sNews newbie
« Reply #9 on: July 24, 2008, 09:18:31 pm »

I didn't have to change the code; because the category that I want is Category #1. I checked that in the PHP-MyAdmin...Was I doing sth wrong ?

Joost's function works for me OK.
Did you go into index.php and add a $ sign to center(); so that it looks like $center(); ?
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

bongda

  • Newbie
  • *
  • Karma: 0
  • Posts: 6
Re: Question from a sNews newbie
« Reply #10 on: July 24, 2008, 10:59:29 pm »

I DID. So it worked for you ? I will check back on my code one more time
thanks
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
Re: Question from a sNews newbie
« Reply #11 on: July 25, 2008, 02:37:41 am »

I DID. So it worked for you ? I will check back on my code one more time
thanks

Have look at Joost's posted code (above) again. Perhaps you inadvertently copied the opening <?php tag at the top... or the closing ?> tag at the bottom... and pasted it into your file along with the actual script. If you did... the server will stop parsing (reading) code right there and nothing else will happen. To make it a bit clearer... copy only the script that is in between the two orange commented strings I added in there (to make it clearer). It's gotta work man.  ;D

PS: We often add those PHP tags at the start and end of a block of code when we post it here so the code will display in color. Never copy them along with code when you copy from code blocks in posts... unless they are within HTML code that is being copied.
« Last Edit: July 25, 2008, 02:40:17 am by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

bongda

  • Newbie
  • *
  • Karma: 0
  • Posts: 6
Re: Question from a sNews newbie
« Reply #12 on: July 26, 2008, 01:14:25 am »

You're RIGHT keyrocks...It's working for me now
Man, that was a silly mistake  :P

One more question:
Is there a version of sNews that store data on a flat file, instead of the MySQL database ?
My company is trying to restricting more databases on the server now
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab
Re: Question from a sNews newbie
« Reply #13 on: July 26, 2008, 01:48:22 am »

@Equilni have one but unfinished (I don't know what mean"unfinished" because I had no time to test it). But you can give it a try.

I can't find it right now :( ....
Logged

Joost

  • Guest
Re: Question from a sNews newbie
« Reply #14 on: July 26, 2008, 02:38:32 am »

It is not a good idea to use a unfinished product  in a production environment.
But if you do have a database running, you can create snews tables in there. Make use of the prefix.

Prefix all tablenames, something like:
snews1_settings
snews1_articles
snews1_categories
snews1_extras

In snews.php add the prefix to database variables like:
 $db['prefix'] = 'snews1_'; //Database prefix
That way, you don't need an extra database, you can even install several systems that way using a different prefix (snews2_).
Logged