Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Perhaps I approached this wrong but I'm hoping someone can set me on the right path while I struggle to make this work...

First, I have a categories page that I setup a relation to products. On the products page I have an image gallery that's I've also created a relationship within.

What I'm trying to accomplish is to list each product on a category page. This works fine. Next I'm trying to reference the first image from the related galleries of the products and this is where it fails. If I just make a cms:pages call it will pull from the entire pool of images and each product gets the same image. If I attempt to make a cms:reverse_related_pages call like I do from the products page I get an error because the category page doesn't have a relation to the gallery.

Any assistance is appreciated. I'm thinking I may need to just tap into the db directly with a query but I thought I'd ask first.

thanks!


for reference:

Code: Select all
<cms:reverse_related_pages 'cat_prod' masterpage='products/product-detail.php' orderby='sort_order' order="asc">
<div>
   <!-- this is the part that's broken because the index page doesn't have a relation to the product gallery -->
   <cms:reverse_related_pages 'product_photos' masterpage='products/template_product_gallery.php' orderby='sort_order' limit='1' order="asc">
      <img src="<cms:show gg_image />" alt="">
   </cms:pages>
   
   <h3><a href="<cms:show k_page_link />"><cms:show product_name /></a></h3>
   <a href="<cms:show k_page_link />">Learn More</a>
</div>
</cms:reverse_related_pages>
Hi, how do you defined relation to gallery?
On the products page I have an image gallery that's I've also created a relationship within.

You have to post relevant cms:template definitions, imo.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Also, sorting is not working?
orderby='sort_order'

If you have a variable sort_order then placing it in single quotes makes couch ignore it, because it looks for a constant and it does not exist. To use with variable remove quotes or make expression in double quotes. Both will work correctly:
orderby=sort_order
orderby="<cms:show sort_order />"
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
I'll take a look at the sorting single/double variable thing....

The gallery template:
Code: Select all
<?php 
   require_once( '../ryzecms/cms.php' );
?>
<cms:template title='Gallery' clonable='1' dynamic_folders='1' gallery='1' hidden='1' order='330'>
<cms:editable
    type='relation'
    name='photo_product'
    masterpage='products/product-detail.php'
    has='one'
    no_gui='1'
    label='-'
/>
</cms:template>
<cms:editable
      name="gg_image"
      label="Image"
      desc="Upload your main image here"
      width="600"
      show_preview='1'
      preview_height='200'
      type="image"
   />

   <cms:editable
      name="gg_thumb"
      assoc_field="gg_image"
      label="Image Thumbnail"
      desc="Thumbnail of image above"
      width='115'
      height='115'
      enforce_max='1'
      type="thumbnail"
   />
   <cms:editable name='image_description' label="Image Description" type='richtext' />
   <cms:editable name='sort_order'
    label="Sort Order"
    type='text'
  />
<?php COUCH::invoke(); ?>


This is the area within the product page where I display the gallery:
Code: Select all
<div>
<cms:reverse_related_pages 'photo_product' masterpage='products/template_product_gallery.php' orderby='sort_order' order="asc">
   <div>
      <img src="<cms:show gg_image />" alt="">
      <a href="<cms:show gg_image />" class="popup-img overlay" title="<cms:show k_page_title />"><i class="fa fa-search-plus"></i></a>
   </div>
</cms:reverse_related_pages>
</div>
From what I can see, the code you are using is not correct -
<cms:reverse_related_pages 'cat_prod' masterpage='products/product-detail.php' orderby='sort_order' order="asc">
<div>
<!-- this is the part that's broken because the index page doesn't have a relation to the product gallery -->
<cms:reverse_related_pages 'product_photos' masterpage='products/template_product_gallery.php' orderby='sort_order' limit='1' order="asc">
<img src="<cms:show gg_image />" alt="">
</cms:pages>


<h3><a href="<cms:show k_page_link />"><cms:show product_name /></a></h3>
<a href="<cms:show k_page_link />">Learn More</a>
</div>
</cms:reverse_related_pages>

1. the closing tag should be </cms:reverse_related_pages> (and not </cms:pages>)
2. the name of the relation region appears to be wrong to me - going by your other code snippet, the name should be 'photo_product' (and not 'product_photos').

Please try your code after rectifying the mentioned problems.

It ideally should work because when we are within the outer <cms:reverse_related_pages> block, the pages being fetched are that of 'products' - so the next <cms:reverse_related_pages> will be in the context of products and should be aware of the reverse relation products have with the gallery images.

Hope it helps.
I think the closing tag is a typo from when I was trying multiple versions of the code, however, you hit the nail on the head with the photo_product reference. it appears to be working as expected.

I'll beat on it a little more just to be sure. This is what I get for not rechecking my code after an all-nighter. lol

I appreciate the second (and third) set of eyes.
6 posts Page 1 of 1