how to - Permalink from imported category included in code generator

7 posts by 3 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: June 10, 2020   (RSS)

Hello. I hope I can explain this well. 

I have a multi record editor called Artwork. In it, I import a list of categories from another multi record using 'Get options from database'. The category records have a permalink. Everything there works fine and I have a sortable gallery with permalinks when the categories are sorted. Then, if you click on an image from Artwork, you get the detail page of that image. Pretty straight forward and common. 

My struggle is on the detail page, itself. Under the artwork image I list out the categories that artwork is in. I would like those categories to be clickable and then the user can get back to the list page and see all the artwork in the categories. However, I can't figure out how to import the category permalink to the artwork detail page in order to make it a link back to the category page.

Image attached for visual reference. 

Any advise is appreciated.

Attachments:

click.jpg 581K

By Steve99 - June 4, 2020

Hello,

Sounds like a similar scenario as this post:
https://www.interactivetools.com/forum/forum-posts.php?postNum=2244369#post2244369

Referencing that post, essentially the "Restaurants" would be your "Artwork" records and the "Cuisines" would be your "Categories" records.

Hope this helps!

Best,
Steve

By Damon - June 4, 2020

Hi Josh,

The forum post link that Steve posted should have everything you need to get the results you are after.

Can you review and let us know if you have any questions about it that we can help with?

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

The solution in the linked post worked well. 

I added this: 

// load records from 'art_categories'
list($art_categoriesRecords, $art_categoriesMetaData) = getRecords(array(
'tableName' => 'art_categories',
'where' => '`name` IN('.mysql_escapeCSV($artwork_imagesRecord['category:labels']).')',
'loadUploads' => false,
'allowSearch' => false,
));

To use this: 

<?php foreach ($art_categoriesRecords as $record): ?>
     <a href="/<?php echo htmlencode($record['permalink']) ?>" target="_self"><?php echo htmlencode($record['name']) ?> 
<?php endforeach ?></a>

Now, I just have one semi-related issue: 

The foreach outputs the array of "All, Paintings", for example. However, all of the artwork, whether drawings or print making, etc, is in the 'All category. How can I always skip the first key in this array so it never prints 'All'? 

Skipping the first item seems like it might be really simple, but I've tried using an array_slice and various if statements, but my novice self just can't figure it out. 

Thanks for any further guidance. 

By Steve99 - June 10, 2020

Hi Josh,

Glad to hear it helped.

This should work if you're looking to skip the first item of an array:

<?php foreach (array_slice($art_categoriesRecords,1) as $record): ?>

Best,
Steve

Thank you! That is exactly what I needed. I was trying to do similar, but had the ",1" on the wrong side of the parentheses. I just don't write PHP enough to ever get even passably good at it... or even figure out what to search for sometimes. So, this is is much appreciated and saved me a lot of frustration.