I added a node teaser thumbnail using the CCK + ImageField modules.

There was one problem though: the thumbnail was placed directly underneath the title, submit date, and five star results.

I want the thumbnail to be on the left side, with everything else being directly to the right of it.

So I made some CSS changes. It displays okay in Firefox, but it still needs some work.

As for Internet Explorer, all I can say is uber-fail.


Can someone please help me out. I've tried many different combinations relying mostly on float, position, and margins. This is the best that I could do and as far as I know, there are no other attributes that can move objects around.

Also, what heck is going on with in IE? Why does it hate my code so much?


ALTERNATIVELY: how can I get the html for the image to be the first thing after node teaser div?

User pictures for comments work this way and it makes theme-ing so much easier. The only change that I had to make was "float: left;" for the image and I was done (and best of all, it worked in FF and IE).


On a side note, how can I get rid of this dash:

(submit date) - (posted by)

The dash and submit date are part of the same span. So "display: none;" would get rid of both of them.


Back to the main problem:

http://img170.imageshack.us/img170/3665/ffviewfn3.jpg
http://img170.imageshack.us/img170/5941/ieviewok3.jpg
http://img170.imageshack.us/img170/9374/htmlviewoc8.jpg

Here is the CSS:

/* 100% Good Code */
.node.teaser {
  padding: 10px;
  margin: 5px 0 10px 0;
  border: 1px solid #000000;
}
.node.teaser h2 a {
  color: #FF9900;
}
.node.teaser h2 a:hover {
  color: #FFCC00;
  text-decoration: none;
}
.node.teaser .submitted a {
  display: none;
}
.node.teaser .fivestar-static-form-item .description {
  display:none;
}

/* Layout Code - The Trouble Maker */
.node.teaser h2 {
  font-size: 14px;
  width: 380px;
  float: right;
}
.node.teaser .submitted {
  width: 380px;
  float: right;
}

.node.teaser .fivestar-static-form-item {
  float: right;
  position: relative;
  bottom: 30px;
}

.node.teaser .content {
  margin: 0;
  padding: 0;
  clear: both;
}
.node.teaser .content img {
  float: left;
  margin: -12px 0px 0px 0px;
}
.node.teaser .content p {
  width: 380px;
  float: right;
}
.node.teaser ul.links {
}



Any help is greatly appreciated.

Comments

dnewkerk’s picture

I've just got to the theming portion of the lesson, but check out the link referenced in my signature. Though it will when complete, it may not yet answer every one of your questions, but it will get you pretty far.

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

chasz’s picture

hi i went to your site

http://www.davidnewkerk.com/book/18

1. how can i make drupal theme fluid?

2. how can i do the same as the OP but using the first/last attached image?

dnewkerk’s picture

1) A Drupal theme is the same in regard to fixed or fluid width as any site. That aspect of a theme is purely HTML and CSS. If your current theme was not designed with fluid width it may take some rewriting - either check a fluid theme to see how it's done or check google for lessons or prewritten layouts.

2) Not sure I understand this question.

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

chasz’s picture

hi at your site i enlarged the fonts and i get the scrollbar for shifting the page horizontally, so thats not fluid is it?

i would like to add this to my front page and menu items, can i do it with themes or plugins?

category1
teaser node1
teaser node2
teaser node3

category2
teaser node1
teaser node2
teaser node3

i am a bit lost as to how to group nodes into categories

dnewkerk’s picture

Correct, my layouts are not fluid. A good example of a fluid (also called liquid) layout is on SitePoint
Here's a useful link to get layout HTML/CSS you can use in your own theme: Perfect multi-column CSS liquid layouts

For your other question, see my other article: Drupal home page creation techniques (still in progress, but has enough info to get you going). Since you're new to Drupal, you probably have not yet learned about CCK and Views module. CCK allows you to add custom fields to your content types (different content types are often a sufficient form of categorization... for more advanced categorization there are various ways, the main way being the Taxonomy module which comes with Drupal core). Views module is how you make custom lists of content, precisely to your settings so that exactly the content you want to list is listed, exactly the fields you want from that content, and many many other options.

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

chasz’s picture

thanks, now i need to learn how to install plugins and themes. The is no upload from the admin CP ?

vm’s picture

Themes and modules get uploaded to your server using FTP, the same way you installed drupal core.

contrib themes = sites/all/themes
contrib modules = sites/all/modules

Doh’s picture

Thank you very much for your response.

I followed pages 18 - 22 of your site. Brilliant! It perfectly lays out all of the objects, and I managed to move the teaser image with a simple "float: left;" :)

There is one small problem though. I need to group all of the objects of a teaser into one div, so that I can give it a border and some padding. Is this possible?

http://img292.imageshack.us/img292/5613/updateyv4.jpg

dnewkerk’s picture

Yes, definitely possible. That's part of the lesson I had not yet arrived at yet (still only up to theming the nodes themselves, not Views theming yet). I'll cover it in detail in the article in the next week or so, but in brief here's a copy/paste based on another post I made plus some expansion on that which might help until then (since your thread says you're using Drupal 6, I'm assuming you are using Views 2... the following applies only to Views 2):

You can have a look at Views' many available templates to see if they suit your needs. Go to your View, click on the Display in the left that you want to theme, then click on the link for "Theme: Information" under Basic Settings. Inside you will see a list of possible templates, starting from the broadest, drilling down to the most specific. For this I think "Style output" is what you're after. Notice that from left to right the template file names you can choose increase the specificity (e.g. the leftmost name would theme all Views... the farthest right one would only affect one specific Display of one specific View and nothing else).

Select the template name you want to use (e.g. depending on the Basic Settings -> Style of your View, to affect the specific Display of the View it might be called something like views-view-unformatted--yourdisplayname--page.tpl.php ... adjust "yourdisplayname"), create a new file in your code editor and save it with that name. Then click the "Style output" link... select the code, copy/paste it into the new file, make a small change to the file (e.g. write test) so you'll be able to see that it is affecting the page, and save. Go back to the Views admin page where you were and press the "Rescan template files" button so that it will see your new template file in your theme directory. All of the template files which Views is currently using on your View are highlighted in Bold (so you should now notice that on the "Style output" row, the template you created should now be shown in bold instead of the default one farthest to the left). Save the View and then go have a look at the output, which should now have your "test" text on it.

This template is one single instance of an field/row in the View... the "foreach" part means its going to repeat the enclosed code as necessary for all the rows it receives for that page of the View. So you can wrap whatever additional code you'd like around the dynamic variable part that Views will be supplying ($rows), and it will be duplicated as needed as well. If you're not displaying a field title you can probably erase the top part up until after the "endif".

Here's a sample of the code you might put into the views-view-unformatted--yourdisplayname--page.tpl.php file:

<?php if (!empty($title)): ?>
  <h3><?php print $title; ?></h3>
<?php endif; ?>

<?php foreach ($rows as $row): ?>

<div class="some-name">
  <?php print $row ?>
</div>

<?php endforeach; ?>

You can get even more "granular" control of every little aspect of every field by using the templates further down on the page (e.g. "Row style output" and below), though using "Style output" for this case is probably all you need, and keeps things simpler.

Hope this helps. Again, stay tuned for a full write up on the process in my article in the near future.

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

talyia’s picture

This is WONDERFUL to know!! I kept overlooking this "Theme: Information" thinking it was just something of not very great importance... was I wrong!

Christine

Doh’s picture

With each view teaser now inside of its own div, I decided to transfer over the remaining content that was in my original node teasers (fivestar ratings and comment count). It is at this point that the CCK + view combo starts to show problems of its own. I managed to add the comment count, but it doesn't link to comments, and it looks like there is no hope for the fivestar ratings. It seems that the only way to add the fivestar ratings to the view teaser is to make them into a field, but that would mean that only the content creater would be able to rate the content. I also don't see any option to only show select articles.

So I gave up on CCK + Views (for my front page teasers) and I decided to try to modify the default node teasers again.

By doing so, I found the source of my original node teaser problems. It is node.tpl.php. In it I found the source of the dash that was bugging me, as well as the source of the html layout.

I separated the code within node.tpl.php into teaser and the actual node itself. Then I made the necessary fixes to the teaser's php and I finished it all up with a CSS layout.

It works absolutely perfect in Firefox and in IE I managed to fix all but one problem. The "Add new comment"/"Login or register to post comments" text flows outside of the teaser div. I don't have anymore time to work on it today, but I will try to tame it tomorrow.

New FF View: http://img514.imageshack.us/img514/4158/newffviewde9.jpg
New IE View: http://img514.imageshack.us/img514/9054/newieviewrg0.jpg

If anyone is interested in using this node teaser layout, here is the code:

CSS Code:

.node.teaser {
  padding: 0px;
  margin: 5px 0px 10px 0px;
  border: 1px solid #000000;
  display: block;
  clear: both;
}

.teaser-container {
  display: block;
  clear: both;
  margin: 10px;
}

.node.teaser img {
  float: left;
  margin: 0px 10px 0px 0px;
}

.node.teaser h2 {
  font-size: 14px;
  width: 295px;
  float: left;
  display: inline;
}
.node.teaser h2 a {
  color: #FF9900;
}
.node.teaser h2 a:hover {
  color: #FFCC00;
  text-decoration: none;
}

.node.teaser .fivestar-static-form-item {
  float: right;
  display: inline;
}
.node.teaser .fivestar-static-form-item .description {
  display:none;
}

.node.teaser .submitted {
  width: 380px;
  float: left;
}

.node.teaser .field_teaser_text {
  width: 380px;
  float: left;
}

.node.teaser ul.links {
}

node.tpl.php (put this file in your theme directory)

<?php phptemplate_comment_wrapper(NULL, $node->type); ?>

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?><?php if ($page == 0) { print ' teaser'; } ?>">


<?php if ($page == 0): ?>

<div class="teaser-container">

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

  <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
  
<?php print $node->content['fivestar_widget']['#value'] ?>

    <?php if ($submitted): ?>
    <span class="submitted"><?php print t('!date', array('!date' => format_date($node->created))); ?></span>
  <?php endif; ?>

<div class="field_teaser_text"><?php print $node->field_teaser_text[0]['view'] ?></div>

  <div class="clear-block clear">
    <div class="meta">
    <?php if ($taxonomy): ?>
      <div class="terms"><?php print $terms ?></div>
    <?php endif;?>
    </div>

    <?php if ($links): ?>
      <div class="links"><?php print $links; ?></div>
    <?php endif; ?>
  </div>
  
  <div style="clear:both;"></div>

  </div>
  
<?php endif; ?>


<?php if ($page == 1): ?>

<?php print $picture ?>

  <?php if ($submitted): ?>
    <span class="submitted"><?php print t('!date — !username', array('!username' => theme('username', $node), '!date' => format_date($node->created))); ?></span>
  <?php endif; ?>

  <div class="content">
    <?php print $content ?>
  </div>

  <div class="clear-block clear">
    <div class="meta">
    <?php if ($taxonomy): ?>
      <div class="terms"><?php print $terms ?></div>
    <?php endif;?>
    </div>

    <?php if ($links): ?>
      <div class="links"><?php print $links; ?></div>
    <?php endif; ?>
  </div>
<?php endif; ?>

</div>

NOTE -> For this code to work for you:

Using CCK, you will need to make an image field for your teaser image, and a text field for your teaser text.

In the file node.tpl.php,
replace <?php print $node->field_image[0]['view'] ?> with <?php print $node->your-image-field-name[0]['view'] ?>

And once again in the file "node.tpl.php",
replace <?php print $node->field_teaser_text[0]['view'] ?> with <?php print $node->your-teaser-text-field-name[0]['view'] ?>

chasz’s picture

these image fields are links to images right??

what about using the image attachment?

Doh’s picture

Image Fields are an expansion of the CCK module. It allows you to create an image upload "field" for your content creation form.

CCK Module: http://drupal.org/project/cck

Image Field: http://drupal.org/project/imagefield


My mini explanation guide:

Pic 1: http://i469.photobucket.com/albums/rr56/something0001/picture1.png?t=121...

Pic 2: http://i469.photobucket.com/albums/rr56/something0001/picture2.png?t=121...

Pic 3: http://i469.photobucket.com/albums/rr56/something0001/picture3.png?t=121...

chasz’s picture

can i use the same field for upload and/or image url's??

i seen on some forums that they used the same input field.

BTW, if u use the CCK does the field generate a full node eg image, file etc?? or does it become a "child node"?

does it inherit the taxonomy of the content type?

-Anti-’s picture

> -- David
> http://www.davidnewkerk.com/book/18

Just wanted to thank you for this. Obviously a lot of time and effort goes into your tutorials. After spending my entire summer (eight weeks) trying to develop a school website and literally not getting anywhere with it, I'm at an all time low with drupal and ready to pack it in and go back to using e107. However, with your tutorial bolstering the slight hope of being able to display a half-decent teaser/summary in drupal, I might give drupal one last attempt.

But I swear, if I'm not at the stage of adding content in another two weeks or so, I'm leaving! lol.

Anyway. Your tutorial is much appreciated.

talyia’s picture

You sound like the way I felt (and sounded) just a couple of weeks ago. I was also very specific about how exactly I wanted my teasers (and actual nodes) to look and I am getting to the point of exactly where I want to be. Go to http://74.220.215.68/~leemagaz/articles and see where I am at. (Please note that the site is under heavy construction so most of the posts are just "dummy content:) The last few teasers at the top above are how I want them to look more or less... all I have to decide on now is what I want the size of the thumbnail to be and adjust accordingly in Imagecache:) Even clicking on the thumbnail does what I want... opens up in Lightbox (thanks a lot to David for his help too! See this post:)
I even pulled a snippet of code from this thread and used/adjusted it in one of my node.tpl.php files, so THANKS:)

(Of course, now I am battling with setting up a gallery grrrrrrr!)

Good luck!

Best regards,
Christine

Doh’s picture

I have fixed the code for IE. It now displays perfectly on both browsers.


UPDATED CSS Code: (put it in your style.css file)

.node.teaser {
  padding: 0px;
  margin: 5px 0px 10px 0px;
  border: 1px solid #000000;
}
.teaser-container {
  margin: 10px;
}
.node.teaser img {
  float: left;
  margin: 0px 10px 0px 0px;
}
.node.teaser h2 {
  font-size: 14px;
  width: 295px;
  float: left;
  display: inline;
}
.node.teaser h2 a {
  color: #FF9900;
}
.node.teaser h2 a:hover {
  color: #FFCC00;
  text-decoration: none;
}
.node.teaser .fivestar-static-form-item {
  float: right;
  display: inline;
}
.node.teaser .fivestar-static-form-item .description {
  display: none;
}
.node.teaser .submitted {
  width: 380px;
  float: left;
}
.node.teaser .field_teaser_text {
  width: 380px;
  float: left;
}
.node.teaser .clear {
  width: 380px;
  float: right;
}
.node.teaser ul.links.inline {
  display: inline;
}
.node.teaser ul.links {
  maring: 0;
  padding: 0;
}
.node.teaser ul.links.li {
  maring: 0;
  padding: 0;
}



UPDATED "node.tpl.php" Code:

<?php phptemplate_comment_wrapper(NULL, $node->type); ?>

<div id="node-<?php print $node->nid; ?>" class="node<?php if ($sticky) { print ' sticky'; } ?><?php if (!$status) { print ' node-unpublished'; } ?><?php if ($page == 0) { print ' teaser'; } ?>">


<?php if ($page == 0): ?>

<div class="teaser-container">

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

  <h2><a href="<?php print $node_url ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
  
<?php print $node->content['fivestar_widget']['#value'] ?>

    <?php if ($submitted): ?>
    <span class="submitted"><?php print t('!date', array('!date' => format_date($node->created))); ?></span>
  <?php endif; ?>

<div class="field_teaser_text"><?php print $node->field_teaser_text[0]['view'] ?></div>

  <div class="clear-block clear">
    <div class="meta">
    <?php if ($taxonomy): ?>
      <div class="terms"><?php print $terms ?></div>
    <?php endif;?>
    </div>

    <?php if ($links): ?>
      <div class="links"><?php print $links; ?></div>
    <?php endif; ?>
  </div>
  
  <div style="clear:both;"></div>
  </div>
  
<?php endif; ?>


<?php if ($page == 1): ?>

<?php print $picture ?>

  <?php if ($submitted): ?>
    <span class="submitted"><?php print t('!date — !username', array('!username' => theme('username', $node), '!date' => format_date($node->created))); ?></span>
  <?php endif; ?>

  <div class="content">
    <?php print $content ?>
  </div>

  <div class="clear-block clear">
    <div class="meta">
    <?php if ($taxonomy): ?>
      <div class="terms"><?php print $terms ?></div>
    <?php endif;?>
    </div>

    <?php if ($links): ?>
      <div class="links"><?php print $links; ?></div>
    <?php endif; ?>
  </div>
<?php endif; ?>

</div>



Enjoy!

chasz’s picture

congrats can i have a look at the site ?? Views has me confused LOL

azabug’s picture

I get

Fatal error: Call to undefined function phptemplate_comment_wrapper() in /home/user/domain.com/themes/activetheme/node.tpl.php on line 19

is this solution applicable to all versions of drupal?

hopefull

dnewkerk’s picture

No... the original poster is using Drupal 6. Theming between Drupal 5 and 6 is not guaranteed to work (some things of course, but not everything). Especially Views theming, which is pretty much 100% redone in Drupal 6/Views 2. CCK 2 may also present some changes.

Supposing you do have Drupal 6, CCK 2, (and Views 2, though I think he said he's not using Views now), then I'm not sure what's causing your issue. Though make sure you have the same fields as the the code he's provided asks for, or update the code to match your fields.

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

chasz’s picture

Not getting the correct info from contemp ??

"$node->teaser
    <p>A man is found guilty of converting replica submachine guns into live weapons linked to more than 50 shootings.</p> <div class="fivestar-static-form-item"><div class="form-item"> <label>Average: </label> <div class="fivestar-widget-static fivestar-widget-static-5 clear-block"><div class="star star-1 star-odd star-first"><span class="off">0</span></div><div class="star star-2 star-even"><span class="off"></span></div><div class="star star-3 star-odd"><span class="off"></span></div><div class="star star-4 star-even"><span class="off"></span></div><div class="star star-5 star-odd star-last"><span class="off"></span></div></div> <div class="description"><div class="fivestar-summary fivestar-summary-"></div></div> </div> </div> "

when i put it in custom template, i only get the star......anyone know why?? this is just D6 defaults, no CCK fields

dnewkerk’s picture

From the mention of $node->teaser .. looks like you're outputting a standard Drupal teaser... the number of characters you've got there is about 735. My guess is you're reaching the limit of the teaser length, which is why it cuts off. See: http://drupal.org/node/300841#comment-982817 and let me know if that helps.

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

chasz’s picture

actually it should display the teaser first then the stars?? but it seem its the body from the feedAPI

Can you tell me the conditional for the front page? what "if" statement do i need to filter the frontpage??

Also what variable is the item order id?? ie. how does Drupal know it the first or last item...is it the UID ?

dnewkerk’s picture

No if I understand correctly where that code you pasted is coming from (copied out of Contemplate), then that is telling you $node->teaser "is" what is shown below it (e.g. "<p>A man is found..." etc). I'm not sure though. I never use Drupal's standard teasers.

For front page...

<?php if ($is_front) : ?>
This only shows up if you're on the front page
<?php endif; ?>

As for your last question, I don't understand what you're asking.

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

chasz’s picture

LOL well when drupal displays a list does it assign an order number?? like the top item is 1 the next is 2 etc

chasz’s picture

hi i would like alternating div's highlighting....how can i detect the ordering so i can apply the alternating color highlight

dnewkerk’s picture

I've never tried it myself, but Drupal provides a $zebra functionality which does that. Search and you should be able to find how to apply it.

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

chasz’s picture

<?php if ($is_front) : ?>

hi is there another way to do this?? this is very slow

dnewkerk’s picture

Do you mean it performs slow? As in makes your site slower? Or do you mean it's slow to apply it around a lot of bits of code?

I'm not sure what you're doing with $is_front ... if you describe or paste what you're doing I will have a clearer idea.

-- David
absolutecross.com
[new guide/lesson in progress: Creating a CCK and Views powered Drupal site - feedback welcome]

chasz’s picture

is there a way to custom a whole page instead of the content_type ??

ie custom the page.tpl.php instead of the individual node.tpl.php

coz every node has to do a check on if it at the front

chasz’s picture

and last thing , how can i filter for the node itself??

if its at the node then is can show ALL, but any other view, then it just the teaser??

cheers thanks for all the help