{NEWCATID}

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
oops
Posts: 35
Joined: Tue 18. Nov 2003, 01:14
Contact:

{NEWCATID}

Post 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}
User avatar
isac
Posts: 410
Joined: Tue 18. Nov 2003, 13:13
Location: Portugal
Contact:

Post by isac »

oops,

Can you show an example or explain

Thank's
Isac
Jenpet
Posts: 74
Joined: Fri 6. Feb 2004, 15:43

Post 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
oops
Posts: 35
Joined: Tue 18. Nov 2003, 01:14
Contact:

Post 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}
User avatar
isac
Posts: 410
Joined: Tue 18. Nov 2003, 13:13
Location: Portugal
Contact:

Post by isac »

Thank's oops
Jan212
Posts: 859
Joined: Wed 28. Jan 2004, 21:38
Location: Solingen
Contact:

Post by Jan212 »

thanks, that's awesome. easy ...
argos
Posts: 135
Joined: Mon 15. Mar 2004, 20:02

Post by argos »

Can someone please explain what this thing does? Or show an example?
Regards,
Jurgen Nijhuis
http://www.argosmedia.nl
Jan212
Posts: 859
Joined: Wed 28. Jan 2004, 21:38
Location: Solingen
Contact:

Post 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...
Regards/ Grüsse/ Groetjes - JAN212
------------------------------------------------
null212 - Büro für Kommunikation und Design
------------------------------------------------
Lyrikfetzen des Tages
1. Ist der Quelltext auch valide fragt Herr Müller ganz perfide.
2. Wat is dat een lekker ding.
3. Wer Vision hat soll zum Arzt gehen.
------------------------------------------------
argos
Posts: 135
Joined: Mon 15. Mar 2004, 20:02

Post by argos »

I see... Thanks alot!
Regards,
Jurgen Nijhuis
http://www.argosmedia.nl
Jan212
Posts: 859
Joined: Wed 28. Jan 2004, 21:38
Location: Solingen
Contact:

Post by Jan212 »

no problemo
Regards/ Grüsse/ Groetjes - JAN212
------------------------------------------------
null212 - Büro für Kommunikation und Design
------------------------------------------------
Lyrikfetzen des Tages
1. Ist der Quelltext auch valide fragt Herr Müller ganz perfide.
2. Wat is dat een lekker ding.
3. Wer Vision hat soll zum Arzt gehen.
------------------------------------------------
hetgasbedrijf
Posts: 4
Joined: Fri 9. Jul 2004, 14:29

Parse error

Post 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
mom2nine
Posts: 9
Joined: Mon 12. Jul 2004, 18:52
Location: Virginia, USA
Contact:

Check for spaces

Post 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...
hetgasbedrijf
Posts: 4
Joined: Fri 9. Jul 2004, 14:29

Post 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 :-)
mom2nine
Posts: 9
Joined: Mon 12. Jul 2004, 18:52
Location: Virginia, USA
Contact:

Post by mom2nine »

Thank you, I will give that a try!!
nichri
Posts: 8
Joined: Sun 11. Jul 2004, 15:39

Modified replacement tag for newcatid

Post 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.
nichri
Post Reply