Hello KK,
I tried to use the couch search tag like this:
BUT I realised it's not possible from the documentation I read so I decided to find a way around using PHP and couch query tag. I will like you to see if I used the right approach or there could be a simpler approach
My solution
1. I passed the folder name and the keyword through a query string
2. I used the following approach to get the ids of the parent folder and it's subfolders into a variable
3. Lastly I used the couch query tag to get the IDs of the pages from the search like this:
I hope I did the right thing? Thank you
I tried to use the couch search tag like this:
- Code: Select all
<cms:search masterpage='products.php' folder=folder_name_from_querystring keywords=keyword_from_query_string >
.......
</cms:search>
BUT I realised it's not possible from the documentation I read so I decided to find a way around using PHP and couch query tag. I will like you to see if I used the right approach or there could be a simpler approach
My solution
1. I passed the folder name and the keyword through a query string
- Code: Select all
http://localhost/dotmatrix/?folder=phones-wearables&keyword=apple
2. I used the following approach to get the ids of the parent folder and it's subfolders into a variable
- Code: Select all
<cms:capture into='product_folder_ids' >
<cms:folders masterpage="product.php" root='phones-wearables' hierarchical='1'>
<cms:show k_folder_id />,
</cms:folders>
</cms:capture>
<cms:php>
global $CTX;
$product_folder_ids = "<cms:show product_folder_ids />";
$product_folder_ids = implode(',',array_filter(explode(',',$product_folder_ids)));
$CTX->set('product_folder_ids',$product_folder_ids,'global');
</cms:php>
<!-- I outputted the results to make sure I was on track -->
<cms:show product_folder_ids />
3. Lastly I used the couch query tag to get the IDs of the pages from the search like this:
- Code: Select all
<cms:capture into='returned_product_ids' >
<cms:query sql="
SELECT DISTINCT p.id, p.template_id, page_title AS k_page_title
FROM <cms:php>echo K_TBL_PAGES;</cms:php> p
inner join <cms:php>echo K_TBL_TEMPLATES;</cms:php> t
on p.template_id = t.id
WHERE (t.name='product.php')
AND (p.template_id=t.id)
AND ( p.page_title LIKE '%apple%' )
AND p.page_folder_id IN (<cms:show product_folder_ids />)
AND NOT p.publish_date = '0000-00-00 00:00:00'
AND p.parent_id=0
ORDER BY p.publish_date desc"
fetch_pages='1'
limit='3'
>
<cms:show k_page_id /> ,
</cms:query>
</cms:capture>
<cms:pages masterpage="products.php" id=returned_product_ids >
<cms:show k_page_title /> <br>
</cms:pages>
I hope I did the right thing? Thank you