Hi, in a site of mine I need to show the scrolling text block only for one content type (news/story). There is a way to get this result?

thanks

CommentFileSizeAuthor
#10 index1.txt10.49 KBsudan

Comments

TheCrow’s picture

The most simple way is to add this code in the _last_node_contents function:
In the example the node type is story:

function _last_node_contents($which_block = '0') {

  if ($which_block == '3') {
    $node = 'story';
    $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE n.type in '%s' AND n.status = 1 ORDER BY n.created DESC"), $node, 0, 10);
    while ($node = db_fetch_object($result)) {
      $output .= l($node->title,'node/'. $node->nid) ."<br />-<br />";
    }
    
    $output = '<marquee id="last_node-block" direction="up" scrollamount="1" scrolldelay="1" onMouseOver="this.stop()" onMouseOut="this.start()">'. $output .'</marquee>';
    drupal_add_css(drupal_get_path("module","last_node") ."/last_node.css");
    return $output;
  }

  ...
fabrizioprocopio’s picture

EN:
Thanks a lot,
the problem is that I don't know php.
Can you explain particularly where put the code you posted?

-------------------------------------------
IT:
Ti ringrazio, il problema è che io non conosco il php,
potresti spiegarmi un po' più banalmente dove copiare e incollare il codice che hai postato?

ti ringrazio molto
fabrizio

TheCrow’s picture

nel file last_node.module, dovresti trovare quella funzione descritta, se ti può servire una guida di base alla creazione di moduli dove specifico la parte relativa ai blocchi. :))

fabrizioprocopio’s picture

Grazie davvero!

fabrizio :-)

amalrajsj’s picture

Dear Crow,
I happened to see your comments about the marquee function. Could you be kind enough to tell me about how to use the function in my home page alone? I do not want the node to be displayed. Just some text, which is often changed, should be displayed in the home page. I am using drupal 6.9 version for my site. If there are some modules to perform this function please let me know. I want a simple marquee function with a facility to upload the text context. I would be grateful to your contribution.

Thanking you in advance,
AAR

TheCrow’s picture

this block is the basic for display the last 10 titles belonging to story type without need any other module:


    $node = 'story';
    
    $result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title FROM {node} n WHERE n.type in '%s' AND n.status = 1 ORDER BY n.created DESC"), $node, 0, 10);

    while ($node = db_fetch_object($result)) {
      $output .= l($node->title,'node/'. $node->nid) ."<br />-<br />";
    }
   
    $output = '<marquee direction="up" scrollamount="1" scrolldelay="1" onMouseOver="this.stop()" onMouseOut="this.start()">'. $output .'</marquee>';
    
    print $output;

i leaved the code for add the css and format the text for keep it clear... using front page module you can paste and adjust it for have your personal home page... otherwise you can paste it inside a block and show it in the region you want (depend from the theme). Just remember to enable the PHP filter.

If you need more simply snippets watch too here.

For more complex and generic use Views module represent the big approach for make any kind of SQL query at your database... it's not so easy to use if you start just now with Drupal but is very powerfull and much documented... could be the answer to your question!

WiFier’s picture

Thank you, sounds good..
but I couldn't make it work on my drupal it returns the same code in the blok.

Could any one please help making it work?

TheCrow’s picture

what code you referrer? #6 or #1?

The #1 is just a part for expand last_node module but it's not complete... need integrate with the tutorial hint for show the new block into the 'admin block' page...

#6 is a stand alone code... doesn't need any other module, just past it into a block u create from zero and modify it for your needs... don't forget to do a preview before save it...

Appelflapje33’s picture

When I paste the PHP code (from post #6) in a block i get the following error:

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''nieuws' AND n.status = 1 ORDER BY n.created DESC LIMIT 0, 10' at line 1 query: SELECT n.nid, n.title FROM node n WHERE n.type in 'nieuws' AND n.status = 1 ORDER BY n.created DESC LIMIT 0, 10 in ***/includes/common.inc(1685) : eval()'d code on line 4.

HELP?

sudan’s picture

StatusFileSize
new10.49 KB

actually i want to add news headlines in my website. i need it to be scrolling in my page.i know hoe to make it scroll but i want to know how to add automatically updated news in side the bar which contains the scrolling text...
this is an example. i'm attaching a page to this mail.. in this u can see a dark red color bar with news running in it. it was just copied from a site.. i need it the similar way but the thing is that the news headlines should be automatically updated every day and also time to time... please help me out ...the file attached is a text file . just save it as a html file and open it..