sNews Forum

sNews 1.6 (previous version) => Mods/addons => Topic started by: H.A.C on November 07, 2007, 05:15:31 pm

Title: [MOD] Show In Front
Post by: H.A.C on November 07, 2007, 05:15:31 pm
miniMOD: Show In Front
Description:
I have a site with many categories (for example: they are softwares, scripts, ebooks and help). I want to display all newly added articles of softwares, scripts, ebooks and I don't want the newly added articles of help showed on home (I turn on "show on home" feature and all the articles from all categories show). If I use "hidden articles mod", the articles are absolutely hidden. But i still want my articles in help are listed in sitemap, in search and in help when visitor clicks help category and so on.

This is the situation with my own site at http://www.chasoft.net. And this is my solution, very simple. Hope it useful to someone. This is my solution for my need. And if it don't fit your needs, you can extend it.

To use this mod, you have to enable "show on home" feature in admin panel and enable "show in front" feature (in customize section) when you create a new article. And I think this mod is compatible to "hidden article mod" because if you turn on "hidden feature" then it will just override my mod.

Okie, let's go.

1. database change

Code: [Select]
--standard mysql query
ALTER TABLE `articles` ADD `show_in_front` char(3) NOT NULL DEFAULT 'YES'

Code: [Select]
--mysql query using table PREFIX_
ALTER `TABLE PREFIX_articles` ADD `show_in_front` char(3) NOT NULL DEFAULT 'YES'

2. language variable (snews.php)
- it will be used inside administration page

Code: [Select]
$l['show_in_front'] = 'Show the article in front page';
3a. // ARTICLES FORM
add this line
Quote
      echo html_input('checkbox', 'show_in_front', 'dt', 'YES', l('show_in_front'), '', '', '', '', $frm_show_in_front, '', '', '', '', '');
just above
Quote
   echo html_input('checkbox', 'display_title', 'dt', 'YES', l('display_title'), '', '', '', '', $frm_display_title, '', '', '', '', '');

3b. // ARTICLES FORM (newly added part- thanks armen for his reply)

locate this:
Code: [Select]
$frm_publish = $r['published'] == 1 ? 'ok' : '';
just above, add this line
Code: [Select]
$frm_show_in_front = $r['show_in_front'] == 'YES' ? 'ok' : '';
4. /*** PROCESSING (CATEGORIES, CONTENTS, COMMENTS) ***/
just below this line
Quote
     $display_title = $_POST['display_title'] == 'on' ? 'YES' : 'NO';
add this
Quote
   $show_in_front = $_POST['show_in_front'] == 'on' ? 'YES' : 'NO';


5. /*** PROCESSING (CATEGORIES, CONTENTS, COMMENTS) ***/
Find and add the text in blue
Quote
                  case(isset($_POST['add_article'])):
                  mysql_query("INSERT INTO ".db('prefix')."articles(title, seftitle, text, date, category, position, displaytitle, displayinfo, commentable, published, description_meta, keywords_meta, show_in_front) VALUES('$title', '$seftitle', '$text', '$date', '$category', '$position', '$display_title', '$display_info', '$commentable', '$publish_article', '$description_meta', '$keywords_meta', '$show_in_front')");
                  break;   
                  case(isset($_POST['edit_article'])):
                  if ($fpost_enabled == true) {$future = " date = '$date',";}
                  mysql_query("UPDATE ".db('prefix')."articles SET title='$title', seftitle = '$seftitle', text = '$text',".$future." category = '$category', position = '$position', displaytitle = '$display_title', displayinfo = '$display_info', commentable = '$commentable', published = '$publish_article', description_meta = '$description_meta', keywords_meta = '$keywords_meta', show_in_front = '$show_in_front' WHERE id = '$id' LIMIT 1;");

6. // CENTER
Quote
         if (s('display_new_on_home') == 'on') {$query_articles .= $use_cat_id != 0 ? " AND category = $use_cat_id" : ' AND show_in_front = "YES"';}
         else {$query_articles .= " AND category = $use_cat_id";}

That's all.
Title: Re: [MOD] Show In Front
Post by: Armen on November 08, 2007, 11:35:24 am
1. You forgot this:

In // ARTICLES FORM, above

Code: [Select]
$frm_publish = $r['published'] == 1 ? 'ok' : '';
You need to add:

Code: [Select]
$frm_show_in_front = $r['show_in_front'] == 'YES' ? 'ok' : '';
To display correct status of the checkbox when editing an existing article.

2. And in SQL strings with 'prefix_':

It should be:

Code: [Select]
alter table prefix_articles add show_in_front char(3) NOT NULL Default 'NO' ;

Set NO or YES as you like.

Old string gives an error because of unnessesary quotes.

Thank you for your mod and a perfect idea how to manage my newest project.
Title: Re: [MOD] Show In Front
Post by: H.A.C on November 08, 2007, 02:56:30 pm
Armen, thanks for your reply. I missed that line of code. I'll update my post at once.
Title: Re: [MOD] Show In Front
Post by: Armen on November 08, 2007, 05:34:34 pm
One more thing which will help to identify "show_in_front" marked artcles in admin article list:

So it would look like this:

  Articles ---------------------------------------------------------------------
  article1 View Edit
  article2 View Edit Status: Show in front page
  article3 View Edit

Step-by-step:

Add language variable:

Code: [Select]
$l['frontpage'] = 'Show in front page';
Find:

Code: [Select]
if ($r['published'] == 0) {echo  l('divider').' ['.l('status').' '.l('unpublished').']';}
And right after it insert:

Code: [Select]
if ($r['show_in_front'] == "YES") {echo  l('divider').' ['.l('status').' '.l('frontpage').']';}
Title: Re: [MOD] Show In Front
Post by: codetwist on December 13, 2007, 04:29:26 pm
Excellent MOD - provides for basic control over what is promoted to entry page (home) and what's not right at site editor hands. No need for tricks at index.php.

P.S. Thanx Ayesseline for reminding (http://snewscms.com/forum/index.php?topic=6462.msg43565#msg43565) of this one.
Title: Re: [MOD] Show In Front
Post by: piXelatedEmpire on December 13, 2007, 11:48:38 pm
what an excellent MOD, cheers HAC well done :)
Title: Re: [MOD] Show In Front
Post by: Martin2007 on December 26, 2007, 03:59:46 am
I am reading this MOD and quite interested and am willing to implement. I just one question. When you choose "show in front" for an article:

1. Does it gets transfered from the intended category to the "home" category?
2. If I applied the [break] in composing the article will this be recognized when shown in front?

I will appreciate a reply for this wonderful MOD.

Martin
Title: Re: [MOD] Show In Front
Post by: codetwist on December 26, 2007, 09:32:49 am
1. No, it doesn't get transfered to different category.
2. [break] as well works as usual.

Only and intended change will be that not all but just 'show in front' articles from all categories will be shown at home. Without this mod all articles from all categories will be shown on home. With this mod You simply have control of what is being shown on home.
Title: Re: [MOD] Show In Front
Post by: Martin2007 on December 26, 2007, 12:59:51 pm
Thanks codetwist for your reply. That is helpful. What if I am using another customized page like Frontpage as Home (that I created through sNews but hide it from the navigation menu pages, will this feature take effect as well? Thanks for any reply.

Martin
Title: Re: [MOD] Show In Front
Post by: codetwist on December 26, 2007, 01:41:30 pm
If that is a custom sNews page then You will need more modifications developed/used for articles to appear on it.
Title: Re: [MOD] Show In Front
Post by: mfaraklit on March 20, 2008, 09:28:55 am
what exactly i want is to show new articles according to categories in Front page(home). ( for example have 3 categories and then draw a table width 3 cols. and showing them according to cats)
Title: Re: [MOD] Show In Front
Post by: Keyrocks on March 20, 2008, 01:18:01 pm
what exactly i want is to show new articles according to categories in Front page(home). ( for example have 3 categories and then draw a table width 3 cols. and showing them according to cats)

You could take a look at the code in the Sitemap function. It displays links to articles by category. You could likely create a custom function using the sitemap code for the bits you need.
Title: Re: [MOD] Show In Front
Post by: jackp on March 24, 2008, 05:06:59 am
Ahhh...

See all you have to do is look. Will implement this mod right away as it is EXACTLY what I have been looking for. sNews is just getting better every minute.

Thanks HAC for creating this Mod and everyone else for extra fixes. Am happy now. (almost)

Jackp
Title: Re: [MOD] Show In Front
Post by: slemborg on April 29, 2009, 10:54:52 pm
Old topic, but I also need a mod like this and will try it out, hopefully it works with snews 1.7
Title: Re: [MOD] Show In Front
Post by: slemborg on April 30, 2009, 01:11:50 am
I tried, but it didn't work for me in sNews 1.7
Title: Re: [MOD] Show In Front
Post by: Joost on April 30, 2009, 01:39:36 am
I tried, but it didn't work for me in sNews 1.7

It is part of 1.7
Title: Re: [MOD] Show In Front
Post by: slemborg on April 30, 2009, 02:00:04 am
Doh.. my bad, thanks for the reply though.