Related articles by texonomy

Events happening in the community are now at Drupal community events on www.drupal.org.
jiatao's picture

Trying drupal for the first time, great system, very easy to use once over the learning curve.
But ran into a wall when tried to create a link of the headline of a related post.

So, I am trying to make a little block displaying the day's top headline, nothing fancy just the latest piece of news article displayed with picture, title and summary, all created in an easy view block.
But in addition, I want to put only the headline of another article related to the top headline by author entered Tags.

In short, every article is tagged with custom taxonomy. A view displays 1 LATEST article. I wish to display in addition the headline of another post related to the top headline by tags.

I've found articles instructing me to use Argument and take either node or taxonomy terms from the URL, but since the top headline is only a block on the main page, there is nothing useful in the URL.
Oh, I am using drupal 7, so all the "related content" modules don't work.

I feel like this is something that one should accomplish without having to venture into the dark undergrowth of custom themeing, but... and sorry for the rambling post.

Comments

A solution with views could be tricky

citlacom's picture

As i understand your problem you are trying to build 2 blocks:
- top deadline
- related to top headline.

The problem with 2 views blocks is that are not communicated one to other and as result the problem is: how the second view will know about what taxonomy terms has the selected node from the first view. In this way is not possible because the first block will be changing the node in the course of the time by the publishing of new contents.

Maybe is possible to do this with Views but it will take you so much try and fail test and will be very tricky solution. Then i suggest you to create a hook_block that act as gate between 2 views, then you can use the second view with arguments and the job of hook_block is to retrieve the taxonomy of the first content and pass to the second.

How to do that:

Create your hook block and call to the function: $view = views_get_view('name_of_your_view');
This will retrieve you the object view and you can execute all the methods (execute, execute_display, preview, render) to that view.

For example:

$view = views_get_view('viewname');
print $view->execute_display('default', $args);

With something like this you can get the result 1 from view 1, take that node nid and taxonomy terms and pass to the second view as arguments.

Hope this is useful for you.

Cheers.

1 transition function in template.php?

jiatao's picture

I see... so, correct me if I am wrong, you are saying create a function in Template.php to catch the content from the "headline" view then pass on the taxonomy terms into the "related" view as arguments.

so what i need is 1 function in template.php that invokes both views, and does the transaction.

Interesting, I'll let you know how that works out.

Oh yea, of course, big thanks!

views_get_view_result returns node array

jiatao's picture

Hey citlacom,

So the following is what I added to the View tpl file:

<?php
$x
=views_get_view_result('top_headline', 'Block', $args);
        
print_r($x);
?>

And the result was something like this: (we are using 'node' not fields in our view);

Array
(
[0] => stdClass Object
(
[nid] => 188
[node_created_hour] => 2011020817
)

[1] => stdClass Object
    (
        [nid] => 165
        [node_created_hour] => 2011011214
    )

)

are these the nodes displayed by the view? how do we extract these nodes and pass the taxonomy into a different view?

I am little vague on the variable scoping in drupal...

Thanks,
Jiatao

Views Developers

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: