SimplePortal

Customization => Custom Coding => Topic started by: russ skinner on January 02, 2010, 06:01:11 AM

Title: Limit Article Block to a specific Category
Post by: russ skinner on January 02, 2010, 06:01:11 AM
Hi all,

Just wondered if there is anywhere the article block can me modified to only show articles from a specific article category.

I have a number of user guides within the forum I look after and would like to add them to an article block on the front page and not have them over written by articles published at a later date - a sticky article block if you like. The easiest way I can see of achieving of this would be to place these articles in a specific category - 'User Guides' and only have the article block look at this category.

I have tried using a custom HTML naviagtion  block to achieve this, but the HTML links get corrupted with PHPSESSID code when viewed by guests - see post here (http://simpleportal.net/index.php?topic=4202.msg26156#msg26156).

Title: Re: Limit Article Block to a specific Category
Post by: Nathaniel on January 02, 2010, 05:28:35 PM
This should be easy, when you public an article you can choose which category that article belongs to. Then you can setup the categories in the admin area so that the other categories don't get shown on the portal (which makes them fairly pointless for the moment - SP 2.3.1 will have other ways of publishing categories).
Title: Re: Limit Article Block to a specific Category
Post by: russ skinner on January 03, 2010, 05:27:29 AM
Thanks Nathaniel, I can see this works.

Not sure what's in the pipeline for SP 2.3.1 and do not know how difficult this would be, but it would be nice to be able to select a category for an article block or some flexibility that can achieve this.   
Title: Re: Limit Article Block to a specific Category
Post by: BPLive on January 25, 2010, 04:02:29 AM
Thanks Nathaniel, I can see this works.

Not sure what's in the pipeline for SP 2.3.1 and do not know how difficult this would be, but it would be nice to be able to select a category for an article block or some flexibility that can achieve this.

I concur...  my main issue right now is that all Article catagory's are posted to the same place on the portal index. CaT blocks for articles are much needed so we can make sections etc.
Title: Re: Limit Article Block to a specific Category
Post by: [SiNaN] on January 29, 2010, 12:15:01 PM
This will let you filter the articles by category for articles block.

Sources/PortalBlocks.php

Code: (Find) [Select]
$block_parameters = array(
'limit' => 'int',
'type' => 'select',
'image' => 'select',
);

if ($return_parameters)
return $block_parameters;

Code: (Replace) [Select]
$block_parameters = array(
'limit' => 'int',
'type' => 'select',
'image' => 'select',
'category' => array(0 => 'All'),
);

if ($return_parameters)
{
global $sourcedir;

require_once($sourcedir . '/Subs-PortalAdmin.php');

$categories = getCategoryInfo();

foreach ($categories as $category)
$block_parameters['category'][$category['id']] = $category['name'];

$txt['sp_param_sp_articles_category'] = 'Category';

return $block_parameters;
}

$category = empty($parameters['category']) ? 0 : (int) $parameters['category'];

Code: (Find) [Select]
AND a.approved = {int:approved}
Code: (Replace) [Select]
AND a.approved = {int:approved}' . (!empty($category) ? '
AND a.id_category = ' . $category : '') . '

While editigin Articles type blocks, you'll notice a new option "Category:" where you can select the category.
Title: Re: Limit Article Block to a specific Category
Post by: russ skinner on February 25, 2010, 10:16:05 AM
Many thanks SiNaN, have just incorporated this feature and it works really well - exactly the flexibility I was looking for  ;D.

Hope you consider including this option in the next portal release. 
Title: Re: Limit Article Block to a specific Category
Post by: AngelinaBelle on February 25, 2010, 11:26:37 AM
Oooh! I like this! 
 
This is much better than the solution I came up while I was trying to figure out "sub-portal" pages (http://simpleportal.net/index.php?topic=4654 (http://simpleportal.net/index.php?topic=4654)).
This is so much better than hand-crafting custom pages using grabmessage.
 
After I test your code, I think I will be back here for advice on how to put message text into the article block, so I can put the article block on a SimplePortal page and display the articles from that category.
 
Thanks [SiNaN], and thanks russ for thinking of the idea.
 
Putting these two ideas together really almost makes SimplePortal a CMS, because I will be able to put custom article categories on custom pages.
 
After that, I'll just throw in a custom navigation bar, and I'll be all set.  I'll let you know how I make out.
Title: Re: Limit Article Block to a specific Category
Post by: AngelinaBelle on February 25, 2010, 04:06:49 PM
This works perfectly!
So now, of course I want to change it.
 
I think it would be best if I took a copy of this slightly-modified block and created a new block
 
function sp_articles_withbody

I have been searching blindly through SimplePortal files, without any luck.
Can a kind soul tell me:Thanks!
 
----------------
I have found out that I don't want to mess with adding new test blocks to the database right now (http://simpleportal.net/index.php?topic=4301.0 (http://simpleportal.net/index.php?topic=4301.0)), so I've scratched that question.
And I think I figured out the block_parameters just from looking at the language files, so I've scratched that question.
And I found template_articles in PortalArticles.template
 
So I'm good!
My next step is to pull some of template_articles into
sp_articles.  Just for fun.
SimplePortal 2.3.8 © 2008-2024, SimplePortal