Inserting programmatically all the stacks filtered by the language
Permalink
Hi,
what would be the best way to insert stacks in a page? I have a long list of stacks containing FAQ blocks. I would like to have a complete list of FAQs.
Inserting them one by one is very time consuming. I would like to hard code a loop in a dedicated template.
How can I do that? How do I get the list of stacks filtered by the language? Do you have an alternative suggestion?
Thank you all.
what would be the best way to insert stacks in a page? I have a long list of stacks containing FAQ blocks. I would like to have a complete list of FAQs.
Inserting them one by one is very time consuming. I would like to hard code a loop in a dedicated template.
How can I do that? How do I get the list of stacks filtered by the language? Do you have an alternative suggestion?
Thank you all.
Can you provide a screenshot or an example of your stacks structure? How do you know which is for what language?
My stacks are very simple stacks. Every stack contains one FAQ module exactly. This is because we include single FAQ questions in the pages of the content. We have four languages and over 80 stacks per language.
I would like to add all the Stacks in one page so I have a list of all of them but inserting them one by one is time consuming and cumbersome because the left menu disappears every time I add one.
How do you know which is for what language?
I actually was hoping it is possible to extract the correct list by specifying the language somehow.
I would like to know if it is possible to get the list and use a php loop to display them on the screen.
Thank you very much
I would like to add all the Stacks in one page so I have a list of all of them but inserting them one by one is time consuming and cumbersome because the left menu disappears every time I add one.
How do you know which is for what language?
I actually was hoping it is possible to extract the correct list by specifying the language somehow.
I would like to know if it is possible to get the list and use a php loop to display them on the screen.
Thank you very much
You can do something like this
I'm sure you could filter it by language somehow, but without knowing your structure I'm not sure how. Try referencing the API
StackList -http://documentation.concrete5.org/api/class-Concrete.Core.Page.Sta...
Stack -http://documentation.concrete5.org/api/class-Concrete.Core.Page.Sta...
$stackList = new StackList(); $stacks = $stackList->get(9999); if(count($stacks)){ foreach($stacks as $stack){ $stack->display(); } }
I'm sure you could filter it by language somehow, but without knowing your structure I'm not sure how. Try referencing the API
StackList -http://documentation.concrete5.org/api/class-Concrete.Core.Page.Sta...
Stack -http://documentation.concrete5.org/api/class-Concrete.Core.Page.Sta...
Filtering languages is indeed a problem. I also end up with having Stacks I don't need so in the end I wrote this function:
The structure is quite straightforward. It is a list of stacks and every stack has one faq block inside.
Maybe there is a better way to do this. For now I will stick with this function.
Thank you very much for your help.
function extractStacks() { $sec = Section::getDefaultSection(); $db = Database::connection(); $r = $db->Execute('select stID,cID from Stacks where stMultilingualSection = ? and stType = 0', array($sec->cID)); $entries = $r->fetchAll(); $result = []; foreach($entries as $entry) { $result[] = Stack::getById($entry['cID']); } return $result; }
The structure is quite straightforward. It is a list of stacks and every stack has one faq block inside.
Maybe there is a better way to do this. For now I will stick with this function.
Thank you very much for your help.
If you had looked at the StackList reference you would have seen that there are classes for filterByPageLanguage and filterByLanguageSection
Actually I tried to use the filtering functions but in the list there were Stacks I didn't create being included. I have no idea why but I got some header contents and stacks that were belonging to the platform but I haven't created them. Or maybe they were old deleted content.
That is why I have opted for the ad-hoc query. This way I only get the content I need.
This is the final function, extracting the content depending on the language.
Also, this way I don't need to filter anything. Everything this function extracts is already the content I need.
That is why I have opted for the ad-hoc query. This way I only get the content I need.
This is the final function, extracting the content depending on the language.
Also, this way I don't need to filter anything. Everything this function extracts is already the content I need.
function extractStacks() { $sec = Section::getByLanguage(Localization::activeLanguage()); $db = Database::connection(); $r = $db->Execute('select stID,cID from Stacks where stMultilingualSection = ? and stType = 0 order by stName', array($sec->cID)); $entries = $r->fetchAll(); $result = []; foreach($entries as $entry) { $result[] = Stack::getById($entry['cID']); } return $result; }