How To Build A Personal Nodetracker

(Submitted Wed, 2006-09-27 01:50) | |

I've received a number of emails since the launch of What Would Drupal Do regarding my personal nodetracker (see the righthand side of the screen, towards the bottom). As a result, I made a post on the drupal.org forums offering to open the nodetracker up to the public, so that people could individually track their own nodes. There was a surprising lack of response, given the number of inquiries I'd received.

I figure there are two probable reasons for this.

1) People want to run a nodetracker on their own sites, not someone else's.

2) Some people were inquiring not because they want a nodetracker per se, but because they are simply curious about how it is set up.

So to satisfy those two groups of people, here is how it's done. It is really an extremely straightforward use of CCK, Panels, and Views. You will need CCK, Panels, Views, and the Views Bonus Pack installed. Drupal 4.7.x is assumed.

Step 1: Set up a CCK type

- At admin >> content >> content types, create a new CCK nodetype called "nodetrack".

- Add an Integer>Textfield field type called "nodeid"

- Add a Text>Textfield field type called "description"

I don't use the CCK Link module here for a reason. You have to go through hoops to extract just the node number from such a field. It is simpler in case like this to work with the node number as text. We will auto-generate our links as we need them.

Now head over to admin >> categories and associated enable a taxonomy vocabulary (or two) to be used with nodes of the type "nodetracker".

You can now create a content of the type "nodetracker" and plug in the drupal.org node id number, title, and a brief description. But we are just getting started. We need a block, and ideally, a full page display.

Head on over to admin >> views, and add a new view. Call it NodeTracker. Under the "Page" fieldset, click on the "Provide Page View" checkbox. Give it a URL alias like nodetracker. For the viewtype, select something along the lines of "Panels: Teasers, 3 Columns". That's the Views Bonus Pack magick. (Thanks merlinofchaos!)

In the "Block" fieldset, click on the checkbox next to "Provide Block". Give it a title, and choose how many node entries you would like to show up in your block view.

Leave the Fields and Arguments fieldsets alone.

Under filters, filter based on

  • Node: Type [IS ONE OF] nodetrack
  • Node: Published [EQUALS] Yes

Leave Exposed Filters alone.

In the "Sort Criteria" fieldset, add

  • Node: Created Time - Descending

Save your view.

Here's the Views export, to save you some time:

$view = new stdClass();
$view->name = 'NodeTracker';
$view->description = 'A list of tracked drupal.org nodes';
$view->access = array (
);
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = '';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'panels_threecol';
$view->url = 'nodetracker';
$view->use_pager = TRUE;
$view->nodes_per_page = '10';
$view->block = TRUE;
$view->block_title = 'Node Tracker';
$view->block_header = '';
$view->block_header_format = '1';
$view->block_footer = '';
$view->block_footer_format = '1';
$view->block_empty = '';
$view->block_empty_format = '1';
$view->block_type = 'teaser';
$view->nodes_per_block = '12';
$view->block_more = '1';
$view->block_use_page_header = FALSE;
$view->block_use_page_footer = FALSE;
$view->block_use_page_empty = FALSE;
$view->sort = array (
array (
'tablename' => 'node',
'field' => 'created',
'sortorder' => 'DESC',
'options' => '',
),
);
$view->argument = array (
);
$view->field = array (
);
$view->filter = array (
array (
'tablename' => 'node',
'field' => 'type',
'operator' => 'OR',
'options' => '',
'value' => array (
0 => 'content_nodetrack',
),
),
array (
'tablename' => 'node',
'field' => 'status',
'operator' => '=',
'options' => '',
'value' => '1',
),
);
$view->exposed_filter = array (
);
$view->requires = array(node);
$views[$view->name] = $view;

Still with me? We're almost there.

Everything is set up, except that things are going to look really ugly. Trust me. Try it. Enable your block and take a look.

We need to theme our teasers. Now, this could probably be handled through the Contemplate module, but I'm a sucker for pain.

Create a file in your theme directory called "node-content_nodetrack.tpl.php". The filename is important. The "nodetrack" bit has to match what you named your CCK type, otherwise PHPTemplate won't know to use it for your node display.

Here's what my node-content_nodetrack.tpl.php file looks like.

<div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
<?php if ($picture) {
      print 
$picture;
}
?>


<?php
 
/* for teasers */
 
if ($page == 0) {
      print 
'<div class="nodetracker_teaser">';
      if ( 
strstr($_REQUEST['q'], 'nodetracker') ) {
     
/* nodetracker */
     
print '<div class="' $zebra '">';
      print 
'<small>(#' $field_nodetrack___nodeid[0][view] . ')</small><BR />';
      print 
'<a href="http://www.drupal.org/node/' $field_nodetrack___nodeid[0][view] . '">' $title '</a><BR />';
      print 
$field_nodetrack___description[0][view] . '<BR />';
      if (
$terms)
      print 
'<span class="taxonomy">[' $terms ']</span><BR />';
      print 
'<BR />';
      print 
'</div><!-- zebra -->';
      }
      else {
     
/* default teaser */
     
print '<div class="' $zebra '">';
      print 
'<small>(#' $field_nodetrack___nodeid[0][view] . ')</small>';
      print 
'<a href="http://www.drupal.org/node/' $field_nodetrack___nodeid[0][view] . '">' $title '</a>';
      print 
'</div><!-- zebra -->';
      }

      print 
'</div><!-- nodetracker_teaser -->';
      }
      else { 
?>


<?php if ($submitted) { print '<small>'.$submitted.'</small><br />'; } ?>
<span class="taxonomy"><?php print $terms?></span>

<div class="content">
<?php
     
print $content;
     
?>


<?php if ($links) { ?><div class="links">&raquo; <?php print $links ?></div><!-- links --><?php ?>
</div> <!-- content -->
<?php /* end of else from beginning */ ?>
</div> <!-- node -->

I think that got a tad mangled, but you get the idea. More about node.tpl.php files here

*Phew*

Now you can easily add your tracked nodes to your website, provide a block view, RSS feed, and have a nice three column page view complete with clickable taxonomy categorization.

Ta-da.

Submitted by bohemicus (not verified) on Wed, 2006-09-27 08:53.

Great tutorial, thanks. Of course, to make it complete, you would have to write a little bookmarklet to make it possible to submit to it directly from the Drupal site. The http://drupal.org/project/nodeformpopup module makes it relatively painless.

Submitted by drawk on Wed, 2006-09-27 16:59.

Interesting .. I wasn't aware of nodeformpopup. Something similar can be done with a javascript bookmark and the prepopulate module.

Yeah, I'll have to do a followup for the bookmarklet. The post was getting a little long and I figured I should wrap it up :)

UPDATE: How to create a bookmarklet for your node tracker

Submitted by Joe Moraca (not verified) on Tue, 2006-10-10 00:23.

I had a problem with the theming -- I was expecting the nodetracker block to show the description field as yours does. Just coping and pasting the node-content_nodetrack.tpl.php didn't do that for me.

At first I thought it was a problem with the variable names but after using printr I found it was the if statement causing the top part to "not work" and going to the "else" part..

I had to copy
print $field_nodetrack___description[0][view]

into the

else {
/* default teaser */

part to get it to show up. It worked -- I have to say I don't really understand the logic in the if ... I am still a beginner at some of this stuff.

Anyway thanks for your how-to's I find them the best way to learn. Keep up the good drupal work.

Glad you found my blog webdevgeeks.com I use it as a bookmark site for things I want to work on more.

Submitted by admin on Sat, 2006-10-14 07:09.

One of the things on my to-do list (but flagged low priority out of necessity) is to clean up the code snippet in the post. Glad to see you got it sorted out to do what you were looking for.

I wonder if you're planning to make your nodetracker public. It would be interesting to see what other people are keeping track of.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
More information about formatting options

Hosted By Dreamhost.com


Node Tracker

(#11811)
template.php: Overriding other theme functions
If you want to override a theme function not included in the basic list (block, box, comment, node, page), you need to tell PHPTemplate about it ...
[ | | ]

(#16383)
Making additional variables available to your templates
How to create additional variables in template.php
[ | | ]

(#5120)
Parse xml into sql insert statements
code (using PERL) to parse XML and programatically create nodes from the parsed data
[ | | ]

(#32597)
Need to create nodes from my module (programatically)
Programatically creating nodes, with examples
[ | | ]

(#17570)
Branches | drupal.org
How you maintain the CVS branches for your projects is very important, since that allows you to properly manage changes. It also determines what snapshot releases are available.
[ | ]

(#42562)
Tutorial 3: Creating new widgets with AJAX
How you build your own AJAX widgets will of course depend a lot on what you're wanting to do. But here are some basic steps to get you started.
[ | | ]

(#91709)
Added nodeapi('access') to node.module
This patch adds the operator 'access' to the hook_nodeapi hook. it is invoked after hook_access and allows a module to overwrite the hook_access result.
[ | | | ]

(#84961)
Add a "select all" toggle to forms with many checkboxes (eg: content management -> posts)
Some forms within drupal have dozens of checkboxes, each of which may have to be individually (de)selected. It would be really nice to have a javascript "checkall" toggle to make this easier. The main place I notice it myself, is when I want to delete lots of content from the content management -> posts screen.
[ | | ]

Did you know?

You don't need to register at WWDD to post comments.

Isn't it annoying when you want to comment on an article, but don't want to go through the hassle of creating yet-another-user account at yet-another-website?

Feel free to comment anonymously, or log in with your username@drupal.org account.

We won't mind a bit.