amitos
01-20-2005, 11:01 AM
Here's how you display the 5 recently added articles in a panel.
Step 1: Copy the following code and paste it into a text editor and save it as LatestArticlesPanel.php
<?php
/*******************************************\
* *
* Generic ArticleLive Panel Parsing Class *
* *
\*******************************************/
$panelClass = "AL_LATESTARTICLESPANEL_PANEL";
CLASS AL_LATESTARTICLESPANEL_PANEL
{
var $_htmlFile;
function AL_LATESTARTICLESPANEL_PANEL($HTMLFile)
{
$this->_htmlFile = $HTMLFile;
}
function ParsePanel()
{
$htmlPanelData = "";
$parsedPanelData = "";
if(file_exists($this->_htmlFile))
{
if($fp = @fopen($this->_htmlFile, "rb"))
{
while(!feof($fp))
$htmlPanelData .= fgets($fp, 4096);
@fclose($fp);
}
}
// Parse the panel of tokens, etc
$numArticles = 0;
$GLOBALS["LatestArticleList"] = $this->_GetLatestArticleList($numArticles);
if($numArticles > 0)
$GLOBALS["HideNoLatestArticles"] = "none";
$parsedPanelData = $GLOBALS["AL_CLASS_TEMPLATE"]->ParseGL($htmlPanelData);
return $parsedPanelData;
}
function _GetLatestArticleList(&$NumArticles)
{
$date_today = time();
// Get a list of Latest articles and return them as an ordered list
$output = "";
$query = "SELECT * FROM ArticleLive_articles AS articles WHERE articles.Visible = '1' AND articles.Status = '1' AND unix_timestamp(articles.StartDate) <= $date_today and IsFinished=1 and (unix_timestamp(ExpiryDate) >= $date_today or EnableExpiry=0) ORDER BY articles.StartDate DESC LIMIT 5";
$articleResult = mysql_query($query);
if(mysql_num_rows($articleResult) > 0)
$output .= "<ol>";
while($articleRow = mysql_fetch_array($articleResult))
{
if(AL_HELPER::ArticleIsLive($articleRow["ArticleID"]) && $NumArticles < 5)
{
if($articleRow["Type"] == 3)
{
$output .= sprintf("
<li>
<A target='_blank' href='%s'>
%s
</A>
</li>
", AL_HELPER::ArticleLink($articleRow["ArticleID"], $articleRow["Title"]), $articleRow["Title"]);
}
else
{
$output .= sprintf("
<li>
<A href='%s'>
%s
</A>
</li>
", AL_HELPER::ArticleLink($articleRow["ArticleID"], $articleRow["Title"]), $articleRow["Title"]);
}
$NumArticles++;
}
}
if(mysql_num_rows($articleResult) > 0)
$output .= "</ol>";
return $output;
}
}
?>
Step 2: Next, copy the html code below into a text editor and save the file as LatestArticlesPanel.html
<TABLE class="Panel LatestArticlesPanel" id="Table2">
<TR>
<TD class="Heading">Latest Articles</TD>
</TR>
<TR>
<TD class="Content">
%%GLOBAL_LatestArticleList%%
<div style="display: %%GLOBAL_HideNoLatestArticles%%">%%LNG_hpNoLatestArticles%%</div>
</TD>
</TR>
</TABLE>
Step 3: Upload the 2 files into the respective template panels folder.
Step 4: To show it on your site, insert either %%Panel.LatestArticlesPanel%% into Default.html or whicever page you wanna display latest articles.
OR
To make it appear on all pages on the right hand column....download DefaultRightColumnPanel.php and add the following:
$parsedPanelData .= $GLOBALS["AL_CLASS_TEMPLATE"]->_GetPanelContent("LatestArticlesPanel");
Good luck trying!! You can view an example at my site: www.SouthAsianConnection.com
Amit
Step 1: Copy the following code and paste it into a text editor and save it as LatestArticlesPanel.php
<?php
/*******************************************\
* *
* Generic ArticleLive Panel Parsing Class *
* *
\*******************************************/
$panelClass = "AL_LATESTARTICLESPANEL_PANEL";
CLASS AL_LATESTARTICLESPANEL_PANEL
{
var $_htmlFile;
function AL_LATESTARTICLESPANEL_PANEL($HTMLFile)
{
$this->_htmlFile = $HTMLFile;
}
function ParsePanel()
{
$htmlPanelData = "";
$parsedPanelData = "";
if(file_exists($this->_htmlFile))
{
if($fp = @fopen($this->_htmlFile, "rb"))
{
while(!feof($fp))
$htmlPanelData .= fgets($fp, 4096);
@fclose($fp);
}
}
// Parse the panel of tokens, etc
$numArticles = 0;
$GLOBALS["LatestArticleList"] = $this->_GetLatestArticleList($numArticles);
if($numArticles > 0)
$GLOBALS["HideNoLatestArticles"] = "none";
$parsedPanelData = $GLOBALS["AL_CLASS_TEMPLATE"]->ParseGL($htmlPanelData);
return $parsedPanelData;
}
function _GetLatestArticleList(&$NumArticles)
{
$date_today = time();
// Get a list of Latest articles and return them as an ordered list
$output = "";
$query = "SELECT * FROM ArticleLive_articles AS articles WHERE articles.Visible = '1' AND articles.Status = '1' AND unix_timestamp(articles.StartDate) <= $date_today and IsFinished=1 and (unix_timestamp(ExpiryDate) >= $date_today or EnableExpiry=0) ORDER BY articles.StartDate DESC LIMIT 5";
$articleResult = mysql_query($query);
if(mysql_num_rows($articleResult) > 0)
$output .= "<ol>";
while($articleRow = mysql_fetch_array($articleResult))
{
if(AL_HELPER::ArticleIsLive($articleRow["ArticleID"]) && $NumArticles < 5)
{
if($articleRow["Type"] == 3)
{
$output .= sprintf("
<li>
<A target='_blank' href='%s'>
%s
</A>
</li>
", AL_HELPER::ArticleLink($articleRow["ArticleID"], $articleRow["Title"]), $articleRow["Title"]);
}
else
{
$output .= sprintf("
<li>
<A href='%s'>
%s
</A>
</li>
", AL_HELPER::ArticleLink($articleRow["ArticleID"], $articleRow["Title"]), $articleRow["Title"]);
}
$NumArticles++;
}
}
if(mysql_num_rows($articleResult) > 0)
$output .= "</ol>";
return $output;
}
}
?>
Step 2: Next, copy the html code below into a text editor and save the file as LatestArticlesPanel.html
<TABLE class="Panel LatestArticlesPanel" id="Table2">
<TR>
<TD class="Heading">Latest Articles</TD>
</TR>
<TR>
<TD class="Content">
%%GLOBAL_LatestArticleList%%
<div style="display: %%GLOBAL_HideNoLatestArticles%%">%%LNG_hpNoLatestArticles%%</div>
</TD>
</TR>
</TABLE>
Step 3: Upload the 2 files into the respective template panels folder.
Step 4: To show it on your site, insert either %%Panel.LatestArticlesPanel%% into Default.html or whicever page you wanna display latest articles.
OR
To make it appear on all pages on the right hand column....download DefaultRightColumnPanel.php and add the following:
$parsedPanelData .= $GLOBALS["AL_CLASS_TEMPLATE"]->_GetPanelContent("LatestArticlesPanel");
Good luck trying!! You can view an example at my site: www.SouthAsianConnection.com
Amit