Drupal

How to print fields on a NODE TPL (node-video.tpl.php, for example)

Drupal 6

Some examples:

<?php print $title; ?>

<a href="<?php print $node_url ?>"><?php print $title; ?></a>

<?php if (!empty($field_news_image)) {
  print $field_news_image['0']['view'];
} ?>

<\div class="submitted">
    <?php print format_date($node->created, 'custom', 'j F Y'); ?>
</div>

<\div class="field venue">
    <?php print l(($node->field_venue[0]['value']), $node->field_venue_url[0]['value']); ?>
</div>

<\div class="field btn-tickets ticket-link">
  <?php 
    if($node->field_sold_out[0]['Yes']){
      print t('Sold out'); } 
    else {
      print l(t('Tickets'), $node->field_ticket_sales_url[0]['value'], array('class' => 'buy-tickets')); }  
  ?>
</div><?php print $title; ?>

<a href="<?php print $node_url ?>"><?php print $title; ?></a>

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Print the complete CCK Link field:

<?php print $node->field_listing_website[0]['view'] ?>

Or separate the URL from the title:

<?php 
    $link_url = $node->field_link[0]['url'];
    $link_title = $node->field_link[0]['title'];
?>

<div<?php print $node_attributes; ?>>
  <?php if (!empty($link_url)) : ?>
    <a href="<?php print ($link_url); ?>">
  <?php endif; ?>



<\h2 class="node-title"><?php print $title; ?><\/h2> <?php print $content; ?>
<?php if (!empty($link_url)) : ?> </a> <?php endif; ?> </div>

This is also explained pretty well here: http://www.caucusllc.com/blog/theming-a-cck-node

Tags:

How to print fields on a views tpl

Drupal core fields:

<?php print $fields['title']->content; ?>
<?php print $fields['body']->content; ?>
<?php print $fields['nid']->content; ?>

Print the teaser:

<?php print $fields['teaser']->content; ?>

CCK fields:

<?php if ($fields['field_location_value']): ?>
<?php print $fields['field_image_fid']->content; ?>

If a field is optional, you might want to say "if field is not empty", like this:

<?php if (!empty($fields['field_image_fid']->content)) {
  print $fields['field_image_fid']->content; }
?>

Especially if you want to add a div or h2 around the print, like this:

  <?php if ($fields['field_location_value']): ?>
    <div class="sample"><?php print $fields['field_location_value']->content; ?></div>
  <?php endif; ?>
  <?php if ($fields['field_venue_value']): ?>
    <<div class="sample">><?php print $fields['field_venue_value']->content; ?></div>
  <?php endif; ?>

Finally, here's a great tutorial on views row theming from the good folks at Mustardseed Media [source]

Tags:

How to setup Drupal Multi-site: Run multiple sites from the same code base

This tutorial is meant to get you up and running with a Drupal multi-site installation quickly and painlessly. I remember trying to figure this out for many weeks. Turns out it's not difficult. It's just difficult to explain.

Here's how it's done from start to finish in the simplest of explanations:

Let's start with Hosting: I highly recommend Bluehost.com.

Bluehost costs $6.95/mo (charged on an annual basis), which is totally reasonable and they have this "Simple Script", one-click-Drupal-install that also has one-click-Drupal-core-updates. Sweet.

If you like this tutorial, kindly follow my Bluehost affiliate link to sign up for their service as a "thanks, Tim!". I get $65 without any negative impact to you.
Full disclosure: I'm an affiliate with lots of hosting companies. Bluehost is my favorite.

Now that you have hosting, let's install Drupal using Bluehost's 1-click Drupal install.

Go to your Bluehost cPanel. Scroll down and click on "Simple Scripts". On the next screen click on Drupal. Bam! Done. Drupal installed.

Next up: Multi-site

From the Bluehost cPanel, click on the "Domain Manager" tab. For the next part we have an question and answer:

Is your domain registered at Bluehost?

From your Bluehost cPanel, click on the "Domain Manager" tab.
Click on the "Assign" link next to the domain you'd like to assign.
On the following screen, make sure to select "Parked domain"

Is your domain registered somewhere besides Bluehost?

Let's say your domain is hosted at GoDaddy. All you need to do is log in to godaddy.com, click on the "My Account" tab, click on "Domain Manager" (in the left sidebar), a new window opens, click on the checkbox next to the name of the domain you'd like to use, then hover over the nameservers icon and click on "Set nameservers".

Then change the nameservers to ns1.bluehost.com and ns2.bluehost.com like this:

Now let's install a database for the second website (the Bluehost "Simple Script" already installed a DB for the first site)

Revisit your Bluehost cPanel and select "MySQL® Databases":

On the subsequent screen enter a unique name for your database (use the name of your second domain, most likely) and click "Create database":

Once you've done that, go back to the page where you created the new database, scroll a bit further down that page, and add a new user for that database (I'd probably name it something similar to the domain name here as well):

Finally, add that user to the database.

Give that user full privileges:

Now for the fun stuff! ;)

  1. Create a new subdirectory of the 'sites' directory with the name of your new site (see below for information on how to name the subdirectory).
  2. Copy the file sites/default/default.settings.php into the subdirectory you created in the previous step. Rename the new file to settings.php.
  3. Adjust the permissions of the new site directory, and grant write permissions on the configuration file
  4. Make symbolic links if you are using a subdirectory such as example.com/subdir and not a subdomain such as subd.example.com (see the subdirectory multi-site section below for details).
  5. In a Web browser, navigate to the URL of the new site and continue with the standard Drupal installation procedure.
Tags:

Drupal Tutorial: How to change text-links to image links in the Views pager

How to add jQuery/JavaScript to a Drupal View

First: Add JavaScript to the Views' block header



<script>
$('document').ready(function(){
$('ul.pager li a').html(' &nbsp; &nbsp;');
$('ul.pager li.pager-current').html(' &nbsp; &nbsp;');
});
</script>


Second: Add the CSS below to your CSS file


ul.pager li {
	padding: 0;
}

ul.pager li.pager-current {
	background: url('../images/sprite.png') no-repeat scroll -160px -137px;
	padding: 0;
}

ul.pager li a {
	background: url('../images/sprite.png') no-repeat scroll -148px -137px;
	padding: 0;
}

ul.pager li a:hover {
	background: url('../images/sprite.png') no-repeat scroll -160px -137px;
	padding: 0;
}