Aggregation and Views: Link to original source; adding categories

femrich - November 3, 2007 - 10:08
Project:Aggregation
Version:5.x-4.0
Component:Code
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

I have both the aggregation module and views running on my site. I have created some feeds and those are generating feed items.

Now I want to create a few views to present feed items in a list. Basically I want to separate my feed items by categories and to have the titles appear to readers as links to the original source, not to the nodes on my site. One reason for this is that I don't want to publish the item nodes on my site without permission--it's more manageable for me just to link back to the original source.

Question #1: How do I make the title in the view link to the original source? If I just use node title, that links back to the (unpublished) node on my site. Is it possible to use Node Title in the view and get it to link back to the original? Or is there some other field I should be looking for to add to the view?

Question #2: I see that the aggregation module collects links from sources and applies them to feeds. That's fine. But I'd also like to create a category (such as those used in the core Aggregator module) just for the main feeds and primarily to sort them into separate views. Is there a problem with doing this?

Question #3: I don't want to give my readers permission to view unpublished content. If I create views using the feed item title (or other field that links back to the original source), will they be able to see the title and use it as a link to original even if those items are unpublished?

Thanks for this module and for any suggestions you can offer.

#1

femrich - November 3, 2007 - 10:10

Oops. Caught a typo. Above where I wrote:

Question #2: I see that the aggregation module collects links from sources and applies them to feeds.

What I meant to write was:

Question #2: I see that the aggregation module collects categories from sources and applies them to feeds.

#2

drewsterumd - November 11, 2007 - 06:35

I am looking for similar functionality -- I want to establish a View for a block that allows me to link to the original source as opposed to the url for the node. Ideally this fix will be integrated into the module in a format that is easy to implement, but I'd be willing to hack the module or template file in order to implement it.

I think this would be an important and valuable addition to the module in the future.

Thanks,
Andrew

#3

femrich - November 12, 2007 - 09:57

I've gotten partway there. I set up a view using Node Title and Original Url as fields. Of course, the original urls are ugly, and there seems to be no automated way (in Views at least) of turning them into links--they just appear as urls that must be cut and pasted into a browser window. So I will have to look into how to theme the view so that it uses the link as part of an href tag applied to the Node Title field. Whee!

#4

drewsterumd - November 12, 2007 - 12:48

Thanks, Femrich... I've gotten that far as well, just don't know how to turn the Original URL into the link for the Node Title. So far, this is as far as my PHP/Drupal skills have gotten me. Let me know what you find. Thanks for looking into this for me.

Andrew

#5

femrich - November 13, 2007 - 03:57

This is on my "to do" list (after theming a new CCK type). Will let you know if I find an answer. Would appreciate it if you do the same.

Best regards,

Frederick

#6

samc - November 14, 2007 - 04:01

I'm trying to do something similar, but I'd like to override the title links in search results.

For your problem, I'd look at creating a custom node template, e.g. node-feed-item.tpl.php [see http://drupal.org/node/117491].

You'll be able to override the title with the original URL.

#7

femrich - November 14, 2007 - 06:23

Thanks for the suggestion. I think you are right about how to approach this. The trick for me will be figuring out how to turn the URL into a link in the new template. I'm sure it isn't all that difficult, but it would be my first foray into the wild world of PHP.

#8

samc - November 14, 2007 - 14:21

The PHP part may be as simple as copying the existing node.tpl.php into node-xxx.tpl.php and changing

<?php
print $node_url;
?>

into

<?php
print $node->url;
?>

It may be tricky trying to figure out the right name for the file...

#9

peggys mouse - November 26, 2007 - 04:58

i have just been trough a lot of similar issues so i offer a few tips..

for theming views, use a list type view along with the views theme wizzard module. it will help you create views-list-view_name.tpl.php template which you can then customize. it will show you a list of available variables including the $node variable which may contain other variables which you can access.

to remove the bullets in the list view, you can do this to the code provided by the wizzard in your template.php:

<?php
 
if ($items) {
   
//return theme('item_list', $items);
   
return implode(" ",$items);
  }
?>

for the same nodes being displayed outside of a view, such as one promoted to the front page, you can use a node-aggregation_item.tpl.php file in your theme assuming you are using the default content types for your feed nodes.

you can use this to print out available variables if you like:

<?php
   
print '<pre>';
   
print_r(get_defined_vars());
    print
'</pre>';
?>

hope this helps.

#10

mauror - April 27, 2008 - 20:00

You could hack the template file... I know it's ugly, but you can do something like...

   <div class="view-field view-data-title">
      <h2><a href="<?php print $url ?>"><?php print $title ?></a></h2>
  </div>

(You must add "Aggregation: URL" as field in the view)
In the example above I assume that you want to show the title as a <h2>, you should change accordingly.
Sorry I don't know how to code neither in PHP neither in Drupal, I just used the Theme Wizard, followed the instructions and changed things quite randomly around... :(

#11

dakotaroar - January 27, 2009 - 03:30

I think this is an excellent idea. It makes much more sense to link to the original source than to link to a node. Of course, I can't even get the views integration to work, so I'm probably out of luck anyway.

#12

robobeau - April 9, 2009 - 15:43

Yo. I know it's probably possible to override the Title's URL with the Original Article URL, but I cannot, for the life of me, find the function I need to do so.

Could anybody point me in the right direction? I think this would be a nice additional featured as well, but I'd happy to hack up a solution.

#13

robobeau - April 17, 2009 - 20:36

In case anyone is still interested in this, I hacked up a nice workaround. I'm still trying to figure out how to do this through one of the themeable Views functions, but this one works fine for me (for now).

Basically, if the node has the "Display link to original URL" option set to anything BUT the first option, the link to the node will be replaced by the original article's URL.

It's not a very graceful hack, but here you go. On views_node.inc, replace the following function:

function views_handler_field_nodelink($fieldinfo, $fielddata, $value, $data) {

// Hacked to HELL, by René & Rick

$node = node_load($data->nid);
$var = unserialize($node->aggregation_item_options);

  if ($fielddata['options'] == 'nolink') {
    return check_plain($value);
  } else if($var[link_to_original_url] != 0){ 
    return l($value, $data->aggregation_item_url);
  } else return l($value, "node/$data->nid");
}

 
 

Drupal is a registered trademark of Dries Buytaert.