Jump to content

Need help to limit number of Rss feed entries via PHP/XML


lorenzofp

Recommended Posts

Hello,

 

I have a real estate website, a rss feed and I use feedburner for email subscriptions etc.

 

Since last week, feedburner is not working anymore cause it says that my feed is larger than 512 KB.

 

Well, i would like to change the code of the feed in order to display only the last 200 items (now we have 300), but i tried many ways and didnt have any luck :(

 

Another solution would be setting a minimum date for publishing the items, for example to set the feed to publish items only if their publication date was after a particular month or day.

 

here is my code, can you help me to limit number of items, please?

 

Thanks in advance

 

<?php
defined('_JEXEC') or die( 'Restricted access' );

jimport( 'joomla.application.component.view');

class PropertiesViewProperties extends JView
{
function display($tpl = null)
{

	global $mainframe;
	$db			=& JFactory::getDBO();
	$document	=& JFactory::getDocument();
	$params =& $mainframe->getParams();
	$document->link = JRoute::_('index.php?option=com_properties&view=properties');



$document->setMetaData('description',JURI::base());
	// Get some data from the model
	JRequest::setVar('limit', $mainframe->getCfg('feed_limit'));


$query = ' SELECT p.*,c.name as name_category,t.name as name_type,cy.name as name_country,s.name as name_state,l.name as name_locality,pf.name as name_profile,pf.logo_image as logo_image_profile, '
. ' CASE WHEN CHAR_LENGTH(p.alias) THEN CONCAT_WS(":", p.id, p.alias) ELSE p.id END as Pslug,'
. ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as Cslug,'
. ' CASE WHEN CHAR_LENGTH(cy.alias) THEN CONCAT_WS(":", cy.id, cy.alias) ELSE cy.id END as CYslug,'
. ' CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(":", s.id, s.alias) ELSE s.id END as Sslug,'
. ' CASE WHEN CHAR_LENGTH(l.alias) THEN CONCAT_WS(":", l.id, l.alias) ELSE l.id END as Lslug, '
. ' CASE WHEN CHAR_LENGTH(t.alias) THEN CONCAT_WS(":", t.id, t.alias) ELSE t.id END as Tslug '
. ' FROM #__properties_products AS p '
. ' LEFT JOIN #__properties_country AS cy ON cy.id = p.cyid '
. ' LEFT JOIN #__properties_state AS s ON s.id = p.sid '
. ' LEFT JOIN #__properties_locality AS l ON l.id = p.lid '
. ' LEFT JOIN #__properties_profiles AS pf ON pf.mid = p.agent_id '
. ' LEFT JOIN #__properties_category AS c ON c.id = p.cid '
. ' LEFT JOIN #__properties_type AS t ON t.id = p.type '
. ' WHERE p.published = 1 '
.' ORDER BY p.id DESC'
;


			$db->setQuery( $query );				
			$prod = $db->loadObjectList();




	foreach ( $prod as $row )
	{

		// strip html from feed item title
		$title = $this->escape( $row->name );
		$title = html_entity_decode( $title );
		// url link to article

		$link = LinkHelper::getLink('properties','showproperty','',$row->CYslug,$row->Sslug,$row->Lslug,$row->Cslug,$row->Tslug,$row->Pslug);
		// strip html from feed item description text
		$image_name=$this->Images($row->id);	
		//print_r($image_name);
		//require('a');
		$image = '<img width="200" align="left" alt="'.$item->title.'" src="'.JURI::base().'images/properties/images/thumbs/'.$row->id.'/'.$image_name.'"/>';
		$category = ' '.JText::_('Category').': <b>'.$row->name_category.'. </b>';
		$desc = '<br>'.'<br>'.'<div align="center" style="border: 1px solid red; margin: 10px; padding: 20px;">'.$row->text.'</div>';


		$description = $image.$category.$type.$ref.$desc;
		$description = $this->escape( $description );
		$description = html_entity_decode( $description );
		$listdate = $row->listdate;
		// load individual item creator class
		$item = new JFeedItem();			
		$item->title 		= $title;
		$item->link 		= $link;
		$item->description 	= $description;
		$item->date			= $listdate;
		$item->category   	= $row->name_category;
		$item->type   	= $row->name_type;

		// loads item info into rss array
		$document->addItem( $item );
	}



}



function Images($id)
{	

$db 	=& JFactory::getDBO();	
$query = ' SELECT i.name '			
		. ' FROM #__properties_images as i '					
		. ' WHERE i.published = 1 AND i.parent = '.$id			
		. ' order by i.ordering LIMIT 1';		
        $db->setQuery($query);   

	$Images = $db->loadResult();

return $Images;
}


}
?>

Try

$query = ' SELECT p.*,c.name as name_category,t.name as name_type,cy.name as name_country,s.name as name_state,l.name as name_locality,pf.name as name_profile,pf.logo_image as logo_image_profile, '
. ' CASE WHEN CHAR_LENGTH(p.alias) THEN CONCAT_WS(":", p.id, p.alias) ELSE p.id END as Pslug,'
. ' CASE WHEN CHAR_LENGTH(c.alias) THEN CONCAT_WS(":", c.id, c.alias) ELSE c.id END as Cslug,'
. ' CASE WHEN CHAR_LENGTH(cy.alias) THEN CONCAT_WS(":", cy.id, cy.alias) ELSE cy.id END as CYslug,'
. ' CASE WHEN CHAR_LENGTH(s.alias) THEN CONCAT_WS(":", s.id, s.alias) ELSE s.id END as Sslug,'
. ' CASE WHEN CHAR_LENGTH(l.alias) THEN CONCAT_WS(":", l.id, l.alias) ELSE l.id END as Lslug, '
. ' CASE WHEN CHAR_LENGTH(t.alias) THEN CONCAT_WS(":", t.id, t.alias) ELSE t.id END as Tslug '
. ' FROM #__properties_products AS p '
. ' LEFT JOIN #__properties_country AS cy ON cy.id = p.cyid '
. ' LEFT JOIN #__properties_state AS s ON s.id = p.sid '
. ' LEFT JOIN #__properties_locality AS l ON l.id = p.lid '
. ' LEFT JOIN #__properties_profiles AS pf ON pf.mid = p.agent_id '
. ' LEFT JOIN #__properties_category AS c ON c.id = p.cid '
. ' LEFT JOIN #__properties_type AS t ON t.id = p.type '
. ' WHERE p.published = 1 '
.' ORDER BY p.id DESC'  'LIMIT 0, 200 '
;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.