Revision: 22 July 2007 (added a
link to downloadable, already modified snews.php files)
Mod version: 2.0.0
For sNews version 1.6.0
Example: leading text on
this page is the content of additional article position which can be accomplished with this mod.
It all started with
keyrocks' post about creating a new article position in sNews 1.4 which you could then use for really anything - as keyrocks points out: "to list several product containers in one specific Category's page(s)... say Products... as sort of a lite e-commerce option"
Or any other extra content for a specific category or page, like for example a category description above the list of articles (like I use it on the above example page) or a small square box with a short announcement somewhere on top of your page...
Encouraged with a success in 1.4 I thought it couldn't be that hard to pull this off in 1.5.
And it took me awhile before I figured out how some things worked in 1.5 and I think it was worth the trouble as I did figure out (I think

) how some things work, eventually, and I even learned many new PHP functions

Also, I think I have finally learned to place ";" at the end of each PHP line...
And now I had to update this mod for the newest version of sNews, sNews 1.6.0.
In making of this mod I went down this route:
I had an intention to use the extra() function as a template for any subsequent article position I'd like to have on my website because while default extra content in sNews is really useful, I could only add it in one place on my website layout. And I needed different extra contents to be on different places in my website's layout and that was only possible by duplicating sNews default extra function to make a new extra function.
Note that these are really short step-by-step instructions of everything you need to change in your snews.php to get a new article position. You can even download the snews.php file taken from the fresh install of the sNews 1.6 (dev. ver. 1.6.0 Stable) and already modified to include this mod from
domdelimar.com if you don't want to follow these instructions.
Here, changes are always shown in blue color.
Unless otherwise noted, all the work is done in your snews.php file. There is no need to modify the MySQL database.
I don't guarantee anything so make sure you BACKUP your website just in case...OK, shall we?
Find the extra function [search for:
function extra], and right below that function paste this code:
function second_extra($styleit = 0, $classname = '', $idname= '') {
$categorySEF = get_id('category');
$categoryId = (check_category($categorySEF) == true || empty($categorySEF) || $categorySEF == l('home_sef')) ? 0 : retrieve('id', 'categories', 'seftitle', $categorySEF);
$pageSEF = get_id('article');
$pageId = (empty($categorySEF)) ? 0 : retrieve('id', 'articles', 'seftitle', $pageSEF);
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) = '9' AND published = 1 ORDER BY id DESC";
$result = mysql_query($query);
while ($r = mysql_fetch_array($result)) {
$pos = $r['position']; $pos_depend = substr($pos, 1, 1); $pos_artID = substr($pos, 2);
switch (true) {
case ($pos_depend == 0 && $categoryId == 0): $print = true; break;
case ($pos_depend == 1 && $categoryId == $pos_artID): $print = true; break;
case ($pos_depend == 2 && $pageId == $pos_artID): $print = true; $category = -1; break;
case ($pos_depend != '2' && $r['category'] == -1): $print = true; break; default: $print = false;
}
if ($print == true) {
if ($styleit == 1) {
$container ='<div';
$container .= !empty($classname) ? ' class="'.$classname.'"' : '';
$container .= !empty($idname) ? ' id="'.$idname.'"' : '';
$container .= '>';
echo $container;
}
echo $r['displaytitle'] == 'YES' ? '<h3>'.$r['title'].'</h3>' : '';
file_include($r['text'], 9999000);
echo $_SESSION[db('website').'Logged_In'] == token() ? '<p><a href="'.db('website').'index.php?action=admin_article&id='.$r['id'].'" title="'.l('edit').' '.$r['seftitle'].'">'.l('edit').'</a></p>' : '';
if ($styleit == 1) {echo '</div>';}
}}}
This is actually a copy of the function extra with minor changes shown in blue color.
Short explanation: after you apply this mod and every time you create a Second Extra Content, it will be denoted with a position field value (in MySQL database) starting with number 9. In default sNews 1.6 there are three positions: position field with value of 1 denotes an article, position field with a value of 3 denotes a page and a position field with a value which starts with number 2 denotes an extra content.
Now, let's add some admin language variables that we'll need later:
Search for:
#SYSTEM VARIABLESAnd just a line above the #SYSTEM VARIABLES, add these three admin language variables, like this:
$l['second_extra_contents'] = 'Second Extra contents';
$l['second_extra_new'] = 'New Second Extra Contents';
$l['second_side'] = 'Second Extra contents';
#SYSTEM VARIABLES (not to be translated)
We're not over yet with the language variables...
Just two lines
below #SYSTEM VARIABLES, you'll notice a long line that starts with:
$l['cat_listSEF'] =
We need to add the following 2 new values at the end of that long array of variables:
second_extra_new and
second_extra_contents
If you didn't tamper with this line before, you can just replace it completely with this one: (I had to break this line into 3 lines so it wouldn't break the layout of this forum page and you should put it back together once you paste it in your snews.php file)
$l['cat_listSEF'] = $l['home_sef'].',archive,contact,sitemap,rss-articles,rss-pages,rss-comments,
login,administration,admin_category,admin_article,article_new,extra_new,page_new,categories,
articles,extra_contents,pages,settings,files,logout,second_extra_new,second_extra_contents'; //SEF links of the hardcoded categories
Now we need to change the
function center().
Search for
function center().
In center function find this line:
case 'extra_contents': admin_articles('extra_view'); return; break;
Right below this line add the following:
case 'second_extra_contents': admin_articles('second_extra_view'); return; break;
Just a few lines below, you'll see this line:
case 'extra_new': form_articles('extra_new'); return; break;
Now, below this line add the following line:
case 'second_extra_new': form_articles('second_extra_new'); return; break;
Then, several lines below, you'll find this line that says:
$query_articles = "SELECT * FROM ".db('prefix')."articles WHERE published = 1 AND SUBSTRING(position, 1, 1) != '2'";
We need to extend this line a bit to look like this:
$query_articles = "SELECT * FROM ".db('prefix')."articles WHERE published = 1 AND SUBSTRING(position, 1, 1) != '2' AND SUBSTRING(position, 1, 1) != '9'";
That's all we need to do with the center function.
Next thing you do, locate
function search(). Once you locate it, several lines inside from the start of this function, you'll find this line:
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND published = 1 AND";
We need to modify this line to look like this:
$query = "SELECT * FROM ".db('prefix')."articles WHERE SUBSTRING(position, 1, 1) != '2' AND SUBSTRING(position, 1, 1) != '9' AND published = 1 AND";
Now search for:
function stats($field, $position)This function starts with:
if (!empty($position)) {$pos = $position == 2 ? " WHERE ...
Well, it needs to start like this (I really wasn't sure about this but it worked at the end so I might have not done a bad job modifying this function):
if (!empty($position)) {$pos = $position == (2 || 9) ? " WHERE ...
Can you see the difference? - change it accordingly.
Now search for
function administration()In this function locate the following line:
if (stats('articles',2) > 0) {echo $link.'extra_contents/" title="'.l('view').'">'.l('view').'</a>';}
Now, right after this line, add this chunk of code:
echo '</p>';
echo '<p>'.l('second_extra_contents').': <a href="second_extra_new/" title="'.l('add_new').'">'.l('add_new').'</a>';
if (stats('articles',9) > 0) {echo $link.'second_extra_contents/" title="'.l('view').'">'.l('view').'</a>';}
Next thing you do is search for the
function form_articles($contents). In this function we'll do the most of our modifying...
First find the part of the code that starts with
switch ($edit_option). It looks like this:
switch ($edit_option) {
case 1: $frm_fieldset = l('edit').' '.l('article'); $frm_position1 = 'selected="selected"'; break;
case 2: $frm_fieldset = l('edit').' '.l('extra_contents'); $frm_position2 = 'selected="selected"'; break;
case 3: $frm_fieldset = l('edit').' '.l('page'); $frm_position3 = 'selected="selected"'; break;
}
Just after the
case 3: line, insert this line of code:
case 9: $frm_fieldset = l('edit').' '.l('second_extra_contents'); $frm_position9 = 'selected="selected"'; break;
There's another switch several lines below, which starts with
switch ($contents). Similarly to the last switch, we'll add one more case line:
case 'second_extra_new': $frm_fieldset = l('second_extra_new'); $pos = 9; $frm_position9 = 'selected="selected"'; break;
Just nine lines below this switch statement, there's another line we need to modify...
$frm_display_info = ($contents == 'extra_new') ? '' : 'ok';
... to look like this:
$frm_display_info = ($contents == 'extra_new' || $contents == 'second_extra_new') ? '' : 'ok';
Two lines below, a very similar thing. This is the line:
$frm_commentable = ($contents == 'extra_new' || $contents == 'page_new') ? '' : 'ok';
And it needs to be modified so it looks like this:
$frm_commentable = ($contents == 'extra_new' || $contents == 'second_extra_new' || $contents == 'page_new') ? '' : 'ok';
If you scroll a bit more down, you'll notice this chunk of code:
if ($contents == 'extra_new' || $edit_option == 2) {
echo '<div style="display: none;">';
html_input('text', 'seftitle', 'as', $frm_sef_title, l('sef_title'), '', '', '', '', '', '', '', '', '', '');
echo '</div>';
}
You need to change the first line of this chunk of code to this:
if ($contents == 'extra_new' || $edit_option == 2 || $contents == 'second_extra_new' || $edit_option == 9) {
Next, find this part of the code a little bit further below:
if ($contents != 'page_new' && $edit_option != 3) {
Two lines below, you'll find this line:
echo ($contents == 'extra_new' || $edit_option == 2) ? l('appear_category') : l('category');
which needs to be changed into this:
echo ($contents == 'extra_new' || $edit_option == 2 || $contents == 'second_extra_new' || $edit_option == 9) ? l('appear_category') : l('category');
Two lines below, almost the same thing. The line which starts with
if ($contents == 'extra_new' || $edit_option == 2) {echo '<option value="-1"'
needs to be changed into:
if ($contents == 'extra_new' || $edit_option == 2 || $contents == 'second_extra_new' || $edit_option == 9) {echo '<option value="-1"'.($article_category == -1 ? ' selected="selected"' : '').'>'.l('all').'</option>';}
The line after that one also needs to be changed. It's a line that starts with:
echo '<option value="0"'.(($article_category == 0 && $contents != 'extra_new') ?
and it needs to be modified like this:
echo '<option value="0"'.(($article_category == 0 && $contents != 'extra_new' && $contents != 'second_extra_new') ? ' selected="selected"' : '').'>'.l('home').'</option>';
Now, several lines below, there's another
if statement. It starts like this:
if ($contents == 'extra_new' || $edit_option == 2) {
echo '<p id="def_page"><label for="dp">'.l('appear_page').':</label>
<select name="define_page" id="dp">';
First line of that if statement needs to be changed to this:
if ($contents == 'extra_new' || $edit_option == 2 || $contents == 'second_extra_new' || $edit_option == 9) {
Third line of the same if statement,
echo '<option value="0"'.($edit_option != '2' ? ' selected="selected"' : '').'>'.l('all').'</option>';
needs to look like this now:
echo '<option value="0"'.($edit_option != '2' && $edit_option != '9' ? ' selected="selected"' : '').'>'.l('all').'</option>';
Oh my... just a little more... and we're done!
If you scroll down just a little bit more you'll notice this chunk of code:
if (!empty($id)) {
echo '<p><label for="pos">'.l('position').':</label>
<select name="position" id="pos">';
echo '<option value="1"'.$frm_position1.'>'.l('center').'</option>';
echo '<option value="2"'.$frm_position2.'>'.l('side').'</option>';
echo '<option value="3"'.$frm_position3.'>'.l('display_page').'</option>';
echo '</select></p>';
}
After the line starting with
echo '<option value="3"
insert the following line of code:
echo '<option value="9"'.$frm_position9.'>'.l('second_side').'</option>';
Then just a few lines below you'll notice one
if statement:
if ($contents != 'extra_new' && $edit_option != '2') {
echo html_input('text', ...
You need to change only the first line of it into this:
if ($contents != 'extra_new' && $edit_option != '2' && $contents != 'second_extra_new' && $edit_option != '9') {
Hmm, after this one, there's another one:
if ($contents != 'extra_new' && $edit_option != '2') {
echo html_input('checkbox', ...
Again, change just the first line of it into this:
if ($contents != 'extra_new' && $edit_option != '2' && $contents != 'second_extra_new' && $edit_option != '9') {
Finally, we're done with this function. Sorry, not yet with the whole script - just 6 more little changes... smile
Search for:
function admin_articles($contents)You see the
switch ($contents) { line there followed by 3
case lines?
You just need to add the fourth case line (after the third one):
case 'second_extra_view': $title = l('second_extra_contents'); $subquery = "WHERE SUBSTRING(position,1,1) = '9'"; break;
Now we need to fiddle with
function processing()...
First, inside the function processing(), we find a line of code that says:
if ($position == 2) {$position = $_POST['cat_dependant'] == 'on' ? 21 : 2;}
And after this line of code, we insert this one:
elseif ($position == 9) {$position = $_POST['cat_dependant'] == 'on' ? 91 : 9;}
Now search for
case 'admin_article' inside
function processing()This is the code you should see:
case 'admin_article';
if (substr($position, 0, 1) == 2) {
$category = $_POST['define_category'];
$page = $_POST['define_page'];
if ($category != -1) {$position = '21'.$category;}
else if ($page != 0) {$position = '22'.$page; $category = -1;}
}
Immediately after this code insert the following snippet of the code:
elseif (substr($position, 0, 1) == 9) {
$category = $_POST['define_category'];
$page = $_POST['define_page'];
if ($category != -1) {$position = '91'.$category;}
else if ($page != 0) {$position = '92'.$page; $category = -1;}
}
Finally, just a little bit further below you will find the LAST part of snews.php file that we need to change. Whooaa!!
It's this code:
$pos = substr($position, 0, 1);
switch ($pos) {case 1: $link = 'articles'; break; case 2: $link = 'extra_contents'; break; case 3: $link = 'pages'; break;}
The line starting with
switch ($pos) needs to be changed into the following:
switch ($pos) {case 1: $link = 'articles/'; break; case 2: $link = 'extra_contents/'; break; case 3: $link = 'pages/'; break; case 9: $link = 'second_extra_contents/'; break;}
All that is left to do now is decide where you'd want this new extra content to be shown on your website.
For example, I put mine right above the center function call (in index.php):
<div id="left">
<? second_extra(); ?>
<? center(); ?>
</div>
But you can place yours anywhere else.
Log into your Admin area and there should be something new under Extra contents:
Second Extra Content or whatever you called it. Try adding a new Second Extra Content now!
Please report here if anything seems out of place or not working. I think I've tested it enough to say it should work fine now.