how do i GET the article ID in a phpscript in template.tmpl?

Get help with installation and running phpwcms here. Please do not post bug reports or feature requests here.
Post Reply
fmaltez
Posts: 25
Joined: Sun 12. Mar 2006, 12:55

how do i GET the article ID in a phpscript in template.tmpl?

Post by fmaltez »

i have a phpscript in one of summary template

[template/inc_cntpart/articlesummary/userinfo.tmpl]---------------
(...)
[PHP]
include("config.php");
(...)
$sql_command="SELECT * FROM tablemysql WHERE id_page='".$_GET[id]."'";
(...)
[/PHP]
(...)
----------------------------------

the .$_GET[id]. variable render the full article code (1,11,0,0,1,0)....

what can i use to to get only the article tag (11)?

OR

how do i insert an article tag {SUB},{SUMMARY} in the PHP script?

like
$sql_command="SELECT * FROM tablemysql WHERE id_entidade='".{SUB}."'";


One of these solutions would help me a lot!
if anyone could help...
fmaltez
Posts: 25
Joined: Sun 12. Mar 2006, 12:55

Post by fmaltez »

i've change the code to

$sql_command="SELECT * FROM tablemysql WHERE id_page='".$_GET[entidade]."'";

and edited the .htaccess to

RewriteRule ^([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.([0-9]+)\.phtml$ index.php?id=$1,$2,$3,$4,$5,$6&entidade=$2

in the frontend everything is okay, but in the backend, the preview pages are index.php?id=.... so it doesnt work....

anybody have another (better) solution?
User avatar
jsw_nz
Posts: 907
Joined: Fri 2. Apr 2004, 02:42
Location: New Zealand

Post by jsw_nz »

hi there

not sure of the specifics of your call
- but in article summary templates
- there are a lot of globals that are already available

LIST Template
$id = {ARTICLEID};

Code: Select all

// ARTICLEID   = ID of list entry
[TITLE]<h1>{TITLE}</h1>[/TITLE]
<div class="entrymeta">{WAK_ARTICLE_CREATED:MEDIUM} | Category: {BREADCRUMB}</div> 
[PHP] 
$id = {ARTICLEID}; 
$query ="SELECT acontent_id FROM ".DB_PREPEND." phpwcms_articlecontent WHERE acontent_aid='$id' AND acontent_type='18'"; 
$result = mysql_query($query) or die(mysql_error()); 
$numRows =  mysql_num_rows($result); 
if($numRows>0){ 
   $row = mysql_fetch_array($result); 
   $guestbook_id = $row[0];
   $query ="SELECT COUNT(*) FROM ".DB_PREPEND." phpwcms_guestbook WHERE guestbook_cid='$guestbook_id' "; 
        $result = mysql_query($query) or die(mysql_error()); 
        $row = mysql_fetch_array($result); 
        $number = $row[0]; 
      mysql_free_result($result); 
      echo '<p><a class="comments-link" href="{ARTICLELINK}">Comments ('.$number.') Read More...</a></p>'; 
   }else{ 
      echo '<p><a class="read-link" href="{ARTICLELINK}"> Read More...</a></p>'; 
   } 
[/PHP]

FULL SUMMARY Template
$id = $GLOBALS['content']['article_id'];

Code: Select all

[TITLE]<h1>{TITLE}</h1>[/TITLE]
<div class="entrymeta">{WAK_ARTICLE_CREATED:MEDIUM} | Category: {BREADCRUMB}</div>
[PHP] 
$id = $GLOBALS['content']['article_id']; 
$query ="SELECT acontent_id FROM ".DB_PREPEND." phpwcms_articlecontent WHERE acontent_aid='$id' AND acontent_type='18'"; 
$result = mysql_query($query) or die(mysql_error()); 
$row = mysql_fetch_array($result);  
$guestbook_id = $row[0]; 
$query ="SELECT COUNT(*) FROM ".DB_PREPEND." phpwcms_guestbook WHERE guestbook_cid='$guestbook_id' "; 
     $result = mysql_query($query) or die(mysql_error()); 
     $row = mysql_fetch_array($result); 
     $number = $row[0];
  mysql_free_result($result); 
if($guestbook_id!=0){
echo "<div class=\"comments_fullarticle\">Comments (".$number.")</div>";
}
[/PHP]
Code above was used to show number of comments in article summary list and full - required some editing of content.func.inc.php

Hope this helps
:)
fmaltez
Posts: 25
Joined: Sun 12. Mar 2006, 12:55

Re: how do i GET the article ID in a phpscript in template.tmpl?

Post by fmaltez »

it did! sorry to didnt reply at the time!
thanks a lot!
Post Reply