Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
I'm setting up a web site that has different kinds of content (each of which uses a different template) all of which I would like to tag using one, single 'tags' template. (By tags, I'm referring to the category tags used on most blogs.)

Tagging, in itself, is working great:
I already found out how to set up and show blog post tags (thanks to this forum), and the method works nicely. (I.e., you link a 'tags.php' template with your 'blog.php' template via 'type='relation', and go from there.)

Therefore, I've successfully done these two things so far:

1. I set up a 'tags' template and linked it to the 'blog posts' template. This works and displays great. When a blog post is displayed on the site, all the category tags it belongs to are displayed under it. Also, if the site visitor clicks to see a list of all the category tags available, he can see them and click on any tag to see links to all the blog posts that belong to it.

2. I have now also linked the same 'tags' template to a different content type on the site, which is a 'book reviews' template. Doing this does successfully apply the tags to this separate template, because when I view a book review, the proper tags appear underneath it, just as they do for the blog posts.

But now is the hard part:

On a "Show All Tags" list page -- and also in the single-tag view, when I want to show the visitor a list of all items under a particular tag (blog posts and book reviews, in this case), I can't figure out how to incorporate 'blog posts' and 'book reviews' into a single, combined result.

EXAMPLE FOR CLARIFICATION:

This exists in the database:

Content Item - Categories (i.e., Tags)
blog post #1 - pets, events, stories
blog post #2 - events, shopping, sales
blog post #3 - sports, social life, gifts

book review #1 - events, biographies
book review #2 - fiction, sales, publishers
book review #3 - bestsellers, gifts, marketing

... But currently, I can only get my "Show All Tags" page to show this:

"Show All Tags" page:
-pets (1) [book reviews not included in this number]
-events (2) [book reviews not included in this number]
-sales (1) [book reviews not included in this number]
-gifts (1) [book reviews not included in this number]
Etc.

I can count and show all blog posts in the "Show All Tags" page or I can count and show all book reviews in it, but I can't figure out how to merge both into the same results set. Here's what I'm looking for instead of the above:

-pets (1) [one item from blog posts; book reviews has no item yet in this category]
-events (3) [two from blog posts and one from book reviews]
-sales (2) [one from blog posts and one from book reviews]
-gifts (2) [one from blog posts and one from book reviews]
Etc.

---

I know that <cms:pages> can only be used with one masterpage at a time. My guess is that I'd need to figure out how to set up a special SQL select statement and maybe use a variable or two, but I'm out of my depth in that regard.

Does anyone have any ideas?

Hi,

If you'd be comfortable dealing with raw SQL, following two features should be able to help -

1. Add return_sql='1' to your <cms:pages> tag to get the SQL it uses internally.
Tweak it to return whatever result you desire (use your favorite SQL editor to do the tests).

2. Once you have the modified query, use <cms:query> to run it within Couch (please see "2. Executing custom SQL queries." section at viewtopic.php?f=5&t=7377).

Hope this helps.

Sum up 2 counts for each tag, it is not a sin to run 2 cms:pages counts.

Re:

KK wrote: Hi,

If you'd be comfortable dealing with raw SQL, following two features should be able to help -

1. Add return_sql='1' to your <cms:pages> tag to get the SQL it uses internally.
Tweak it to return whatever result you desire (use your favorite SQL editor to do the tests).

2. Once you have the modified query, use <cms:query> to run it within Couch (please see "2. Executing custom SQL queries." section at viewtopic.php?f=5&t=7377).

Hope this helps.


It does help. Cracks open a door to a whole new level of functionality. I'll work on this. Thank you, as always.

Re:

trendoman wrote: Sum up 2 counts for each tag, it is not a sin to run 2 cms:pages counts.


Thanks, Trendoman.

At first, I was indeed considering using two <cms:pages> blocks, one to list "tags for blog posts" and one to list "tags for book reviews", separately but on the same page. Not ideal, but definitely better than nothing, for sure.

Is that what you were thinking? Or are you saying that with some variable shuffling or the like I might be able to merge the counts into one combined result for each tag?

By the way, just out of curiosity, is it possible to run one <cms:pages> loop inside an entirely different <cms:pages> loop? Nested like? For the record, I guess I doubt it due to variable collision.

Thanks again, T.

I meant running and summing like this -
Code: Select all
<cms:set pets_posts = "<cms:pages ... count_only='1' />" />
<cms:set pets_reviews = "<cms:pages ... count_only='1' />" />
<cms:set pets_total = "<cms:add pets_posts pets_reviews />" />
..
Pets (<cms:show pets_total />)

What? There's a count_only parameter??

Thanks for the example. Nice technique. Thanks, T.

There's a book I want to buy whenever it comes out: The Mechanics and the Magic of CouchCMS. Online only is fine. Incomplete is fine. Based on the myriad posts and helpful answers on the forum, there seems to be so much cool method and power under the hood.
7 posts Page 1 of 1
cron