Reverse Relationship and categories?
Posted: 19 September 2007 04:07 PM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  534
Joined  10-24-2005

Is it possible to utilize {reverse_related_entries} tags and show the reverse related results by category?  I’d like to have anchor tags that link to “domain.com/template_group/template/category/url_title” and limit the output to reverse related entries.

Is this possible?  The following is not working for me…

{exp:weblog:entries weblog="{weblog}"}

    {reverse_related_entries weblog
="{weblog_reverse}"}
        
<p>{body}</p>
    
{/reverse_related_entries}

    {
/exp:weblog:entries}

...when I try to link to it via:

<ul>
    
{exp:weblog:categories weblog="{weblog_reverse}" style="linear"}
         
<li><a href="{path=template_group/template}">{category_name}</a></li>
    
{/exp:weblog:categories}
</ul>

Any help is greatly appreciated!

Profile
 
 
Posted: 20 September 2007 03:34 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  534
Joined  10-24-2005

Bump:)  Anyone?

Profile
 
 
Posted: 23 September 2007 01:36 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  534
Joined  10-24-2005

Anyone?  Help, please:)

Profile
 
 
Posted: 26 September 2007 07:19 AM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  173
Joined  03-07-2007

Maybe you can elaborate the question a bit. What happens with the above code, and what are you trying to do.

Profile
 
 
Posted: 26 September 2007 07:27 AM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  534
Joined  10-24-2005

I have a list of categories like so:

<ul>
    
{exp:weblog:categories weblog="{weblog_reverse}" style="linear"}
         
<li><a href="{path=template_group/template}">{category_name}</a></li>
    
{/exp:weblog:categories}
</ul>

I would like to link to a page that is pulling in the weblog data via reverse relationship.  I’d like this data to be categorized based on the categories of the reverse related weblog.

For example:
I have a weblog called documents and these documents are reverse related to a weblog called projects.  The documents have many categories.  So, when I show all the documents associated with a particular project via reverse relationship tags, I’d like to be able to show the category they belong to.  Make sense?

Profile
 
 
Posted: 26 September 2007 07:50 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  173
Joined  03-07-2007

Makes almost sense. Aren’t the documents related to one project (so that a project is reverse related to many documents)?

Profile
 
 
Posted: 26 September 2007 08:19 AM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  534
Joined  10-24-2005

Yes, that is correct.

I want the URL structure to be:
domain.com/templategroup/template/category/project  OR domain.com/templategroup/template/project/category


And I’d like the page to have results:

category1:
list of documents

category2:
list of documents

category3:
list of documents

These results would be specific to the project they are related to.

EDIT/ADD:  Also, I’d like to have a list of category links that filter the list based on the category.  So, I don’t think I was completely clear in the above.  I’d like a way to list documents “all” categories and then a way to list “by category”

Profile
 
 
Posted: 26 September 2007 09:27 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  173
Joined  03-07-2007

projects_weblog (title, body)
docs_weblog (title, body, relationship>projects_weblog)

{assign_variable:my_weblog="projects_weblog"}

{exp
:weblog:entries weblog="{my_weblog}"}
<h3>{title}</h3>

{reverse_related_entries} <!-- if you have more relations then specify weblog="" -->
  <
b>{title}</b>
  
{categories}
    
<i>cat: {category_name}</i> -
  
{/categories}
  {if no_reverse_related_entries}
    
<small><i>No reverse-related entries found (docs)</i></small>
  
{/if}
  
<br />
{/reverse_related_entries}

{
/exp:weblog:entries}


This shows the docs for a project. I don’t see in the docs that you can order reverse_related entries by categories.
And with a category archive tag i can’t seem to find if you could limit to one related_entry
http://expressionengine.com/docs/modules/weblog/category_archive.html

I think you might end up with using a query… sorry i couldn’t help you more with this…
I hope someone with a bit more EE-finesse comes along

Profile
 
 
Posted: 26 September 2007 09:33 AM   [ Ignore ]   [ # 8 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  534
Joined  10-24-2005

Thank you GDan.  I think I’ve tried this, but I’ll give it another try and let you know if it works for me.

If it doesn’t work, are you suggesting that a query would work?

Profile
 
 
Posted: 26 September 2007 01:52 PM   [ Ignore ]   [ # 9 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  173
Joined  03-07-2007

I really don’t know enough just yet about EE tags for this particular issue… i’ve spent a few minutes (*cough*) on this but what you want with these related entries and categories is a peculiar thingy. (Show all reverse-related docs from a project, grouped and ordered by or within a specific certain category). Hope some EE or EE-SQL guru comes by.

Profile
 
 
Posted: 29 September 2007 08:47 PM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  165
Joined  09-29-2007

hi stephen, i’ve been following your progress on the project management thread and am looking forward to seeing it in action. 

regarding the problem you are having in this thread, a query would definitely work.  this would probably involve writing a small plugin to return the entries categorised and in the correct order.  if you want help with this then let me know, i’d be happy to help out.

can you please clarify that this is what is supposed to happen:

given a project, all the documents that are related to that project should be returned, grouped into their appropriate categories

 Signature 

* Get the Sitemap Module and improve your site’s SEO

More Add-ons: Multi Language, iWebApp, Stand-Alone Image Editor, Landing Page, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
Posted: 29 September 2007 08:57 PM   [ Ignore ]   [ # 11 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  534
Joined  10-24-2005

Ha, this response couldn’t have come at a better time.  I’m sitting here in bed watching football and trying to figure this query out:)

Yes, I believe you got it.  I’m attaching a screenshot that should help communicate what I’m needing.  Each of the documents are single entries in a weblog called cs_planning.  These documents are categorized.  Also, these documents are related to a weblog called cs_projects.

Thanks for your suggestions.

Image Attachments
planning.gif
Click thumbnail to see full-size image
Profile
 
 
Posted: 29 September 2007 09:06 PM   [ Ignore ]   [ # 12 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  534
Joined  10-24-2005

I may have not been clear on that last part.  Each of the entries in cs_planning are related to an entry of cs_projects.

Profile
 
 
Posted: 29 September 2007 09:49 PM   [ Ignore ]   [ # 13 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  165
Joined  09-29-2007

ok, well this turned out to be a bit of a head melter.  the following php code put in a plugin (and maybe given a once over) should do the trick.

removed by author, see below

 Signature 

* Get the Sitemap Module and improve your site’s SEO

More Add-ons: Multi Language, iWebApp, Stand-Alone Image Editor, Landing Page, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
Posted: 30 September 2007 03:42 PM   [ Ignore ]   [ # 14 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  165
Joined  09-29-2007

stephen, after some testing of the code in the last post i realised that there were a few things missing.  i’ve tested this code and it works for me so i hope its what you need.  let me know if you have any questions or if i can help with anything else.


// assume that the project entry title has been provided
$project_title = "Test project 1";


// 1. we get the entry id of the related project
$sql = "SELECT entry_id FROM exp_weblog_titles WHERE title = '".$project_title."'";
$query = $DB->query($sql);
$row = $query->row;
$my_related_entry_id = $row['entry_id'];


// 2. we get the field id of the relationship field
$sql = "SELECT field_id FROM exp_weblog_fields WHERE field_type = 'rel'";
$query = $DB->query($sql);
$row = $query->row;
$my_field_id = $row['field_id'];


// 3. we get all of the entries (joined with the categories and relationships) that are in the right weblog and that are related to the project and sort them by category id
$sql = "SELECT * FROM exp_weblogs JOIN (exp_weblog_titles, exp_weblog_data, exp_category_posts, exp_categories, exp_relationships)
ON exp_weblogs.weblog_id = exp_weblog_titles.weblog_id
AND exp_weblog_titles.entry_id = exp_weblog_data.entry_id
AND exp_weblog_data.entry_id = exp_category_posts.entry_id
AND exp_category_posts.cat_id = exp_categories.cat_id
AND exp_weblog_data.field_id_"
.$my_field_id." = exp_relationships.rel_id
WHERE exp_weblogs.blog_name = 'cs_planning'
AND exp_relationships.rel_child_id = '"
.$my_related_entry_id."'
ORDER BY exp_categories.cat_id ASC"
;

$query = $DB->query($sql);


// we can now group the entries by categories

 Signature 

* Get the Sitemap Module and improve your site’s SEO

More Add-ons: Multi Language, iWebApp, Stand-Alone Image Editor, Landing Page, LogMeIn, Loop Plugin, Session Variables

Profile
 
 
Posted: 30 September 2007 07:17 PM   [ Ignore ]   [ # 15 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  534
Joined  10-24-2005

Hi Ben,

FYI…  I private messaged you to discuss this topic in more detail.  Thanks.

Profile
 
 
Posted: 24 December 2007 03:37 AM   [ Ignore ]   [ # 16 ]  
Summer Student
Total Posts:  1
Joined  09-16-2007

I’m facing the same thing, sorting reverse relationships by categories. Do you have any progress on this matter? THanks!

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 65027 Total Logged-in Users: 41
Total Topics: 82116 Total Anonymous Users: 18
Total Replies: 441313 Total Guests: 181
Total Posts: 523429    
Members ( View Memberlist )