Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
I saw a guy ask this question so thought it wise to bring it here and he says:

I'm making a blog with couchcms. So I am trying to figure out how to create a section below every blog post on my website with 3 related posts.

Thanks in advance.
The simplest way would be by using 'relations' - please see http://docs.couchcms.com/concepts/relationships.html

While all the examples in the link above use two templates to create the relations, there is no problem in relating a template to *itself*. So, suppose your template is 'blog.php', you may add an editable region to it this way -
Code: Select all
<cms:editable type='relation' name='related_posts' masterpage='blog.php' />

As you can see, we are relating blog.php to blog.php. So, while editing a post you'll see a list of all other posts.
You can manually select which of the posts are related to the current post being edited.

On the front-end, in the page_view, use <cms:related_pages> (as show in the link above) to output the posts related to the page being displayed.

Hope it helps.
KK, I am very much impressed with how swift you reply to problems and the patience with which you answer them. Will post your response to Stack Overflow where I found the question.

I have a personal question too, on blog page-view I have a next and previous buttons that loops through all blog posts. How do i make these buttons show the title of the next or previous blog posts so users know what they are about to read next. Thank you
Thank you for the kind words :)

Replying to your query -
on blog page-view I have a next and previous buttons that loops through all blog posts. How do i make these buttons show the title of the next or previous blog posts so users know what they are about to read next

The easiest way to do so for a blog (because here posts are sorted by publish_date) would be as explained in the following thread -
viewtopic.php?f=2&t=21

You can find more ways here -
viewtopic.php?f=8&t=7087

Hope it helps.
I want the highlighted text in the image attached below to be the "Title of the next blog item".
Next blog.JPG
Next blog.JPG (85.87 KiB) Viewed 1299 times


I used the code below but it rather outputs the "Title" of the current post instead of the next
Code: Select all
<cms:set page_name=k_page_title />


This is how I used it in my code
Code: Select all
<cms:set page_name=k_page_title />
             <cms:php>
                  global $CTX;
                  $page_ids = explode( ",", "<cms:pages ids_only='1' />" );
                  $cur_page_id = "<cms:show k_page_id />";
                 $pos = array_search( $cur_page_id, $page_ids );
                  if( $pos!==FALSE ){
                  if( $pos>0 ){
                     // Prev page id
                     $prev_page_id = $page_ids[$pos-1];
                     $CTX->set( 'prev_page_id', $prev_page_id, 'global' );
                  }
                  if( $pos<count($page_ids)-1 ){
                     // Next page id
                     $next_page_id = $page_ids[$pos+1];
                    $CTX->set( 'next_page_id', $next_page_id, 'global' );
                  }
                  }
            </cms:php>
                       <div class="comments_section">
                        <cms:if prev_page_id >
                           <cms:pages id=prev_page_id skip_custom_fields='1'>
                         <div class="prev-button"><a class="ajax-link" href="<cms:show k_page_link />">Next Blog</a> | <cms:show page_name /></div>
                              </cms:pages>
   </cms:if>
Hi KK, never mind. I found a solution. The problem was from my side but I found it. Thank you very much
KK, how do I automatically list related posts instead of maually selecting them inside the admin page? Thank you
7 posts Page 1 of 1
cron