How to pageList->filterByTopic multiple topics?

Permalink
I would like to be able to filter my page list by multiple topics, how can I do this?

ob7dev
View Replies: View Best Answer
ob7dev replied on at Permalink Reply
ob7dev
ITS IMPOSSIBLE! That's why no one tried answering!
Parasek replied on at Permalink Best Answer Reply
Parasek
Actually it is not impossible. You just to need do create your own class, which extends original PageList class

1. create file application/src/Page/CustomPageList.php
(you can actually create it anywhere you want - you just need to use proper namespace)
and paste this code
<?php
namespace Application\Src\Page;
use PageList;
class CustomPageList extends PageList
{
    public function filterByMultipleTopics($topics = array())
    {
        if (is_array($topics) AND count($topics)>0) {
            $this->query->innerJoin('cv', 'CollectionAttributeValues', 'cavTopics',
                'cv.cID = cavTopics.cID and cv.cvID = cavTopics.cvID');
            $this->query->innerJoin('cavTopics', 'atSelectedTopics', 'atst', 'cavTopics.avID = atst.avID');
            $query = '';
            foreach ($topics as $topic) {
                if (is_object($topic)) {
                    $treeNodeID = $topic->getTreeNodeID();

It is modified function filterByTopic(), which is located in concrete/src/Page/PageList.php
But instead of one topic id, it requires and array of topic ids as argument

2. To display pagelist, use this code

<?php
$topicIDs = array(11, 8);
$list = new Application\Src\Page\CustomPageList();
$list->filterByMultipleTopics($topicIDs);
$pages = $list->getResults();
?>
ob7dev replied on at Permalink Reply
ob7dev
No wonder your avatar is of a coding ninja! You are one! Nice domain name btw.
ScottsdaleUnified replied on at Permalink Reply
ScottsdaleUnified
Where does the second snippet of code go?
ob7dev replied on at Permalink Reply
ob7dev
Are you adding this to a page type or a block view?
ScottsdaleUnified replied on at Permalink Reply
ScottsdaleUnified
The PageList Block is what I wanted to use to display multiple topics (multiple schools or types of schools)
ob7dev replied on at Permalink Reply
ob7dev
So basically building a new package?
ScottsdaleUnified replied on at Permalink Reply
ScottsdaleUnified
Excuse my ignorance - maybe?

Basically I have 30 Blogs or Topics ( II have not decided if it would be smarter to have 30 blog roots or 1 Blog Root and 30+ topics)

So on every school site, my web author uses the blog feature to add announcements which go to a page as well as get displayed on the homepage of the school in a list view.

We used to use ProBlog (discontinued now) and I am developing the new site using Fundamental and C5DK Blog. I would really like to be able to use only one PageList and select Multiple Topics so I do not need to add 2+ Page Lists to show multiple topics.
ob7dev replied on at Permalink Reply
ob7dev
Ahh I understand. So there is two ways I know of the embed this "multiple topic pagelist". One if via embedding the code within a page template ( i.e. full.php or blog.php inside a theme folder ) or two is coding a block that has this code within its view.php.

I will need to see if I can pull this off before trying to tell you how to do it.
ScottsdaleUnified replied on at Permalink Reply
ScottsdaleUnified
I appreciate all your help!
JohntheFish replied on at Permalink Reply
JohntheFish
There was something on c5 github about enhancing the data list class for filtering a list by OR as well as or instead of AND.
ob7dev replied on at Permalink Reply
ob7dev
do u have the link by chance?
JohntheFish replied on at Permalink Reply
JohntheFish
I am afraid not. It was posted or updated fairly recently, within the last few weeks.
ob7dev replied on at Permalink Reply
ob7dev
Maybe something we can look forward to in 8.2