How can I change position of particular fields or category terms inside nodes? I need for instance one field alongside other field.

Positions of all fields are by default like this:

Field1
Field2
Field3

What exactly should I do if I need positioning like this?

Field1 Field2 Field3

Thanks for answer!

Comments

matt_harrold’s picture

You can either make a custom template for your content types using a Theme ... see your node.tpl.php file in your theme folder, or you can use the contributed module Contemplate.

Both methods have identical end results, complete control over how your node content is displayed.

santoro’s picture

Thanks, but how can I determine particular fields?

matt_harrold’s picture

If you have a look at the Contemplate module, you'll see a section called "Teaser Variables" or "Body Variables". This is a list of all the fields that you have in that content-type. If you click on the link, it auto inserts the exact PHP code into the Teaser (or Body) template editor.

An example ... imagine a content type with one CCK field ... a date field called field_date ... an "Event".
This template prints the date with links to a site calendar, and the node body.

  print '<div class="field-item"><div class="field-label-inline-first">';
      print 'Date: ';
      print '</div><span class="date-display-single">';
      $date = strtotime($node->field_date[0]['value']);
      print l(date('l dS',$date),'calendar/'.date('Y/m/d',$date)).' '.l(date('F',$date),'calendar/'.date('Y/m',$date)).' '.l(date('Y',$date),'calendar/'.date('Y',$date));
      print '</span></div>';
      print '<div class="node-body">'.print $node->content['body']['#value'].'</div>';
santoro’s picture

Thanks. Is there some guide to this for people who doesn't undestand PHP? :) I know there are different fields and properties, but I don't know what properties I should add and where I shoud add them...
I only find out that this line can display the content of the field:
<?php print $node->field_name[0]['view'] ?>
How can I display the label of the field? The next choice here is only "['value']" (which do the same thing?), nothing more.

matt_harrold’s picture

The easiest way to find out the names of the fields is to do something like this:

  print "<pre>";
  print_r($node);
  print "</pre>";

This will dump the entire contents of the $node variable including names to the screen. You can have a look at the output to locate the variables you want to display. This is how I usually check things during development.

santoro’s picture

Ok, thanks. Now I only need to figure out how to display the field "Name" alongside the field "Year" (see code below).
Just like this:
Name Year

This is what i have in Contemplates. I don't know if this is ok - in Contemplates there is written: "Fields marked with ** (which is the field "value" I used) are insecure and need to be wrapped with either check_plain() or check_markup()" (but I don't understad PHP).

Teaser Template:

<?php print $field_teaser[0]['view']?>

Body Template:

<div class="teaser" style="border-color:blue;color:red">
<?php print $field_teaser[0]['view']?>
</div>
<div class="content">
<?php print $node->content['body']['#value']?>
</div>
<?php print $node->content['field_name']['#value'] ?>
<?php print $node->content['field_year']['#value'] ?>
hollybeary’s picture

couldn't you just put each of your fields, name and year, in their own div's? That way in your style sheet you could use floats to position them beside each other. Or you could also just add a simple table into your body template around the name and year fields to get them to show up the way you want.

<div id="field-name"><?php print $node->content['field_name']['#value'] ?></div>
<div id="field-year"><?php print $node->content['field_year']['#value'] ?></div>

or

<table><tr><td>
  <?php print $node->content['field_name']['#value'] ?>
</td>
<td>
  <?php print $node->content['field_year']['#value'] ?>
</td></tr></table>

Hope that helps some :)

santoro’s picture

Isn't this maybe unnecessarily complicated? :) I need only little space between these two fields (by "little space" I mean "usual space between two words" - sorry, I don't know how to say it in english). But maybe it can't be done in simplest way, I don't know :)

Flutty’s picture

I wanted to have the label and the content of a field displayed inline, rather than the default which is above. I eventually found that this is achieved inside the Drupal menu

Content Management / Content Type

Select the relevant Content Type and then edit the Display Fields tab. You can select to hide the label, place it above or inline.

To edit the style and the order of the fields go to the website via ftp and find the /sites/default/node-contenttype.tpl.php. You need to edit this using PHP and HTML and also CSS too.