PDA

View Full Version : Display all articles on home page


boccio
05-01-2006, 12:00 PM
This Mod allows having all categories and articles on home page.

1. index.php
Right after line 676 (// -- - main form -- //) place this snippet:

//*** display all articles ***
$column_view = 3;
$index_news_r = HTML_index($column_view);
$index_news_pattern = array();
for($i=1; $i<=sizeof($index_news_r); $i++){
$index_news_pattern[] = '/{COL_' . $i . '}/';
}

$category=new Category();
//$featured_news_HTML = HTML_latest_news(1);
//$latest_news_HTML = HTML_latest_news();
$index_template = "$tpl_folder/index.tpl";
/*
if ($featured_news_HTML = HTML_featured_news())
{
if (isset($ajax_script) && file_exists($ajax_script))
$java_scripts = "<script language=\"JavaScript\" src=\"{$url}{$ajax_script}\"></script>";
else
$java_scripts = "<script language=\"JavaScript\" src=\"{$url}include/ajax.js\"></script>";
}
*/
At line 847, right before:

$subject=preg_replace($pattern, $replacement, $subject);
place this snippet:

if (is_array($index_news_pattern))
$pattern = array_merge( $pattern, $index_news_pattern);
if (is_array($index_news_r))
$replacement = array_merge( $replacement, $index_news_r );

2. HTML_function.php
Add this code at the bottom of the file

//*** Show all articlces on home page ***//
function HTML_index($column_view = 3){
global $tpl_folder, $cur_date, $connection;
// show all categories and subs;
// fetch the number of active articles and split into columns;
// show all articles in category;
// set filter;
$filter = "status=1 and created<='$cur_date'";
$SQL = "SELECT count(id) FROM tblArticles WHERE $filter";
$result = mysql_query($SQL) or sql_error($SQL);
$article_num = mysql_result($result, 0);
$article_no = 0; // article counter
$column_no = 0;

$cat_list = SubCategoryList(0);
$categories = array();

$filename = $tpl_folder . "/index_category.tpl";
$subject = file_get_contents($filename);
$pattern = array( '{CATEGORY_LINK}', '{CATEGORY_NAME}', '{ARTICLES}' );

foreach($cat_list as $cat){
// query articles in category
$articles = '';
$SQL = "SELECT id FROM tblArticles WHERE category_id={$cat['id']} and $filter";
$result = mysql_query($SQL) or sql_error($SQL);
while ($row = mysql_fetch_assoc($result)){
$article = new Article();
$article->LoadFromDatebase($connection, $row['id']);
$article_link = HTML_show_friendly_url($row['id'], '');
// generate output:
$articles .= "<li><a href=\"{$article_link}\">{$article->Title}</a></li>";
$article_no ++;
}
$category_link = friendly_path($cat['id']);
$replacement = array( $category_link, $cat['category_name'], $articles );
$categories[$column_no] .= str_replace( $pattern, $replacement, $subject );
// if counter exceeds article # for a column
if ($article_no > (($article_num / $column_view) * ($column_no + 1))){
$column_no ++;
}
}

return $categories;

}
function SubCategoryList($cid, $level=0) {
$cat_list = array();
$level++;
$SQL = "SELECT id, category_name, parent_cat FROM tblCategories WHERE parent_cat={$cid} ORDER BY order_num";
$result = mysql_query($SQL) or sql_error ($SQL, "CategoryList");
while ($row = mysql_fetch_assoc($result)) {
$row['level'] = $level;
array_push($cat_list, $row);
if ($subcat_list = SubCategoryList($row['id'], $level)) {
$cat_list = array_merge($cat_list, $subcat_list);
}
}
return $cat_list;
}

3. index_category.tpl
Create index_category.tpl file in /templates folder to handle display of individual categories. Example:

<div class="trHeadline_right">
<div class="category_link_depth3">
<a href="{CATEGORY_LINK}">{CATEGORY_NAME}</a>
</div>
</div>
<div class="article">
<ul> {ARTICLES} </ul>
</div>
4. index.tpl
In order to have home page displaying all the articles (only), you need to change index.tpl in complete, so it's recommended to backup original index.tpl and make new one. Example:

<!-- index.tpl -->
<table width="780" cellspacing="0" cellpadding="0" border="0">
<tr>
<td height="30" bgcolor="#92B2CD" colspan="5">{BOX_SEARCH}</td>
</tr>
<tr>
<td width="150" valign="top" rowspan="3"> {BOX_SECTIONS}
{CALENDAR}
{BOX_SYNDICATION}
{BOX_NEWSLETTER}
{BOX_POLL}<br />
</td>
<td width="10" valign="top" rowspan="3"></td>
<td valign="top">
<table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" class="col" width="33%"><br />{COL_1}</td>
<td valign="top" class="col" width="33%"><br />{COL_2}</td>
<td valign="top" class="col" width="33%"><br />{COL_3}</td>
</tr>
</table></td>
</tr>
</table>
<!-- end index.tpl -->

5. style.css
Add the styles for articles and categories on the home page. This is something you'll most probably amend to fit your needs.

.article ul {
margin: 0;
padding: 3px;
list-style: none;
border-bottom: 0;
}

.article ul li {
margin: 0;
padding-bottom: 5px;
list-style: none;
border-bottom: 0;
font-size: 10px;
list-style-image: url(../img/arrow_red.gif);
}

.article ul li a {
color:#000000;
}

.article ul li a:hover {
color:#000000;
background-color: #f6f6f6;
}

.col {
padding-left: 0px;
border-left: 1px solid #999999;
}

Leea
05-23-2006, 09:22 PM
Hi there,
I have tried this hack on the 3,2 version and it doesn't work.
Boccio can you pls write it for 3,2 version to?
It seems very interesting.
Thanks
Regards,
Leea

boccio
06-09-2006, 04:30 PM
This is the mod for v3.2 version:

1. index.php
After line 602 (// -- - main form -- //) place the following snippet:

//*** display all articles ***
$column_view = 3;
$index_news_r = HTML_index($column_view);
$index_news_pattern = array();
for($i=1; $i<=sizeof($index_news_r); $i++){
$template_manager->assign($index_news_r[$i-1], '/{COL_' . $i . '}/');
}
$category=new Category();
//$featured_news_HTML = HTML_latest_news(1);
//$latest_news_HTML = HTML_latest_news();
$index_template = "$tpl_folder/index.tpl";
/*
if ($featured_news_HTML = HTML_featured_news()){
if (isset($ajax_script) && file_exists($ajax_script)){
$java_scripts = "<script language=\"JavaScript\" type=\"text/javascript\" src=\"{$url}{$ajax_script}\"></script>";
}else{
$java_scripts = "<script language=\"JavaScript\" type=\"text/javascript\" src=\"{$url}include/ajax.js\"></script>";
}
}
*/


2. HTML_function.php
Add this code at the bottom of the file:

//*** Show all articlces on home page ***//
function HTML_index($column_view = 3){
global $tpl_folder, $cur_date, $connection;
// show all categories and subs;
// fetch the number of active articles and split into columns;
// show all articles in category;
// set filter;
$filter = "status=1 and created<='$cur_date'";
$SQL = "SELECT count(id) FROM tblArticles WHERE $filter";
$result = mysql_query($SQL) or sql_error($SQL);
$article_num = mysql_result($result, 0);
$article_no = 0; // article counter
$column_no = 0;

$cat_list = SubCategoryList(0);
$categories = array();

$filename = $tpl_folder . "/index_category.tpl";
$subject = file_get_contents($filename);
$pattern = array( '{CATEGORY_LINK}', '{CATEGORY_NAME}', '{ARTICLES}' );

foreach($cat_list as $cat){
// query articles in category
$articles = '';
$SQL = "SELECT id FROM tblArticles WHERE category_id={$cat['id']} and $filter";
$result = mysql_query($SQL) or sql_error($SQL);
while ($row = mysql_fetch_assoc($result)){
$article = new Article();
$article->LoadFromDatebase($connection, $row['id']);
$article_link = HTML_show_friendly_url($row['id'], '');
// generate output:
$articles .= "<li><a href=\"{$article_link}\">{$article->Title}</a></li>";
$article_no ++;
}
$category_link = friendly_path($cat['id']);
$replacement = array( $category_link, $cat['category_name'], $articles );
$categories[$column_no] .= str_replace( $pattern, $replacement, $subject );
// if counter exceeds article # for a column
if ($article_no > (($article_num / $column_view) * ($column_no + 1))){
$column_no ++;
}
}

return $categories;

}
function SubCategoryList($cid, $level=0) {
$cat_list = array();
$level++;
$SQL = "SELECT id, category_name, parent_cat FROM tblCategories WHERE parent_cat={$cid} ORDER BY order_num";
$result = mysql_query($SQL) or sql_error ($SQL, "CategoryList");
while ($row = mysql_fetch_assoc($result)) {
$row['level'] = $level;
array_push($cat_list, $row);
if ($subcat_list = SubCategoryList($row['id'], $level)) {
$cat_list = array_merge($cat_list, $subcat_list);
}
}
return $cat_list;
}


3. index_category.tpl
Create new index_category.tpl file in /templates folder to handle display of individual categories. Example how this file should look:

<div class="trHeadline_right">
<div class="category_link_depth3">
<a href="{CATEGORY_LINK}">{CATEGORY_NAME}</a>
</div>
</div>
<div class="article">
<ul> {ARTICLES} </ul>
</div>


4. index.tpl
In order to make home page display all the articles, you need to change index.tpl in complete, so it is recommended to backup original index.tpl and make new one. Example:

<!-- index.tpl -->
<table width="780" cellspacing="0" cellpadding="0" border="0" align="center" class="white">
<tr>
<td width="150" valign="top" rowspan="3" class="leftColumn"> {BOX_SECTIONS}
{CALENDAR}
{BOX_SYNDICATION}
{BOX_NEWSLETTER}
{BOX_POLL}<br />
</td>
<td width="10" valign="top" rowspan="3"></td>
<td valign="top"><table cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top" class="col" width="33%"><br />{COL_1}</td>
<td valign="top" class="col" width="33%"><br />{COL_2}</td>
<td valign="top" class="col" width="33%"><br />{COL_3}</td>
</tr>
</table></td>
<td width="10" valign="top" rowspan="3"></td>
<td valign="top" width="150" rowspan="3" class="rightColumn"> {BOX_CATEGORY_HEADERS}
{BOX_MOST_POPULAR}
{BOX_MOST_COMMENTED}
{BOX_FEATURED_AUTHOR} </td>
</tr>
</table>
<!-- end index.tpl -->


5. style.css
Finally, add the styles for articles and categories on the home page. This is something you'll most probably amend to fit your needs.

.article ul {
margin: 0;
padding: 3px;
list-style: none;
border-bottom: 0;
}

.article ul li {
margin: 0;
padding-bottom: 5px;
list-style: none;
border-bottom: 0;
font-size: 10px;
list-style-image: url(../img/arrow_red.gif);
}

.article ul li a {
color:#000000;
}

.article ul li a:hover {
color:#000000;
background-color: #f6f6f6;
}

.col {
padding-left: 0px;
border-left: 1px solid #999999;
}

cicocico
09-25-2006, 12:58 PM
do not work!

superman
11-30-2006, 12:22 AM
can you show a demo...

SonNguyen
05-25-2007, 09:54 PM
And can u show it on version 3.4

UnionDance
09-23-2007, 08:24 PM
if you have a demo, that would be great.... but thanks :P