SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Drupal / Node Refrencing / Views (and Reverse Referencing?)

    Here's what I have:
    Drupal 6.x with 3 content types:
    - Con1
    - Con2
    - Con3

    All three have their own template files and I can access everything in the $node object. I can also use things like node_load() to load other nodes, views_embed_view() to embed views, etc. I can also pass values into views_embed_load() in order to create conditional views. A very handy thing to do, I might add...

    Here's the problem:
    I'm having a hard time generating links to Con1 content from within Con3 content if and only if Con2 content is node-referenced from a single Con1 CCK field using nothing more than the current Con3 content's $node->nid.

    I need help:
    Would anyone have any suggestions about how to go about achieving this? I thought the reverse node reference module would help, but I can't even tell if it's doing ANYTHING... It seems to be a somewhat flaky module as far as I can tell but I'm assuming this is just because I don't know how to use it within Views yet. I then thought I might be able to use the Con2 NIDs from within Con3 as I have already used node_load to load their objects into my Con3 template, but the problem is that this is somewhat static--there's no way to determine if something has been node-referenced or not (which is why I tried using that module above).

    Any insight or feedback is appreciated.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,017
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    It's the end of the day so I might be a bit thick but can you explain what is is that you want to do?

    You've got 3 content types and you're trying to reference content from one type into another somehow... Now I'm intrigued and I'll help if I can but I need a little more info.

    Cheers,
    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  3. #3
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Andrew and thanks for responding. I'll try to explain this from another angle that might make a little more sense:

    Let's say we have 3 content types of the following (which all use their own template files):

    1. Products Page
    2. Application Page
    3. Organization Page


    Now let's say that we want to include links to product pages on the organization pages if and only if each product page node-references an application page that is being node-referenced from an organization page (including links to product pages if the product pages are node-referencing the same application pages that the organization pages are node-referencing).

    Does that help? The rationale behind all this mess is that a product can encompass multiple applications and we have organizations which have multiple products but from everything, we're just trying to avoid duplicating labor because we can do a simple node-reference field from the organization page for product pages, but this constitutes a manual entry. We want this to be programmatic (automatic) by somehow making the organization template file determine which application pages have been node-referenced and based on that finding, determine whether or not those application pages being node-referenced from organization pages == those being node-referenced from product pages. If they do, then this would mean that that the product page is a product belonging to the organization.

    (I hope that clears it up a bit. If we have to, we can go with the node-reference field on the organization template, but again, we're just trying to make everything as automatic as possible.)

  4. #4
    SitePoint Wizard Wolf_22's Avatar
    Join Date
    Jul 2005
    Posts
    1,700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This one must be a biggie for everyone... Well, rest assured: I found a solution using nothing more than Views.

    Here's how it works:

    1.) Create a default view. Give it a name, etc. Nothing special here.
    2.) You will use the fields area to link to the final node you wish to output links to. Keeping that in mind, if content_type_1 needs links to content_type_3 if and only if content_type_2 is being referenced by both content_type_1 and content_type_3, then you will use the relationships area to create a relationship of the CCK field that ties everything together (the node_reference field). Make sure the relationship is required, too.
    3.) I decided to embed my view (put the specific view call inside the template file with views_embed_view('<name of view>', 'default', $views_argument), so this meant that I needed the argument area to create a views argument of the same type as the node_reference field I used in the previous step. I set this argument to be of the content_type_2 type, allowed it to validate for user access, and also allowed multiple arguments (which is imperative if using an array).
    4.) I then sorted in ascending order and filtered against content_type_3 (making sure to also create a filter of being published).

    Worked like a charm using Drupal 6.x, Views CCK w/ Node Reference 6.x-2.9, and Views 6.x-2.16 on a hot, dry, and somewhat muggy summer day with 1 grande iced-coffee from Starbucks...

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,017
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I'm glad you figured it out... I often figure out my solutions while composing a posting on SP myself... It forces me to think it through thoroughly.

    I thought it would be possible using views; Oh how I love views, the make me look like a genius. I haven't had time yet to review your explanation but I'll do that this afternoon.

    Cheers,
    Andrew
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  6. #6
    SitePoint Zealot bronze trophy
    Join Date
    Jan 2012
    Posts
    116
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Wolf_22 View Post
    Now let's say that we want to include links to product pages on the organization pages if and only if each product page node-references an application page that is being node-referenced from an organization page (including links to product pages if the product pages are node-referencing the same application pages that the organization pages are node-referencing).
    I think you just turned my brain in to a pretzel.

    This post should come with a warning message. I might have to sue. Makes me think of a Drupal T-shirt I saw: "I don't know the question, but the answer is views."

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,017
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by CMS Dude View Post
    I think you just turned my brain in to a pretzel.

    This post should come with a warning message. I might have to sue. Makes me think of a Drupal T-shirt I saw: "I don't know the question, but the answer is views."
    Yeah, that is some crazy Ninja, Voodoo stuff you're working on Wolf_22.... I'm still not quite sure exactly what you're doing but I'm glad you got it figured out... I've been thinking about it off and on and the first thing I would try is Taxonomy to act as a link but I don't think it would be flexible enough so then I'd try something way out there like Organic Groups. I've done lots with CCK and Views but I don't think I've done anything quite like that.

    PS: CMS Dude, I want one of those t-shirts
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •