Full time Drupalista. Part-time U.S. Army Sergeant. Latte aficionado. Mother Jones reader and international politics junkie.
Full biography
Creating my own newsticker module
I need to construct a newsticker for Diálogo Digital. We have been re-redesigning our news site for about 8 weeks now (except for the web designer that prepared the plain HTML/CSS files) I am alone. Initially I felt inclined to use a community provided (contrib) module, but here were my options:
http://drupal.org/project/newsticker It is built for Drupal 6, uses JQuery's serialscroll plugin, outputs the newsticker into a block. Does not use Drupal's node system.
http://drupal.org/project/views_ticker Built for Drupal 5 only, so it wasn't really an option. Offers views integration. Could have peeked at the code to see how it made use of the Views API (something I have considered myself but haven't done yet). Just like the newsticker module, outputs contents in blocks.
So far for DD's redesign I have created a custom module called dd2_components that is acting sort of like a "support module" that creates all kinds of things that are I am not creating using a combination of cck + views. Whatever my module fetches from Drupal's databases it is made available to the theme by using the theme hook. I have a dd2_components_theme() { ... } ?> hook in place that calls 8 custom theming functions so far for site components like
- Latest items list or "lo ultimo"
- Advertisement blocks
- The news blocks visible on the re-designed site's front page
- The main slideshow on the front page
All these components get constructed by a single SQL query from the dd2_components module to the database. Yeah, I'm pretty sure that (if you know about this stuff) you must have said "that must be the Uber query string", but no. I am calling a stored procedure (which acting like a main sp in turn calls other stored procedures so the SQL is easier to read and edit). So in reality the SQL looks more like this:
<?php
$query = "CALL sp_frontpage";
?>So anyways, after considering the two slideshows I mentioned, I think I am going with my own solution because:
- The newsticker module outputs it's content into a block.
- Although dd2_components outputs it's contents in blocks, like I say in the attached pseudocode, I don't want to output the contents into a block in this case.
- I think the space where the newsticker will go is too tight for outputting a block without creating a separate block-xxx tpl.php and stripping it of everything except my content.
So I want to output the content using a theming function, which in turn gets called directly by page-front.tpl.php and page.tpl.php.
Attached is the pseudocode of what I considered before I started coding. (I think that I am going to start doing this more frequently for technical recruitment purposes, and so I don't have to store those pesky note pads - which are very sensitive to water, natural disasters, fire, etc).
Notice: When writing pseudocode I write very fast, as the ideas were to escape. Don't expect anything beautiful =)
[inline:pseudocode_newsticker_nov_21_2009_alexander_allen.PNG]







Nice ticker Solution for Drupal
I found this the be a very elegant solution: http://pras.net.np/blogs/create-bbc-style-news-ticker-drupal
not sure if you have seen this already.
Cheers,
Casey
http://twistedpairwd.com
Thanks for the suggestion
That's one of the first ones I saw, and it looks good enough - I also thought about using Views. But I ended implementing my own module after two days of brainstorming and programming. In the end it resulted that making my own module gave my more control - and headaches ;-)