Problems, need help? Have a tip or advice? Post it here.
9 posts Page 1 of 1
Back here again, i've been looking into listing things currently. However i've decided i wanted to list in different ways (news/blog articles)

On the main Index page i have a list of 4 news articles. They have an image to the left, title and some text within the main area. Now that follows on and lists only 4 items like so.

Now under that i would like to list the top 4 Articles, then list the next 4 articles but in links only, rather than having images, and the post text.

can this happen? :)
Hi Simon,

So, as far as I could get it, you wish to display a list of pages with the top few pages shown in a certain way, followed by the next few pages in a different way, followed by next pages in altogether different way etc. Right?

Two different ways of doing so come to my mind -

1. If all the pages are shown contiguously (no other elements of the webpage coming between them), we can use a single 'pages' statement. We'll keep a count of the pages that have been displayed and then show the current page accordingly. For example, the following code will display the first 2 pages, then the next 5 pages and then all the rest in different ways -
Code: Select all
<cms:pages masterpage='property.php' limit='10'>
   <cms:if k_count le '2' >
      <h1><cms:show k_page_title /></h1>
   </cms:if>
   
   <cms:if k_count ge '3' && k_count le '7' >   
       <h3><cms:show k_page_title /></h3>
   </cms:if>

   <cms:if k_count ge '8' >
      <cms:show k_page_title /><br />
   </cms:if>   
</cms:pages>

In the snippet above, we use the variable 'k_count' to keep track of the current page's position in the list and then display it accordingly (please see http://www.couchcms.com/docs/concepts/pagination.html for a complete list of all the variables set by Couch within the 'pages' tag that can be used for such counting purposes. Also see http://www.couchcms.com/docs/tags-reference/if.html for the 'ge' -greater or equal, 'le' -lesser or equal and other operators used by the 'if' tag for comparision).

To be fair, the method above might seem a bit..geekish:)
An easier method is the following that uses separate 'pages' tag for each group of pages -
Code: Select all
<cms:pages masterpage='property.php' limit='2'>
   <h1><cms:show k_page_title /></h1>
</cms:pages>

<cms:pages masterpage='property.php' limit='5' offset='2'>
   <h3><cms:show k_page_title /></h3>
</cms:pages>

<cms:pages masterpage='property.php' limit='3' offset='7'>
   <cms:show k_page_title /><br />
</cms:pages>

Please notice the use of the 'offset' parameter, in all the 'pages' loop other than the first, that instructs Couch to fetch pages skipping those many pages.
This method also makes it possible to use the three groups of pages at different places on the same webpage, as they are independent of each other.

Take your pick.

Do let me know if this helped.
rather than listing the pages, i want to list the posts.

So maybe this will help somemore. on the page ''News'' i have a number of posts, lets say 20 posts so far. They list them all.

Now i've already got them showing on the index page with a limit of '4' currently. Now they show up with the image, title, and count some of the news-content. Now i wanted to lets say show a second '2' posts so limiting that to just the '2'. However this wont work if i just show with a limit of to. ie <cms:pages masterpage='news/index.php' limit='4'>

and then a second <cms:pages masterpage='news/index.php' limit='2'>

So the first one in blue is fine, however they show the image, title, and some of the conent.

Now the second one in red is where i will show just the title, no image no conent.

Right so next i want the top one in blue to show the recent 4 posts, now the one in red i want to show the following 2, so that would miss the 4 most recent ive done, and display the 5th one in the list but limit to '2'

Have i confused you yet?

in simple terms, i want to list count recent '4' then a second part where i want to list the 5th anf 6th post but in text form only.
Hi Simon,

When I said 'pages' in my last post, I meant the 'cloned pages' of any template - so what you are referring to as 'posts' is exactly what I meant.

I think I understood you right the first time but will try to answer again -
See, within the 'pages' tag ALL the editable regions belonging to a page/post become available. It is up to you as to which of those you display.
So suppose your 'news/index.php' has three editable regions - 'news_content', 'news_excerpt and 'news_image' -

<cms:pages masterpage='news/index.php' limit='4'>
<cms:show k_page_title />
<cms:show news_content />
<cms:show news_excerpt />
<cms:show news_image/>
</cms:pages>


<cms:pages masterpage='news/index.php' limit='2'>
<cms:show k_page_title />
</cms:pages>


- in each of the two loops above, we are displaying different regions (the second only showing the post's title). That shouldn't be the problem.

The problem, as you rightly said, is that the red loop above displays the same posts as that of the blue loop (only 2 less).
You wish it to display the posts number 5 and 6, not 1 and 2.
If you read my previous post, it can be done by using the 'offset' parameter.

You revised red loop will now become -

<cms:pages masterpage='news/index.php' limit='2' offset='4'>
<cms:show k_page_title />
</cms:pages>


I hope I was able to make myself understandable.
Do try it out and let me know.
right now i understand :lol:
@kk, So here's a situation I'm currently facing, similar to the issue above. I have a homepage that needs to lists posts in 3 different sections. Let's assume these posts are associated with any of 3 folders titled News/Articles/Insights.

Section 1 (1 post: Banner / Headline Post) is fetched from the latest post in Articles folder.
Section 2 (2 posts) is fetched from the 2 latest posts in News folder.
Section 3 (6 posts, in random order, ideally) needs to fetch any posts belonging to News, Articles and Insights that aren't already shown in the above 2 sections. i.e. it should fetch 2nd latest Article post/s, 3rd latest News post/s, and recent Insights post/s.

Ideally, I'd need to something like <cms:pages masterpage='blog.php' orderby='random' limit='6' 'and can't figure out this bit'>
Is there some way to do this? This is the part I need help with.

Also, I'm wondering whether to introduce a potential complication, which is have Section 1 (i.e. the Banner/Headline post) be something that is selectable via the admin (perhaps using relation method, or even a boolean in every post saying "Is Headline Post". This implies that the Headline post could belong to any folder. In that case, we will to account for this whilst fetching the posts in Section 2 and 3 as well.

Let me know if this is workable, and if not, I can easily output the posts in a more structured fashion, as you mentioned in your response above.
@imohkay,
The 'id' parameter of <cms:pages> supports 'NOT' so, for example, the following will fetch 10 pages *except* those with ids 210 and 310 -
Code: Select all
<cms:pages masterpage='posts.php' limit='10' id="NOT 210,310">

We can make use of this property to exclude posts shown in previous sections from the sections further ahead.

We do that in the following sample code by storing the ID of each page shown in earlier sections in a global variable (concatanating with the previous values using a comma) -
Code: Select all
<cms:set my_excludes='' scope='global' />

<cms:pages masterpage='posts.php' limit='1'>
    <h3><cms:show k_page_title /></h3>
    <cms:set my_excludes = "<cms:concat my_excludes k_page_id ',' />" scope='global' />
</cms:pages>

<cms:pages masterpage='posts.php' limit='2' folder='news' id="NOT <cms:show my_excludes />">
    <h3><cms:show k_page_title /></h3>
    <cms:set my_excludes = "<cms:concat my_excludes k_page_id ',' />" scope='global' />
</cms:pages>

<cms:pages masterpage='posts.php' limit='6' folder='articles, news' id="NOT <cms:show my_excludes />" orderby='random'>
    <h3><cms:show k_page_title /></h3>
</cms:pages>

In the sample above,, the first section fetches a page from any folder so this is akin to what you asked for in your second point. You can use relation here and things should work just the same (TIP: as an aside, if you are planing to use relations for selecting the page to be shown, try using the 'Advanced GUI' if the number of pages is large - viewtopic.php?f=5&t=11021).

Hope this helps. Do let me know.
Thanks @kk! This is really amazing and works great! I knew I had a to set a variable to get the page_id for exclusion, but had no idea how to go about it. Your detailed explanations are something else, and every member on this forum appreciates all the time you put in :)
I'm looking forward to purchasing 2 licenses in the next two months. I'm getting back to Couch after nearly 3 years, and am surprised how easy it's been to jump back in!
You are always welcome, @imohkay :)
9 posts Page 1 of 1