Show Top Stories by Category in Sidebar - A How To

Register an Account
Pligg Chat Room
Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-23-2007, 09:30 PM
Casual Pligger
 
Join Date: Mar 2007
Posts: 46
Ok, I wanted to show the top stories by category in the sidebar. You can see it at http://www.acttup.com. This took the following mods.

First, edit libs/sidebarstories.php. We need to add a category variable to the SidebarStories class. First add a variable as follows in the variable declarations:

Code:
var $category = "";
Next, we need to assign the passed in category to the search. Add this line to the assignments:

Code:
$search->category = $this->category;
The entire updates libs/sidebarstories.php file looks like this:

Code:
class SidebarStories {
  var $pagesize = 5; // The number of items to show
  var $orderBy = ""; // The sorting order
  var $filterToStatus = "all"; // Filter to "all" or just "published" or "queued"
  var $category = "";
  var $filterToTimeFrame = ""; // Filter to "all" or just "published" or "queued"
  var $header = ""; // The text to show at the top
  var $template = ""; // The template to use, including folder
  
	function show() {
		global $main_smarty, $db;
		include_once(mnminclude.'search.php');

		$search=new Search();
		$search->orderBy = $this->orderBy;
		$search->pagesize = $this->pagesize;
		$search->filterToStatus = $this->filterToStatus;
		$search->category = $this->category;
		$search->filterToTimeFrame = $this->filterToTimeFrame;
		$search->doSearch();
	
		$linksum_sql = $search->sql;
	
		$link = new Link;
		$links = $db->get_col($linksum_sql);
	
		if ($links) {
			foreach($links as $link_id) {
				$link->id=$link_id;
				$link->read();
				$main_smarty = $link->fill_smarty($main_smarty);
				$main_smarty->display($this->template);
			 }
		}
		
	}
}
Next we need edit sidebar_stories in your root directory. There are several changes here: Change the order by to order by link_votes descending, take out the header assignments that where determined by the page we were one, add a condition to assign the query category and title of the sidebar module. I also took out the collapse code for my template - acttup. All these updates are at the top of the file:

Code:
<?php
// The source code packaged with this file is Free Software, Copyright (C) 2005 by
// Ricardo Galli <gallir at uib dot es>.
// It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
// You can get copies of the licenses here:
// 		http://www.affero.org/oagpl.html
// AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING".
// -------------------------------------------------------------------------------------

include_once('Smarty.class.php');
if(!isset($main_smarty)){$main_smarty = new Smarty;}
// If we're calling this page through another page like index.php, $main_smarty will already be set
// If we're calling this page directly, set main_smarty

include_once('config.php');
include_once(mnminclude.'html1.php');
include_once(mnminclude.'link.php');
include_once(mnminclude.'tags.php');
include_once(mnminclude.'search.php');
include_once(mnminclude.'smartyvariables.php');
include_once(mnminclude.'sidebarstories.php');

Global $the_template;

	// for filterTo you can use "published", "queued" or "all"
	// to change the way the links look, edit /tempates/<your template>/sidebar_stories.tpl

	$ss = new SidebarStories();
	$ss->orderBy = "link_votes DESC"; // newest on top.
	$ss->pagesize = 10; // the number of items to show in the box.
	
	if(pagename == "index"){
		$ss->filterToStatus = "published";
	}
	elseif(pagename == "upcoming"){
		$ss->filterToStatus = "queued";
	}
	else{
		$ss->filterToStatus = "published";
	}

	if(isset($_REQUEST['category'])){
		$ss->header = "Top Stories in " . $_REQUEST['category'];
		$ss->category = $_REQUEST['category'];
	} else {
		$ss->header = "Top Stories in All";
	}

	if($the_template == "mollio-beat" || $the_template == "acttup") {	
 	
	echo " <h3>".$ss->header."</h3><div id=ss class=switchcontent>";
		$ss->template = $the_template . '/sidebar_stories.tpl';
		$ss->show();
	echo "</div>";
	
	}
	
	elseif ($the_template == "digitalnature") {
	
	echo "<div class=box><h1><span class=expand><a href=javascript:toggle('stories','expstories'); id=expstories class=expand-up></a></span><a href=javascript:toggle('stories','expstories');".$ss->header."</a></h1><div class=box2 id=stories><div class=wrap><div class=content>";
	$ss->template = $the_template . '/sidebar_stories.tpl';
		$ss->show();
	echo "</div></div></div></div>";
	
	}
	
	elseif ($the_template == "yget") {
	
	echo "<div class=tlb><span><a onclick=\"new Effect.toggle('ssstories','blind', {queue: 'end'}); \"> <img src=\"".my_base_url.my_pligg_base."/templates/yget/images/expand.png\"  onClick=expandcontent(this,'ssstories') ></a></span><a href=".my_pligg_base."/upcoming.php>".$ss->header."</a></div><div id=ssstories style=padding-bottom:5px>";
	$ss->template = $the_template . '/sidebar_stories.tpl';
	$ss->show();
	echo "</div>";
	
	}
?>
Next, if you want, you can change the appearance of the top stories list. I simply added the number of votes. My template is a derivative of Paul01, so I edited the sidebar_stories.tpl file in templates/acttup.

Code:
{$link_shakebox_votes} - <a href="{$story_url}">{$title_short|truncate:35}</a><br>
Note, I extended the length of the truncation from 22 to 35.

Lastly, I wanted it to show no matter which page I was on, so I removed the conditional display option from sidebar.tpl. It was this:

Code:
{if $pagename eq "index" || $pagename eq "upcoming"}
	{assign var=sidebar_module value="sidebar_stories"}{include file=$the_template_sidebar_modules."/wrapper.tpl"}
{/if}
It is now just this:

Code:
{assign var=sidebar_module value="sidebar_stories"}{include file=$the_template_sidebar_modules."/wrapper.tpl"}

Last edited by TrailofDead; 04-23-2007 at 09:31 PM. Reason: added site
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Show Stories Differently on the Front Page and the Category Page maxkiesler Questions and Comments 3 02-28-2010 12:49 AM
Control of meta description - categories Divisive Cotton Questions and Comments 65 11-06-2009 07:10 PM
How to include Sidebar Modules only category and categroy stories page amsy Questions and Comments 1 01-28-2009 02:21 AM
How to show category keywords as text on the site? gnalkit Questions and Comments 4 11-26-2008 05:17 AM
category related sidebar stories Andtony Questions and Comments 0 04-07-2007 10:55 AM


Pligg Modules and Pligg Templates from Pligg Pro Find support on the Pligg CMS Forum - 24 hours a day! Make a donation to support Pligg CMS development