Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
Okay, i don't know if this has been updated yet or i'm still waiting for the couch upgrade but just checking if this can be done yet.

I have sections,

Mulitmedia which is the gallery,
Videos
Blog

Now i want to dump them all into one page, so rather than just show them with the couch cms tag i want them to all show, so they show when they was posted rather than the couch tags. IE.

<cms:pages masterpage='blog.php' masterpage='videos.php' masterpage='multimedia.php' > </cms:pages>

rather than separate masterpages. Can this be done?
Hi Simon,

Using multiple masterpages in a single cms:pages listing is not natively supported. However, now that we can run custom SQL queries, what you want can be pulled-off using the cms:query tag.

Please see the '2. Executing custom SQL queries.' section here for details - viewtopic.php?f=5&t=7377

Let me know if you require any assistance with it as it is an advanced topic.
Hi KK,

I've gone and added this code into a template called newsfeed.php and added this page into couch with the require_once tag.

Now its not showing the results.

Code: Select all
<cms:query 
    sql="  SELECT p.id pid, t.name tname
        FROM couch_pages p
        inner join couch_templates t
        on p.template_id = t.id
        WHERE (t.name='msport/index.php')
        AND publish_date < '<cms:date format='Y-m-d H:i:s' />'
        AND NOT publish_date = '0000-00-00 00:00:00'
        ORDER BY publish_date desc;"
    >

    <cms:show pid /><cms:show tname /><br/>

    <cms:pages masterpage=tname id=pid>
       <a href="<cms:show k_page_link />"><cms:show k_page_title /></a><br />
     
    </cms:pages>

    <br />
    <cms:paginator />
</cms:query>



The newsfeed page is located in Public_html/Sport and the page i'm pulling is located in Sport/msport/index.php.

Also the code within that above,
Code: Select all
<cms:pages masterpage=tname id=pid>
       <a href="<cms:show k_page_link />"><cms:show k_page_title /></a><br />
     
    </cms:pages>


How are you showing custom couch tags,

I'm confused with this
Hi Simon,

You have specified only one template the cms:query tag which makes it no different than using cms:pages tag directly.
Anyways, for simplicity sake let us continue with a single template.

Forget cms:query for a little while and place a regular cms:pages tagpair on your newsfeed template. Suppose it looks something like this -
Code: Select all
<cms:pages masterpage='msport/index.php' limit='10' paginate='1'>
   .. output whatever HTML markup you need here..
   <h3><cms:show k_page_title /></h3>
   <cms:paginator />
</cms:pages>

Run the template and make sure the output is correct.
Now add the following code just below the code we added above -
Code: Select all
<cms:query
    sql="  SELECT p.id pid, t.name tname
        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='msport/index.php')
        AND publish_date < '<cms:date format='Y-m-d H:i:s' />'
        AND NOT publish_date = '0000-00-00 00:00:00'
        ORDER BY publish_date desc;"
    limit='10'
    paginate='1'>

    <cms:pages masterpage=tname id=pid>
      .. output whatever HTML markup you need here..
       <h3><cms:show k_page_title /></h3>
    </cms:pages>

    <cms:paginator />
</cms:query>

Run the template. The new code should produce exactly the same output as that of one using cms:pages.

Of course, it'd be silly to use cms:query to do exactly the same thing as done much easily by cms:pages. However, since the raw SQL is available for tweaking, we can now add more than one template to it and this is where cms:query scores over cms:pages.

Suppose you have a second template named 'msport/blog.php'. We can add it to the SQL statement -
Code: Select all
<cms:query
    sql="  SELECT p.id pid, t.name tname
        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='msport/index.php' or t.name='msport/blog.php')
        AND publish_date < '<cms:date format='Y-m-d H:i:s' />'
        AND NOT publish_date = '0000-00-00 00:00:00'
        ORDER BY publish_date desc;"
    limit='10'
    paginate='1'>

    <cms:pages masterpage=tname id=pid>
       .. output whatever HTML markup you need here..
       <h3><cms:show k_page_title /></h3>
    </cms:pages>

    <cms:paginator />
</cms:query>

Now we'll have a list of the titles of pages belonging to both the templates.

Of course, we are only displaying the titles which is a common field for both the templates so we can get away with a single <cms:show k_page_title /> statement.
When it comes to displaying custom field data from both the templates, since the names of the fields would likely be unique to their respective templates, we'll have to test which template a page belongs to.
This is how we can do it -
Code: Select all
<cms:query
    sql="  SELECT p.id pid, t.name tname
        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='msport/index.php' or t.name='msport/blog.php')
        AND publish_date < '<cms:date format='Y-m-d H:i:s' />'
        AND NOT publish_date = '0000-00-00 00:00:00'
        ORDER BY publish_date desc;"
    limit='10'
    paginate='1'>

    <cms:pages masterpage=tname id=pid>
        <cms:if k_template_name='msport/index.php' >
            .. here we have fields belonging to 'msport/index.php' ..
            <h3><cms:show k_page_title /></h3>
            .. show other fields e.g...
            <cms:show my_heading />
            <cms:show my_image />
        </cms:if>
       
        <cms:if k_template_name='msport/blog.php' >
            .. here we have fields belonging to 'msport/blog.php' ..
            <h2><cms:show k_page_title /></h2>
            .. show other fields e.g. ..
            <cms:show my_desc />
            <cms:show my_link />
        </cms:if>
    </cms:pages>
   
    <cms:paginator />
</cms:query>

So, you see, inside the cms:pages used within cms:query, you deal with only a single page out of the list.

You can now add more templates to the mix and output whatever HMTL is required by you.
Hope this helps. Please let me know.

Thanks.
Hi Kamran,

The limit='x' in the query tags doesn't work for some reason.

I have a listing of machinery and two templates, new and used, i'm combining them to show previously sold with custom field <cms:if status =='sold'>

Code: Select all
<cms:query
sql="SELECT p.id pid, t.name tname
    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='new-machinery.php' or t.name='used-machinery.php')
    AND publish_date < '<cms:date format='Y-m-d H:i:s' />'
    AND NOT publish_date = '0000-00-00 00:00:00'
    ORDER BY modification_date desc;"
limit='3'
>

<cms:pages masterpage=tname id=pid>

   <cms:if status =='sold'>
   <div class="row mb20">
   <div class="feed-block">
      <div class="col-lg-4">
         <a href="<cms:show k_page_link />">
         <cms:show_repeatable 'gallery' startcount='1'>
            <cms:if k_count =='1'>      
            <img src="<cms:thumbnail image_file width='700' height='500' />" alt="<cms:show k_page_title />" class="img-responsive" />
            </cms:if>
         </cms:show_repeatable>
         </a>
      </div>
      <div class="col-lg-8">
      <a href="<cms:show k_page_link />" class="title-link">
         <cms:show k_page_title />
      </a>

         <ul>
             <li><i class="fa fa-caret-right"></i> Year: <strong><cms:show year /></strong></li>
             <li><i class="fa fa-caret-right"></i> Model: <strong><cms:show model /></strong></li>
             <li><i class="fa fa-caret-right"></i> Branch: <strong><cms:show branch /></strong></li>
         </ul>
         <a href="<cms:show k_page_link />" class="btn btn-primary btn-md pull-right visible-xs infobtn" role="button">More Info</a>
      </div>
   </div>
</div>
   </cms:if>

</cms:pages>

</cms:query>

Hi Patrick,

The cms:query (that has the 'limit' set to 3) indeed does fetch 3 pages - your enclosed code then filters out from these 3 pages the pages that do not have a status='sold'. This can lead to showing less than 3 pages.

I think you can see the problem.

The solution would be to add the status='sold' filter to the cms:query block itself.
However the SQL required will be considerable more convoluted as the custom fields of the two templates will have to be brought into the equation.
Hi Kamran

I figured as much actually when playing with the code. I'm just struggling to join to get the field for sold at the moment.
7 posts Page 1 of 1