I’m working on a portfolio site. A few months ago, I wrote some query logic that (combined with a little reverse_related_entry magic and the count tag) helped me get the site working the way I intended for it to work.
When I recently upgraded to 1.6, that set of logic broke down. I’ve done a decent amount of troubleshooting by stripping down my code, isolating templates, etc., and I think I’ve found the culprit. I just don’t know if it’s a bug or if it’s something that I can fix on my end, and I would love some help.
(An aside to those who have helped me with queries before: This is indeed the same site as this thread, but it isn’t the navigation that has flummoxed me this time.)
CURRENT SITE STRUCTURE
I’ll streamline my structure a little to see if I can explain myself clearly.
1. I’ve got a weblog called “clients” and one called “projects.”
2. The “projects” weblog contains a custom relationship field (“projectclient”) that allows me to assign each project to a client.
3. The primary navigation is a list of categories that have been assigned to “projects.”
4. The navigation links to category pages with a secondary navigation listing the clients that have projects associated with that category.
5. On those category landing pages, I would like to show the most recent project associated with the top client on the secondary navigation list.
It is this final point that is no longer working.
HOW IT WORKED UNDER 1.5.2
Under 1.5.2, I had written a query that took the category designation from segment_2 and returned the url_title of the client that I wanted to feature. I then fed that url_title to an exp:weblog:entries tag and called up a list of projects associated with that client using a reverse_related_entries tag. Finally, I used an “if count == 1” conditional to display only the first entry from the resulting list of projects.
Here’s a simplified version of the code:
{exp:query sql="SELECT DISTINCT url_title as firstclient
FROM exp_weblog_titles
LEFT JOIN exp_relationships ON exp_weblog_titles.entry_id = exp_relationships.rel_child_id
INNER JOIN exp_category_posts ON exp_relationships.rel_parent_id = exp_category_posts.entry_id
INNER JOIN exp_categories ON exp_category_posts.cat_id = exp_categories.cat_id
WHERE exp_categories.cat_name='{segment_2}'
ORDER BY url_title
LIMIT 0, 1"}
{exp:weblog:entries weblog="clients" url_title="{firstclient}" disable="member_data|pagination|trackbacks"}
{reverse_related_entries weblog="projects"}
{if count == 1}
{projectcaption}
{/if}
{/reverse_related_entries}
{/exp:weblog:entries}
{/exp:query}THE PROBLEM
When I upgraded to 1.6 (build 20070626), the count part of that logic stopped working. My list of projects no longer displays just the first one. Instead, it displays the entire list.
I discovered the reason for this when I added a {count} tag next to {projectcaption}: each project in the list was given a count of 1.
I did a little other troubleshooting and determined that it must have something to do with the query, because when I removed the query and hard-coded a url_title into the exp:weblog:entries tag, the count tag worked as expected, and each project entry received a distinct number (1, 2, 3…).
THE QUESTION
Why did this stop working when I upgraded to 1.6? Do I need to construct my query differently, or could this possibly be caused by a bug in 1.6? Ultimately, how can I get this working again?
I hope I’ve described this clearly enough, but let me know if you need examples or anything else.