Problems, need help? Have a tip or advice? Post it here.
17 posts Page 2 of 2
While we're all on this topic of categories in the tutorial, I noticed that clicking on "Clients" gave me just that category, but if I click on an "Uncategorized" link, I got all the posts not just the uncategorized. Related to that, I also thought I'd add an entry to the end of the category list as "Others" for the uncategorized (is it a "z" or an "s"?). So I just added an <li> tag outside the loop:
Code: Select all
<cms:folders masterpage='blog.php' >
<li><a href="<cms:show k_folder_link />"><cms:show k_folder_title /></a></li>
</cms:folders >
<li><a href="<cms:show k_template_link />">Others</a></li>

Although the result looks great, it unfortunately selects all posts. How could I just select just the uncategorized?
@wysocki, any cloned page that is not specifically placed within a folder belongs to the template's root.

As an example, please take a look at the page hierarchy below. Here 'page_1' and 'page_2' have not been assigned any folder and hence they fall right below the root.
Code: Select all
/blog.php
|_page_1
|_page_2
|_CLIENTS (folder)
|    |_page_3
|    |_page_4
|    |_ SPECIAL CLIENTS (folder)
|        |_page_5
|_EMPLOYEES (folder)
    |_page_6

The <cms:pages> tag has a parameter named 'include_subfolders' that can be used to specify if we want the tag to fetch only pages that are the immediate children of the specified folder or to include pages from the child folders too.

The default value of this parameter is '1' so when we use the following code -
Code: Select all
<cms:pages masterpage='blog.php' folder='clients'>..
it will fetch pages 'page_3', 'page_4' and also 'page_5'.

If we modify the code to explicitly set 'include_subfolders' to '0' as follows -
Code: Select all
<cms:pages masterpage='blog.php' folder='clients' include_subfolders='0'>..
only pages 'page_3' and 'page_4' would be fetched.

The point I wish to stress is that if we do not specify any 'folder' with cms:pages, it starts from the root. So the following would fetch *all* the pages
Code: Select all
<cms:pages masterpage='blog.php' >..

If, however, we use the 'include_subfolders' parameter
Code: Select all
<cms:pages masterpage='blog.php'  include_subfolders='0'>..
it will only fetch pages that are the immediate children of the root i.e. 'page_1' and 'page_2'

So, to answer your query, 'uncategorized' pages are actually pages that are the immediate children of the root. So to fetch only those, you can use the include_subfolders='0' parameter as shown above.

Hope it helps.
Ahh, I should have known to look deeper into the docs for the answer! So I tried to change my pages criteria based upon that:
Code: Select all
<cms:pages masterpage='blog-item.php' 
    <cms:if k_folder_name =="" >
        include_subfolders='0'
    <cms:else />
        folder=k_folder_name
    </cms:if>   
    start_on=k_archive_date
    stop_before=k_next_archive_date
    paginate='1'
    limit='10'
    >

Which gave me:
ERROR! ATTRIB_NAME: Invalid char "<" (line: 212 char: 1847)

If this is the right approach, what is the correct syntax to insert a parameter conditionally. Couldn't find that issue covered in the docs.
Sorry. Removed post.
That's not it either. :? :lol:
wysocki wrote: Ahh, I should have known to look deeper into the docs for the answer! So I tried to change my pages criteria based upon that:
Code: Select all
<cms:pages masterpage='blog-item.php' 
    <cms:if k_folder_name =="" >
        include_subfolders='0'
    <cms:else />
        folder=k_folder_name
    </cms:if>   
    start_on=k_archive_date
    stop_before=k_next_archive_date
    paginate='1'
    limit='10'
    >

Which gave me:
ERROR! ATTRIB_NAME: Invalid char "<" (line: 212 char: 1847)

If this is the right approach, what is the correct syntax to insert a parameter conditionally. Couldn't find that issue covered in the docs.


You cannot add tags inside the tag like that, your best bet is to use two separate pages tags inside the if statement.

Code: Select all
<cms:if ... >
    <cms:pages ...>
<cms:else />
    <cms:pages ...>
</cms:if>
Image
Please try it this way -
Code: Select all
<cms:pages masterpage='blog-item.php'
    folder=k_folder_name
    include_subfolders="<cms:if k_folder_name>1<cms:else />0</cms:if>"
    start_on=k_archive_date
    stop_before=k_next_archive_date
    paginate='1'
    limit='10'
    >
    <cms:show k_page_title /><br />
</cms:pages>

The k_folder_name variable would be set only in folder-view so in the views where it is not set the folder=k_folder_name statement would simply evaluate to folder=''.

The value of 'include_subfolders' parameter is set depending on the presence of k_folder_name variable (notice the use of double-quotes to evaluate Couch tags enclosed within the quotes).

Hope it helps.
17 posts Page 2 of 2