Page 1 of 3

{NEWCATID}

Posted: Sun 23. Nov 2003, 15:45
by oops
headlines from category

Code: Select all

function get_new_articles_from_catid($template_default, $max_cnt_links=0, $cid=0, $dbcon) {
	// find all new articles

	$max_cnt_links = intval($max_cnt_links);
	$limit = ($max_cnt_links) ? " LIMIT ".$max_cnt_links : "";

	$sql =	"SELECT article_id, article_title, article_cid, UNIX_TIMESTAMP(article_tstamp) AS article_date ".
			"FROM ".DB_PREPEND."phpwcms_article WHERE ".
			"article_cid='$cid' AND article_public=1 AND article_aktiv=1 AND article_deleted=0 AND ".
			"article_begin < NOW() AND article_end > NOW() ".
			"ORDER BY article_tstamp DESC".$limit.";";

	// new articles list
	$new_links = "";
	$target = ($template_default["link_target"]) ? ' target="'.$template_default["link_target"].'"' : "";
	if($result = mysql_query($sql, $dbcon)) {
		$count_results = mysql_num_rows($result); $count = 0;
		while ($row = mysql_fetch_row($result)) {
			$count++;
			if($template_default["link_length"] && strlen($row[1]) > $template_default["link_length"]) {
				$article_title = substr($row[1], 0, $template_default["link_length"]).$template_default["cut_title_add"];
			} else {
				$article_title = $row[1];
			}
			if(trim($template_default["date_format"])) {
				$article_title = international_date_format(
									$template_default["date_language"], 
									$template_default["date_format"], 
									$row[3]).$article_title;
			}
			$new_links .= $template_default["link_before"].$template_default["link_symbol"];
			$new_links .= '<a href="index.php?id='.$row[2].','.$row[0].',0,0,1,0"';
			$new_links .= $target.">".html_specialchars($article_title)."</a>";
			
			//try to remove possible unwanted after - if not enclosed before.link.after
			if($new_links && !$template_default["link_before"] && $count < $count_results) {
				$new_links .= $template_default["link_after"];
			}
		}
		mysql_free_result($result);
	}

	//enclose whole
	if($new_links) $new_links = $template_default["before"].$new_links.$template_default["after"];
	
	return $new_links;
}

Code: Select all

if( ! ( strpos($content["all"],'{NEWCATID:')===false ) ) {
	$content["all"] = preg_replace('/\{NEWCATID:(\d+):(\d+)\}/e','get_new_articles_from_catid($template_default["news"],$1,$2,$db);',$content["all"]);
}
replacement tag: {NEWCATID:max_count_links:cid}

Posted: Mon 9. Feb 2004, 20:46
by isac
oops,

Can you show an example or explain

Thank's
Isac

Posted: Tue 10. Feb 2004, 18:07
by Jenpet
I would test it, but I don't know where to put it. Sounds good, but a few explanations would be great ! ;) Looking forward to them

Posted: Thu 12. Feb 2004, 08:33
by oops
code one: add to /include/inc_front/front.func.inc.php
code two: add to /include/inc_front/content.func.inc.php

replacement tag: {NEWCATID:max_count_links:category_id}

Posted: Thu 12. Feb 2004, 11:51
by isac
Thank's oops

Posted: Thu 12. Feb 2004, 17:52
by Jan212
thanks, that's awesome. easy ...

Posted: Sat 3. Apr 2004, 17:29
by argos
Can someone please explain what this thing does? Or show an example?

Posted: Sat 3. Apr 2004, 18:01
by Jan212
this replacement tag shows the last created articles from the category you change over the CID - the max_count_links is the number of links which will be displayed instead of the replacement tag...

Posted: Sat 3. Apr 2004, 19:10
by argos
I see... Thanks alot!

Posted: Sat 3. Apr 2004, 19:11
by Jan212
no problemo

Parse error

Posted: Fri 9. Jul 2004, 14:32
by hetgasbedrijf
Hi there,

Great looking script, but i can't seem to get it to work.

This is wat i get:

Parse error: parse error in /home/gasbedrijf/hetgasbedrijf.nl/html/clienten/cms/include/inc_front/front.func.inc.php on line 30

Fatal error: Call to undefined function: get_struct_data() in /home/gasbedrijf/hetgasbedrijf.nl/html/clienten/cms/include/inc_front/content.func.inc.php on line 38

Can somebody help me...

Regards

Check for spaces

Posted: Tue 13. Jul 2004, 17:35
by mom2nine
Check to see if you have extra white spaces at the end of the code you added, that can cause this kind of error. I added both sections of code to the pages he listed, and got errors like this the first time. I deleted the extra space after the end of the code and saved it and the errors went away.

Still can't figure out how to get the categories to display the articles listed...so even though the code is in there, I don't know how to use it. I added {NEWCATID:max_count_links:cid} after the {CONTENT} code and all I see is the code...

Posted: Tue 13. Jul 2004, 21:16
by hetgasbedrijf
hi mom2nine,

Thanks! Still working on my code. I Thinks the solution to your problem is NOT to use:

{NEWCATID:max_count_links:cid}

but to use for example

{NEWCATID:5:nameofthecategory}

I hope it helps :-)

Posted: Tue 13. Jul 2004, 21:25
by mom2nine
Thank you, I will give that a try!!

Modified replacement tag for newcatid

Posted: Fri 16. Jul 2004, 10:10
by nichri
mom2nine wrote:Thank you, I will give that a try!!
I found this new replacement tag very useful but then found out that I would rather get it a bit modified to show me the articles in all categories (from the whole cms) instead.

Here it is, I hope it is useful for somebody :)

Code: Select all

// +-------------------------------------------------+
// | Include in include/inc_front/front.func.inc.php |
// +-------------------------------------------------+

function get_new_articles_from_all($template_default, $max_cnt_links=0,
$dbcon) {
   // find all new articles

   $max_cnt_links = intval($max_cnt_links);
   $limit = ($max_cnt_links) ? " LIMIT ".$max_cnt_links : "";

   $sql =   "SELECT article_id, article_title, article_cid,
UNIX_TIMESTAMP(article_tstamp) AS article_date ".
         "FROM ".DB_PREPEND."phpwcms_article WHERE ".
         "article_public=1 AND article_aktiv=1 AND article_deleted=0 AND
".
         "article_begin < NOW() AND article_end > NOW() ".
         "ORDER BY article_tstamp DESC".$limit.";";

   // new articles list
   $new_links = "";
   $target = ($template_default["link_target"]) ? '
target="'.$template_default["link_target"].'"' : "";
   if($result = mysql_query($sql, $dbcon)) {
      $count_results = mysql_num_rows($result); $count = 0;
      while ($row = mysql_fetch_row($result)) {
         $count++;
         if($template_default["link_length"] && strlen($row[1]) >
$template_default["link_length"]) {
            $article_title = substr($row[1], 0,
$template_default["link_length"]).$template_default["cut_title_add"];
         } else {
            $article_title = $row[1];
         }
         if(trim($template_default["date_format"])) {
            $article_title = international_date_format(
                           $template_default["date_language"],
                           $template_default["date_format"],
                           $row[3]).$article_title;
         }
         $new_links .=
$template_default["link_before"].$template_default["link_symbol"];
         $new_links .= '<a
href="index.php?id='.$row[2].','.$row[0].',0,0,1,0"';
         $new_links .=
$target.">".html_specialchars($article_title)."</a>";

         //try to remove possible unwanted after - if not enclosed
         //before.link.after
         if($new_links && !$template_default["link_before"] && $count <
$count_results) {
            $new_links .= $template_default["link_after"];
         }
      }
      mysql_free_result($result);
   }

   //enclose whole
   if($new_links) $new_links =
$template_default["before"].$new_links.$template_default["after"];

   return $new_links;
}

Code: Select all

// +---------------------------------------------------+
// | include in include/inc_front/content.func.inc.php |
// +---------------------------------------------------+

if( ! ( strpos($content["all"],'{NEWALL:')===false ) ) {
   $content["all"] =
preg_replace('/\{NEWALL:(\d+)\}/e','get_new_articles_from_all($template_default["news"],$1,$db);',$con
tent["all"]);

}
use it like {NEWALL:no_of_latest_articles_to_be_shown} i.e. {NEWALL:10} gets the latest 10 articles from the whole site.