by
KK » Thu Oct 06, 2011 1:09 am
In the tutorial some categories are created in the sidebar, when clicking on them they show all the posts belonging to category, how to limit the number of posts shown.I think this will solve my problem.
You have mentioned the way categories are listed in the sidebar of our tutorial.
Let us start from there.
In the tutorial the code is
- Code: Select all
<h4>Categories</h4>
<ul class="sidebar">
<cms:folders masterpage='blog.php' >
<li><a href="<cms:show k_folder_link />"><cms:show k_folder_title /></a></li>
</cms:folders>
</ul>
Suppose 'blog.php' had 2 categories 'cat1' & 'cat2'. The code above would result in the following with prettyURLs turned on
- Code: Select all
<h4>Categories</h4>
<ul class="sidebar">
<li><a href="http://www.yoursite.com/blog/cat1/">cat1</a></li>
<li><a href="http://www.yoursite.com/blog/cat2/">cat2</a></li>
</ul>
Without prettyURLs, it would be -
- Code: Select all
<h4>Categories</h4>
<ul class="sidebar">
<li><a href="http://www.yoursite.com/blog.php?f=1">cat1</a></li>
<li><a href="http://www.yoursite.com/blog.php?f=2">cat2</a></li>
</ul>
Point to note is that the links
- Code: Select all
http://www.yoursite.com/blog/cat1/
or
http://www.yoursite.com/blog.php?f=1
when clicked will lead back to 'blog.php'.
Instead of using
cms:folders tag to create the folder-view URLs, we can use the
cms:link tag to do the same (if we know the folder names) e.g. the following will generate the same code
- Code: Select all
<a href="<cms:link masterpage='blog.php' folder='cat1' />">cat1</a>
Once someone clicks on the links and 'blog.php' gets called, it is now upto our code within it to list pages however we like.
We can be helped by the fact that Couch is smart enough to figure out by seeing the 'f=1' or 'cat1' in the URL that this is the 'folder-view' and makes available information about the folder in question for you to handle. This it does by setting up certain variables -
k_folder_name being one of them e.g. if the link clicked was for folder 'cat1',
k_folder_name will contain 'cat1' as value.
In our case, what we can do is check whether it is the folder-view we are handling (i.e. the link bringing up blog.php had folder info within it) -
- Code: Select all
<cms:if k_is_folder >
</cms:if>
If it is, we can then list the pages belonging to the folder -
- Code: Select all
<cms:if k_is_folder >
<cms:pages masterpage='blog.php' folder=k_folder_name>
<h1><cms:show k_page_title /></h1>
...other variables of each page in the folder..
</cms:pages>
</cms:if>
Notice how we have set the
folder=k_folder_name where
k_folder_name will be either 'cat1' or 'cat2' depending on the link clicked.
The code above will list
all the pages belonging to the folder being listed.
Since you require only 8, we can set the limit parameter -
- Code: Select all
<cms:if k_is_folder >
<cms:pages masterpage='blog.php' folder=k_folder_name limit='8'>
<h1><cms:show k_page_title /></h1>
...other variables of each page in the folder..
</cms:pages>
</cms:if>
This is the only way we can list pages in Couch.
Do let me know if this helped.
Thanks.