View Full Version : MOD Display new links on index page
Mod by "Vincent Wright"
Here is a quick mod that displays new links on index page. But first, let me explain how it works. It uses the same mechanism to display a list of links that is used in any subcategory. But instead of subcategory links we substitute new links. Only slight changes are necessary to achieve the effect.
Ok, let's jump straight to the gory details.
1. Open index.php in your directory script root folder. Go to the very bottom. Right before the last two lines of code:
$gDirSmarty->display("index{$templ}.tpl");
?>
insert this snippet:
if (0 == $category['id'])
{
$new_links =& $gDirDb->getNewLinks(0, 5);
$gDirSmarty->assign_by_ref('links', $new_links);
$gDirSmarty->assign('show_as_new', true);
}
The condition 0 == $category['id'] means this is ROOT category, or index page. In the block below new links are fetched. I used 5 as the number of new links to return from getNewLinks() function call. You can vary this number if you need more or less new links on index page.
The next two lines assign Smarty variables. An important variable here is 'show_as_new' -- this is a flag to differentiate between regular and new links because the same template is used to display both. Well, it's use is described below. Read on....
... but before, save changes to index.php and close the file.
2. The next step is to slightly adjust template file. Go to your template folder. By default it is templates/GreenLeaves. Open index.tpl file.
Find the piece of code that displays links. In my distribution it is line 20 and starts like this:
{if $links}
<div class="box">
<div class="box-caption-right">
<div class="box-caption-left">
<div class="box-caption">{$lang.links}</div>
</div>
</div>
<div class="box-content">
The line in bold gets replaced with the line below (in bold as well):
{if $links}
<div class="box">
<div class="box-caption-right">
<div class="box-caption-left">
<div class="box-caption">{if $show_as_new}{$lang.new_links}{else}{$lang.links}{/if}</div>
</div>
</div>
<div class="box-content">
You see, we only had to change one line of code in the template file to complete this mod. This line displays block title correctly -- "Links" for regular pages (subcategory pages) and "New Links" for index page.
Save changes, close the index.tpl file and give it a try!
Is it what you wanted to see? Yes? Great! :)
P.S.
If you have trouble implementing this mod feel free to ask.
Vasily B.
06-07-2006, 09:50 AM
I have just sticked this thread. It seems to be useful
David Marshall
11-25-2006, 09:50 PM
Excellent info,have just used this with version 2.0.01 and works great.........
http://linkerman.com
Cris Santos
12-05-2006, 03:28 PM
Having problem with this mod in my v.2 greenleaves template.
I have the following layout :
{if $category.id == 0} my article {/if}
<div>{if $links}
{if $show_as_new}{$lang.new_links}{else}{$lang.links}{/if}
</div>
{if $category.id == 0} my 2nd article {/if}
All worked fine til i added this mod.
Now i'm getting the following error :
Fatal error: Smarty error: [in index.tpl line 94]: syntax error: unclosed tag {if} (opened line 34). (Smarty_Compiler.class.php, line 320) in /home/cristina/public_html/news/smarty/Smarty.class.php on line 1095
Thing is, all {if}'s are closed...why is smarty not recognizing this?
Dave Baker
12-05-2006, 03:58 PM
Hello Cris,
This modification made for version 2.0:
http://www.esyndicat.com/forum/about7600.html
Please try to check it.
Cris Santos
12-05-2006, 04:14 PM
Hi Dave - The mod you mention doesnt work for me since, as explained, the links should appear in the middle of the index (between 2 articles)...
David Marshall made it work...
Anybody??
Dave Baker
12-05-2006, 07:17 PM
It seems the code selected with red color is "unclosed tag"
{if $category.id == 0} my article {/if}
<div>{if $links}
{if $show_as_new}{$lang.new_links}{else}{$lang.links}{ /if}
</div>
{if $category.id == 0} my 2nd article {/if}
Maybe your code must be similar to the following:
{if $category.id == 0} my article {/if}
<div>{if $links}
{if $show_as_new}{$lang.new_links}{else}{$lang.links}{ /if}
{/if}</div>
{if $category.id == 0} my 2nd article {/if}
Joe Boxer
12-19-2006, 11:21 PM
Very nice mod, thanks.
Joe
webvivre
02-21-2007, 07:59 PM
How can we have this feature in v2.1?
Shunny
02-23-2007, 07:17 PM
Yes this is a feature I am looking for too can someone give the details for 2.1.01
Dave Baker
02-23-2007, 10:10 PM
***Open index.php and find code(at the bottom of the file)***
// if unique template _not_ exists, then reset to default
if(!file_exists($gDirSmarty->template_dir.$render))
{
$render = "index.tpl";
}
***Below add***
if ($category['id'] == 0)
{
loadClass("DirLink");
$Link = &new Link;
$listings = $Link->getLatest(0, 10);
$gDirSmarty->assign_by_ref('listings', $listings);
}
***Save changes***
***Open template/yourTemplate/index.tpl and find code****
{if $neighbour_categories}
<!-- neighbour categories box start -->
{include file="box-header.tpl" caption=$lang.neighbour_categories style="green"}
<div class="categories">{$neighbour_categories}</div>
{include file="box-footer.tpl"}
<!-- neighbour categories box end -->
{/if}
***Below add***
{if $listings}
{include file="box-header.tpl" caption=$lang.new_links style="green"}
<table cellspacing="0" cellpadding="0">
{foreach from=$listings item=link name=links}
{include file="link-display.tpl"}
{/foreach}
</table>
{include file="box-footer.tpl"}
{/if}
***Save file***
joimplers
02-23-2007, 10:16 PM
Hell0 i would like to know how to do to put the "new links" section on a right column on my site for the acqua template, thanks. :)
joimplers
02-23-2007, 10:17 PM
anyone? i need this as soon as posible
thanmks
Shunny
02-23-2007, 10:28 PM
Hey Dave I just tried this and dont have a directory anymore
Dave Baker
02-23-2007, 10:28 PM
AFAIK acqua template does not have a right column.
Dave Baker
02-23-2007, 10:29 PM
Shunny, please send me PM your ftp credentials.
Shunny
02-23-2007, 10:46 PM
Okay thanks Dave
Shunny
02-23-2007, 11:02 PM
Dave how to get only 3 or 5 showing not 10 as I can see now
Dave Baker
02-23-2007, 11:06 PM
Shunny, please check your directory now. I don't know how it was connected with my modification, but was missed {/if} tag in code:
{if $categories}
<!-- categories box start -->
{include file="box-header.tpl" caption=$lang.categories style="center"}
{$categories}
{include file="box-footer.tpl"}
<!-- categories box end -->
{/if}
Shunny
02-23-2007, 11:08 PM
My mistake thanks Dave
Dave Baker
02-23-2007, 11:11 PM
***Replace with the following code***
if ($category['id'] == 0)
{
loadClass("DirLink");
$Link = &new Link;
$listings = $Link->getLatest(0, 5);
$gDirSmarty->assign_by_ref('listings', $listings);
}
5 - number of links
Shunny
02-23-2007, 11:19 PM
Perfect now Dave..You are the Champ...Thanks again !!!!
joimplers
02-24-2007, 04:08 AM
Could anyone help me with this:
i would like to know how to put "new links"
in a right (third) column.
I will really apreciate it, thanks.
joimplers
02-24-2007, 01:46 PM
Hey someone can help me on this??
Dave Baker
02-25-2007, 03:06 PM
hello joimplers,
It's very difficult modification, because "Aqua" template does not have right column. Try to contact with WTM (http://www.esyndicat.com/forum/member.php?u=2307), may be he'll help you.
omaron
02-25-2007, 04:28 PM
Is any way to put instead new links random links on popular links?
I think will need to change the variable here: $Link = &new Link;
But i am not sure. Any ideeas?
Thanks
Dave Baker
02-25-2007, 06:52 PM
Hello omaron,
For random links you should use this code:
if ($category['id'] == 0)
{
loadClass("DirLink");
$Link = &new Link;
$listings = $Link->getRandom(10);
$gDirSmarty->assign_by_ref('listings', $listings);
}
For popular links you should use this code:
if ($category['id'] == 0)
{
loadClass("DirLink");
$Link = &new Link;
$listings = $Link->getPopular(0, 10);
$gDirSmarty->assign_by_ref('listings', $listings);
}
Do not forget to change your caption in templates/yourTemplate/index.tpl according to your type of links.
{include file="box-header.tpl" caption=$lang.popular_links style="green"}
or
{include file="box-header.tpl" caption=$lang.random_links style="green"}
easydesigngroup
02-27-2007, 08:29 PM
I integrated to show up the latest 3 links.
They are showing./
But there is a problem at "link details"
The created link is:
http://www.domain.com/Internet/Web-designWebsite-templates-l3.html
and should be:
http://www.domain.com/Internet/Web-design/Website-templates-l3.html
What to change and where?
Thanks.
Tilek E.
02-28-2007, 01:01 PM
But there is a problem at "link details" What to change and where?
Hi easydesigngroup,
I have fixed that bug. Please take a look at this thread (http://www.esyndicat.com/forum/showthread.php?p=59795#post59795).
kamy81
03-19-2007, 01:43 AM
I applied Patch patch 2.1.02 and using template "GreenLeaves" .
Please help me to add 10 new links on home page bellow the categories section and also i want to show only the main categories on home page
Tilek E.
03-19-2007, 12:48 PM
Hi kamy81,
In order to apply the mod "New Links on Home" please make the following changes:
#1. Open index.php file and insert the highlighted code like this:
// if unique template _not_ exists, then reset to default
if(!file_exists($gDirSmarty->template_dir.$render))
{
$render = "index.tpl";
}
//get latest links
$latest_links = $Link->getLatest($start, 10); // number of links = 10
$gDirSmarty->assign_by_ref('latest_links', $latest_links);
$gDirSmarty->display($render, $cache_id);
#2. Save changes and close the file.
#3. Open index.tpl file and insert the following code where you want the latest links to be displayed:
<!-- latest links box start -->
{if $latest_links}
{include file="box-header.tpl" caption="New Links" style="green"}
<div class="links">
<table cellspacing="0" cellpadding="0">
{foreach from=$latest_links item=link name=links}
{assign var="latest_links" value=0}
{include file="link-display.tpl"}
{/foreach}
</table>
</div>
{include file="box-footer.tpl"}
{/if}
<!-- latest links box end -->
#4. Save changes and close the file.
#5. Open link-display.tpl and find the following code:
{if $config.mod_rewrite}
<a href="{$config.base}{$config.dir}{$link.path}{convert_st r string=$link.title}-l{$link.id}.html">{$lang.link_details}</a>
{else}
<a href="{$config.base}{$config.dir}view-link.php?id={$link.id}">{$lang.link_details}</a>
{/if}
#6. Replace the code you found with the following code:
{if $config.mod_rewrite}
{if $tab eq 'home'}
<a href="{$config.base}{$config.dir}{if $latest_links}{$link.path}{else}{$link.path|cat:"/"}{/if}{convert_str string=$link.title}-l{$link.id}.html">{$lang.link_details}</a>
{else}
<a href="{$config.base}{$config.dir}{$link.path}{convert_st r string=$link.title}-l{$link.id}.html">{$lang.link_details}</a>
{/if}
{else}
<a href="{$config.base}{$config.dir}view-link.php?id={$link.id}">{$lang.link_details}</a>
{/if}
#7. Save changes and close the file.
That's it!
Please feel free to ask in case you have any questions.
kamy81
03-20-2007, 02:10 AM
Thanks David Evans.
New links showing on home page - its Working.
But it is also showing in every category pages. Actually in category page I don't want to show this. New links will show only for home page .
Another thing is - from category when I click on Link Details it open correctly as:
domain.com/Business/Employment/South-Business-Employment-Corporation-l1.html
But when I click on Link Details of any new list links from homepage it show error as "Error: Requested URL not found (404)" it miss / as:
domain.com/Business/EmploymentSouth-Business-Employment-Corporation-l1.html
5 & 6 steps : Modification for (link-display.tpl ) is it a part of showing new links on homepage
OR for showing only Main category in home page
ok i followed the instructions to the letter and they work for me perfectly thanks!!!
ksgboy2
03-22-2007, 12:17 PM
Hi Dave
How to make showing new links just on home page not on all categories pages
ksgboy2
03-22-2007, 12:46 PM
Nermind I found solution
Tilek E.
03-22-2007, 02:08 PM
Hi kamy81,
If you have some difficulties with implementing this mod you can provide me your FTP credentials via PM and I help you to apply it.
Steps #5 and #6 help you to avoid the problem with wrong URLs to Link Details page. Maybe this is a reason of missing '/' in your site.
Tilek E.
03-22-2007, 02:19 PM
Also I think it will be useful to have the latest links shown only on homepage:
Just change the step #3 and insert the highlighted code:
<!-- latest links box start -->
{if $category.id eq '0'}
{if $latest_links}
{include file="box-header.tpl" caption="New Links" style="green"}
<div class="links">
<table cellspacing="0" cellpadding="0">
{foreach from=$latest_links item=link name=links}
{assign var="latest_links" value=0}
{include file="link-display.tpl"}
{/foreach}
</table>
</div>
{include file="box-footer.tpl"}
{/if}
{/if}
<!-- latest links box end -->
kamy81
03-22-2007, 03:24 PM
Thanks David Evans. Excellent job :applause:
Its very helpful for me
Loren
03-22-2007, 07:21 PM
Whats the difference between these codes, New links in index and new links on home?
Is it just terminology? or is there a difference in how these two sets of codes work? And if someone would be so kind to help me and others out direct to an working example of these, being specific as to what area, as i don't know what i am looking for..
Cheers :good:
kamy81
03-23-2007, 04:51 AM
Hi Loren,
Difference between these codes,
New links in index: It shows new links on homepage, category page, new link page, top link page, popular link page, etc (where link shows as indexing)
New links on homepage: It shows new links only on homepage
Tilek E.
03-23-2007, 11:07 AM
Thanks David Evans. Excellent job :applause:
Its very helpful for me
I'm glad to be of any use to you. :)
thanks that modification for home page only perfect - i was needing that for some time now :)
PassionSeed
04-12-2007, 01:07 PM
Great mod!
Is there a way to list the new links in the left column?
paypal2go
04-12-2007, 05:07 PM
When i click on link details from home page:
url 404 not found
***Open index.php and find code(at the bottom of the file)***
// if unique template _not_ exists, then reset to default
if(!file_exists($gDirSmarty->template_dir.$render))
{
$render = "index.tpl";
}
***Below add***
if ($category['id'] == 0)
{
loadClass("DirLink");
$Link = &new Link;
$listings = $Link->getLatest(0, 10);
$gDirSmarty->assign_by_ref('listings', $listings);
}
***Save changes***
***Open template/yourTemplate/index.tpl and find code****
{if $neighbour_categories}
<!-- neighbour categories box start -->
{include file="box-header.tpl" caption=$lang.neighbour_categories style="green"}
<div class="categories">{$neighbour_categories}</div>
{include file="box-footer.tpl"}
<!-- neighbour categories box end -->
{/if}
***Below add***
{if $listings}
{include file="box-header.tpl" caption=$lang.new_links style="green"}
<table cellspacing="0" cellpadding="0">
{foreach from=$listings item=link name=links}
{include file="link-display.tpl"}
{/foreach}
</table>
{include file="box-footer.tpl"}
{/if}
***Save file***
paypal2go
04-12-2007, 05:17 PM
When i click on link details from home page:
url 404 not found
Fix it. Insert code from your next post.
PassionSeed
04-13-2007, 12:11 AM
Just a bump so it won't get lost in the mix.
Great mod!
Is there a way to list the new links in the left column?
Tilek E.
04-16-2007, 01:56 PM
Originally Posted by PassionSeed
Great mod!
Is there a way to list the new links in the left column?
Hi PassionSeed,
Please take a look at the following thread: http://www.esyndicat.com/forum/about9984.html
Another question about new links...
For example lets say I have 10 categories...
I would like to pull new links only from categories #3, #4, #5 and show them on the home page.
Is this possible? If yes, how???
Thanks!
John Turner
06-05-2007, 05:25 AM
Hi WTM,
Open your '../includes/classes/DirLink.php'
find function getLatest
find following code
function getLatest($aStart = 0, $aLimit = 0, $aEditor = '')
replace with following code
function getLatest($aStart = 0, $aLimit = 0, $aEditor = '', $aOnIndex = false)
than you should find following code in this function
$sql .= "WHERE t1.`status` = 'active' ";
$sql .= "AND t9.`status` = 'active' ";
and add after it following code
$sql .= $aOnIndex ? "AND t9.`id` IN ('4','5','6') " : '';
Where '4','5','6' categories IDs from what you would display new links
*** save and close it.
Also you should made changes in your 'index.php' in compliance with previous messages of this thread
find following code
if ($category['id'] == 0)
{
loadClass("DirLink");
$Link = &new Link;
$listings = $Link->getLatest(0, 10);
$gDirSmarty->assign_by_ref('listings', $listings);
}
replace with following code
if ($category['id'] == 0)
{
loadClass("DirLink");
$Link = &new Link;
$listings = $Link->getLatest(0, 10, false, true);
$gDirSmarty->assign_by_ref('listings', $listings);
}
** save and close it.
HTH
Thank you very much!!!
I will try it today and let you know the results.
John Turner
06-05-2007, 09:13 AM
You're welcome WTM,
always at your services.
Hi John,
Your modification doesn't work... :(
All links disappeared even when I tried to enter all the categories I have... :cry:
Any other ideas?
The mod that David described above is working but it shows link from all categories and I need to exclude some categories...
If you find a solution - how to implement it also to random and top links?
Random and top links will be shown on some category pages, not the home one.
Thanks for your time.
Tilek E.
06-06-2007, 02:42 PM
Hi WTM,
Please try the following to display links of definite categories:
#1. Make all the steps of New Links on Index Pages modification which was described by me in this thread before.
#2. (NOTE: please make a backup of includes/classes/DirLink.php) Open includes/classes/DirLink.php file and insert the highlighted string: (for new links)
function getLatest($aStart = 0, $aLimit = 0, $aEditor = '')
{
$sql = "SELECT t1.*, `t1`.`comments_active` `comments`, t9.`path` ";
$sql .= $aEditor ? ', IF((`t1`.`id_editor` IS NULL) OR (`t1`.`id_editor` = \'0\'), \'0\', \'1\') `id_editor_edit` ' : ', \'0\' `id_editor_edit` ';
$sql .= "FROM `".$this->mTable."` t1 ";
$sql .= "LEFT JOIN `".$this->mPrefix."link_categories` t8 ";
$sql .= "ON t1.`id` = t8.`id_link` ";
$sql .= "AND t8.`crossed` = '0' ";
$sql .= "LEFT JOIN `".$this->mPrefix."categories` t9 ";
$sql .= "ON t8.`id_category` = t9.`id` ";
$sql .= "WHERE t1.`status` = 'active' ";
$sql .= "AND t9.`status` = 'active' ";
$sql .= "AND t8.`id_category` IN ('4', '5', '6') ";
//$sql .= "GROUP BY t1.`id` ";
$sql .= "ORDER BY t1.`date` DESC ";
$sql .= $aLimit ? "LIMIT {$aStart}, {$aLimit}" : '';
return $this->getAll($sql);
}
#3. You can make the same thing for Top Links page:
function getTop($aStart = 0, $aLimit = 0, $aEditor = '')
{
$sql = "SELECT t1.*, `t1`.`comments_active` `comments`, t9.`path` ";
$sql .= $aEditor ? ', IF((`t1`.`id_editor` IS NULL) OR (`t1`.`id_editor` = \'0\'), \'0\', \'1\') `id_editor_edit` ' : ', \'0\' `id_editor_edit` ';
$sql .= "FROM `".$this->mTable."` t1 ";
$sql .= "LEFT JOIN `".$this->mPrefix."link_categories` t8 ";
$sql .= "ON t1.`id` = t8.`id_link` ";
$sql .= "AND t8.`crossed` = '0' ";
$sql .= "LEFT JOIN `".$this->mPrefix."categories` t9 ";
$sql .= "ON t8.`id_category` = t9.`id` ";
$sql .= "WHERE t1.`status` = 'active' ";
$sql .= "AND t9.`status` = 'active' ";
$sql .= "AND t8.`id_category` IN ('4', '5', '6') ";
//$sql .= "GROUP BY t1.`id` ";
$sql .= "ORDER BY t1.`rank` DESC ";
$sql .= $aLimit ? "LIMIT ".$aStart.", ".$aLimit : '';
return $this->getAll($sql);
}
#4. For Random Links page:
function getRandom($num=10)
{
$sql = "SELECT t1.*, `t1`.`comments_active` `comments`, t9.`path`, '0' `id_editor_edit` ";
$sql .= "FROM `".$this->mTable."` t1 ";
$sql .= "LEFT JOIN `".$this->mPrefix."link_categories` t8 ";
$sql .= "ON t1.`id` = t8.`id_link` ";
$sql .= "AND t8.`crossed` = '0' ";
$sql .= "LEFT JOIN `".$this->mPrefix."categories` t9 ";
$sql .= "ON t8.`id_category` = t9.`id` ";
$sql .= "WHERE t9.`status` = 'active' ";
$sql .= "AND t1.`status` = 'active' ";
$sql .= "AND t8.`id_category` IN ('4', '5', '6') ";
$all = $this->one("count(*)");
// avoiding very expensive ORDER BY RAND()
if($all > 1000)
{
$ids = array();
// within num*2 we might get number of `active` listings
$x = $num*2;
for($i=0; $i < $x; $i++)
{
$ids[] = rand(1, $all);
}
$sql .= "AND t1.`id` IN('".implode("','", $ids)."') ";
}
else
{
//$sql .= "GROUP BY t1.`id` ";
$sql .= "ORDER BY RAND() ";
}
$sql .= "LIMIT ".$num;
return $this->getAll($sql);
}
#5. For Popular Links page:
function getPopular($aStart = 0, $aLimit = 0, $aEditor = '')
{
$sql = "SELECT t1.*, `t1`.`comments_active` `comments`, t9.`path` ";
$sql .= $aEditor ? ', IF((`t1`.`id_editor` IS NULL) OR (`t1`.`id_editor` = \'0\'), \'0\', \'1\') `id_editor_edit` ' : ', \'0\' `id_editor_edit` ';
$sql .= "FROM `".$this->mTable."` t1 ";
$sql .= "LEFT JOIN `".$this->mPrefix."link_categories` t8 ";
$sql .= "ON t1.`id` = t8.`id_link` ";
$sql .= "AND t8.`crossed` = '0' ";
$sql .= "LEFT JOIN `".$this->mPrefix."categories` t9 ";
$sql .= "ON t8.`id_category` = t9.`id` ";
$sql .= "WHERE t1.`status` = 'active' ";
$sql .= "AND t1.`clicks` > 0 ";
$sql .= "AND t9.`status` = 'active' ";
$sql .= "AND t8.`id_category` IN ('4', '5', '6') ";
//$sql .= "GROUP BY t1.`id` ";
$sql .= "ORDER BY `clicks` DESC ";
$sql .= $aLimit ? "LIMIT {$aStart}, {$aLimit}" : '';
return $this->getAll($sql);
}
#6. Save changes and close the file.
Mishef
09-26-2007, 12:02 PM
Hello..! I would like to know how to do to put the "new links" section on a right column on my site for the GreenLeaves template ?? Thanks :)
readvolumes
10-01-2007, 10:58 PM
Hi,
In 2.1.03 is it possible to create a random links version of this mod?
(ie make a box with a few random links in it, on the homepage)
Thanks
Ed
rasmussen
10-09-2007, 08:13 AM
I tried to use the latest mod (2,1) in my 2,2 version but now my site is totally blank :p
Can someone confirm that the latest mod works for the latest version (2,2)?
Vasily B.
10-09-2007, 08:52 PM
Hi rasmussen
You do not need to use this modification. Just download a plugin for that here:
http://www.esyndicat.com/forum/about12025.html
vBulletin® v3.7.0, Copyright ©2000-2013, Jelsoft Enterprises Ltd.