Gossamer Forum
Home : Products : Gossamer Links : PHP Front End :

Featured Site mod [release]

Quote Reply
Featured Site mod [release]
As mentioned in another thread...
I've got the old v1.1x Featured mod updated to a dynamic PHP version now,
complete with templates and a Featured.inc.php file, sans error reporting.

Basically, what it does is randomly select a 'featured' site from the database and
build that into the template, with a link to a popup window containing the full list
of featured links. Pretty simple, but it adds incentive to other sites to link back to
you in return for a featured listing...

The old v1.1x version can be found here for reference:


You will want to start by adding the isFeatured column to your Links table:

Column Name: isFeatured
Type: INT
Form Length: 1
Max Length: 1
Not Null: Yes
Default: 0
Validation: 1|0

The v2.x admin area (Database > Links > Properties > Add Column) contains a lot of
other optional table fields that can probably be ignored, so long as you set the
important ones above.

In page.php's switch($do) section, add the following:

case 'featured':

Create a new file called Featured.inc.php and place it in the /admin/Links/PHP/ directory.
Add the following to the file:

# ==================================================================
# Links SQL - enhanced directory management system
# Website : http://gossamer-threads.com/
# Support : http://gossamer-threads.com/scripts/support/
# CVS Info : 087,068,082,095,085
# Revision : $Id: Featured.inc.php
# Copyright (c) 2001 Gossamer Threads Inc. All Rights Reserved.
# Redistribution in part or in whole strictly prohibited. Please
# see LICENSE file for full details.
# ==================================================================

# used for formatting the featured link with link.html:

function handle() {
# ---------------------------------------------------
# Determine what to do.

# $id = isset($IN['link_id']) ? intval($IN['link_id']) : '';
$action = isset($IN['action']) ? strtolower($IN['action']) : '';

# Now figure out what to do.
if ($action == 'full') {

$results = "";
$sth = $DB->query("SELECT ID, Title, URL, Description FROM ${PREFIX}Links WHERE isFeatured = 1 ORDER BY Title ASC");
while ($row = $sth->fetchrow_hash()) {
$results .= "<a href=\"". $CFG['db_php_url'] ."/page.php?do=jump&link_id=". $row['ID'] ."\" target=\"_blank\">". $row['Title'] ."</a> - ". $row['Description'] ."<br><br>\n";

print_page('featured_full', array('featured_full' => $results));
} else {

# build an array of featured links to randomly select one from
$featured_array = array ();

$sth = $DB->query("SELECT ID FROM ${PREFIX}Links WHERE isFeatured = 1");
while ($row = $sth->fetchrow_hash()) {
$featured_array[] = $row['ID'];

# select a random id from the array
srand ((float) microtime() * 10000000);
$rand_keys = array_rand($featured_array);
$featured_id = $featured_array[$rand_keys];

// use this for a more efficient query if you will be manually formatting the link output:
// $sth = $DB->query("SELECT ID, Title, URL, Description FROM ${PREFIX}Links WHERE ID = '$featured_id'");

$sth = $DB->query("SELECT * FROM ${PREFIX}Links WHERE ID = '$featured_id'");
$row = $sth->fetchrow_hash();

// use this instead of _print_link() for manually formatting the link output:
// $result = "<a href=\"". $CFG['db_php_url'] ."/page.php?do=jump&link_id=". $row['ID'] ."\" target=\"_blank\">". $row['Title'] ."</a> - ". $row['Description'] ."<br>\n";

$result = _print_link($row);
print_page('featured', array('featured' => $result));


Create 2 new template files that will go into the /templates/default_php/local/
directory. The first will be called featured.html and will contain:

<title><?echo $site_title?> : Featured Sites</title>

function new_window() { rate =
// -->


<?echo $featured?>


Where "..." refers to whatever header/footer layout your templates take.

The second will be called featured_full.html and will contain:

<title><?echo $site_title?> : Featured Sites</title>

<body BGCOLOR="#ffffff">

<?echo $featured_full?>

<center><form><input type="button" value="Close" onClick="window.close();"></form></center>


Finally, you will access the featured page through:


That should about do it. To see it in action, you can take a look at the semi-static
(updated daily) current production version it is based on:


I'm also working on an updated version of the Priority Link Listing mod.

Quote Reply
Re: [Dan Kaplan] Featured Site mod [release] In reply to
Hi Dan,

Thank you for posting your works, my question is, it possible to have the featured sites to be list with numbers

1. site 1

2. site 2

3 site 3

Quote Reply
Re: [xpert] Featured Site mod [release] In reply to
Do you mean in the full list version? All that would require is a counter started at zero that increments by one as each link is prepared in Featured.inc.php. What would be the basis for numbering/ordering the links?

Quote Reply
Re: [Dan Kaplan] Featured Site mod [release] In reply to
increment form 1, up and in alphabet order!
Quote Reply
Re: [xpert] Featured Site mod [release] In reply to
Easy enough. That's the sort order already, so all you have to do is change the while() loop in the ($action == "full") section to:

$count = 1;
while ($row = $sth->fetchrow_hash()) {
$results .= $count .". <a href=\"". $CFG['db_php_url'] ."/page.php?do=jump&link_id=". $row['ID'] ."\" target=\"_blank\">". $row['Title'] ."</a> - ". $row['Description'] ."<br><br>\n";

Last edited by:

Dan Kaplan: Jul 2, 2002, 11:51 PM