Sunday, January 30, 2011

Can Rephresh Cause Discharge?

Drupal 6: block with the data 'linked node'

In this period I've been really busy for the final stages of my work with the Monsummano Terme , where I managed the whole migration to Drupal as management interface, and not only , the same work simultaneously for three other towns in the Valdinievole ( Larciano , Lamporecchio , Pieve a Nievole ) that previously were handled associate, but now had the need for independent management platforms.

Since the external layout is unchanged, I had to meet a number of requests for presentation of content that is not could manage with the default feature of Drupal. For example, today I'll show you how easy it is to go fishing content "secondary" and put it on a block in any region of the page.

the site of the City, each page is a matter of a certain office, which in turn is represented by a node (a special type of content). The Office of jurisdiction shall be displayed in a special box on the right hand column, complete with all the information in the public interest (links, opening hours, addresses various).

The Office is linked to the page via a CCK field 'node linked' to selection unique: a tent lets you choose any of the nodes such as 'Office' previously published.

The problem to be solved is to load data from a node that is not loaded on the page, but a node connected to it, also working in a block we do not have the variable $ node with all the data node of the page .

We then load the first node, and then accessing the field 'linked node', node connected load and extract the data we need. To this end we use the function node_load () , which needs a NID to function.

To find the ID of the root node, we exploit the function arg () , which returns a portion of the current path, for example, a page node with a path type www.mysite.com / node / nid arg (0) returns "node", arg (1) Back "nid" and so on.

All the code that we will examine from now on will end up in a nice new block to put anywhere we like.
 \u0026lt;? 
php if (arg (0) == 'node' & & is_numeric (arg (1))) {$ node =
node_load (arg (1));
$ node_collegato node_load = ($ node-> field_ufficiocompetenza [0] ["nid"]);
/ / code to extract data from the node of interest connected

}?>
The requirement serves to ensure that you have to do with a page / node (of course also works if the path is in the form of aliases). The first use of
node_load loads the root node, the second access to the CCK field that contains the node's Office NID collegato.Il rest is easy: just print the data that interest us with the necessary markup to format everything. So my block "office of jurisdiction" is finished and ready for use:
 \u0026lt;? 
php global $ base_path;

if (arg (0) == 'node' & & is_numeric (arg (1 ))) {$ node =

node_load (arg (1));
$ node_collegato node_load = ($ node-> field_ufficiocompetenza [0] ["nid"]);
if ($ node-> field_ufficiocompetenza [0] ["nid"]> 0) {
print "\u0026lt;div class = \\ "itemdx \\"> ";
print" \u0026lt;h2> \u0026lt;a href=\\"".$base_path.$node_collegato-> path. "\\" title = \\ "page". node_collegato $ -> title. "" \\ ">".$ node_collegato-> title. "\u0026lt;/ a> \u0026lt;/ h2>";
print "\u0026lt;ul>"
print "\u0026lt;li> \u0026lt; b> Area: \u0026lt;/ b> ". $ node_collegato-> field_settore [0] [" value "]."\u0026lt;/ li> ";
print "\u0026lt;li> \u0026lt;b> Hours: \u0026lt;/ b>". $ Node_collegato-> field_apertura [0] ["value "]."\u0026lt;/ li>";
print "\u0026lt;li> \u0026lt;b> Head office: \u0026lt;/ b> ". $ node_collegato-> field_responsabile [0] [" value "]."\u0026lt;/ li> ";
print" \u0026lt;li> \u0026lt;b> Phone: \u0026lt;/ b> ". $ node_collegato-> field_telefono [0] [" value "]."\u0026lt;/ li> ";
print" \u0026lt;li> \u0026lt;b> Fax: \u0026lt;/ B> ". $ Node_collegato-> field_fax [0] [" value "]."\u0026lt;/ li> ";
print" \u0026lt;/ ul> ";
print" \u0026lt;/ div> ";
}}


?>
The condition of line 8 is to make sure that there is indeed an Office related, otherwise the block remains empty.

With the same method then you can indulge to divide content into different regions through other blocks.

0 comments:

Post a Comment