How can i add css class into theme('item_list',$items) ?

i want to generate a list like:

if(count($items)) {
print theme('item_list',$items);
}

but i want to use a css class for listing.

Comments

nevets’s picture

Do you want to add a class name to the whole list or individual menu items?

skullJ’s picture

to whole list!!!!

i think the theme('item_list',$items) generate a normal < ul >< li >1st item< /li >< /ul > without any ul class,right?

I tried to take a div like:

if(count($items)) {
print '

' . theme('item_list',$items) . '

';
}

and its work!But can i add a class into ul?

nevets’s picture

So in this case something like

$class = "your-class-name-here";
print '' . theme('item_list',$items, NULL, 'ul', array('class' => $class)) . '';

will work.

You can find more information on the function at http://api.drupal.org/api/function/theme_item_list/5

skullJ’s picture

working!!

thank you!!! :D

tanyi’s picture

Does anyone know how I can change the font size of the items in a list when I use the statement

print theme('item_list', $items);

Below is the full code.

  $vid = 4; /* <---- put correct vocabulary ID here */
  $items = array();
  $terms = taxonomy_get_tree($vid);
  foreach ( $terms as $term ) {
    $count = taxonomy_term_count_nodes($term->tid);
          $items[] =  l($term->name,'taxonomy/term/'.$term->tid)."  (".$count.")  ".$term->description;
    
  } /* end foreach */
  print theme('item_list', $items);
    

Thanks in advance!

nevets’s picture

If you use the above suggestion to give the list a class you can then use css to change the font size.

tanyi’s picture

I added two lines to the code and it is working but I do not understand how the second line works .

$class = "valu";
print '' . theme('item_list',$items, NULL, 'strong', array('class' => $class)) . '';

  $vid = 4; /* <---- put correct vocabulary ID here */
  $class = "valu";
  $items = array();
  $terms = taxonomy_get_tree($vid);
  foreach ( $terms as $term ) {
    $count = taxonomy_term_count_nodes($term->tid);
          $items[] =  l($term->name,'taxonomy/term/'.$term->tid)."  (".$count.")  ".$term->description;
    
  } /* end foreach */
  print '' . theme('item_list',$items, NULL, 'strong', array('class' => $class)) . '';
    
nevets’s picture

See http://api.drupal.org/api/function/theme_item_list/5 for information on using the theme function. Where you have 'strong' it really should be 'ul' or ''ol' (other values may produced unexpected results). The last part, array('class' => $class), allows yo to set html attributes for the outer tag, in this case setting the class to the value you have specified.

tanyi’s picture

How do I use CSS to change the font size? Do you mean style.css? Please help out I'm a newbie. Thanks.

nevets’s picture

Correct you can add an appropriate ccs rule in style.css, if you class is 'valu' something like this will work.

.valu {
  font-size: 0.8em;
}

Values less than 1 will decrease the font size, values greater than one will increase the font size.

tanyi’s picture

Thanks. When I have the line below

print '' . theme('item_list',$items, NULL, 'ul', array('class' => $class)) . '';

and add

.valu {
font-size: 0.8em;
}

to the CSS it doesn't seem to work. When I change the font size nothing changes in the display. But, when I replace the 'ul' with 'strong' or 'bold' then I can see changes when I change the font size in the CSS.

tanyi’s picture

In my style.css I have

.valam {
font-weight: bold;
font-size: 10.8em;
font-family: Verdana;
}

and my theme list looks like this

  $vid = 4; /* <---- put correct vocabulary ID here */
  $class = "valam";
  $items = array();
  $terms = taxonomy_get_tree($vid);
  foreach ( $terms as $term ) {
    $count = taxonomy_term_count_nodes($term->tid);
    
      $items[] = l($term->name,'taxonomy/term/'.$term->tid)."   ".$term->description;
   
  } /* end foreach */
  print '' . theme('item_list', $items, NULL, 'ul', array('class' => $class)) . '';

When I make changes to the font size in style.css I don't see any changes. I must be doing something wrong.

nevets’s picture

The firebug extension for Firefox would be useful for figuring this out. It would allow you to inspect the html and see what css is actually be applies. You could check to see the class is being added to the ul tag and also if there is any other css that is overriding your css.

tanyi’s picture

Thanks will take a look at it. There must be something overiding my css.

tanyi’s picture

Is there any way to not display the bullets/numbering when the items are listed?

nevets’s picture

Yes set the css properties list-style-image and/or list-style-type to none.

tanyi’s picture

Where do I change these properties? I see CSS class and CSS id in the panels for each of the category. I entered none in both but it the bullets are still there.

nevets’s picture

Generally you would add the css to a themes style.css file.

ganesh_drupal-1’s picture

hi Dear

May i know what is this theam('item_list') ?

Any idea about this !!!!!!!!!!!!!!!!!!!

Urgent

skullJ’s picture

Are you sure is theam('item_list') ???

Check the right syntactic in api: http://api.drupal.org/api/function/theme/5

__________________
www.skull.gr

bharanikumariyerphp’s picture

can plz tell me each parameter explation for theme....
am
using this theme in pagination...

when i click the list..

the 5 content will display and balance is display in the next page ..

but u see when there is no records..on that time also the pagination is displayed with three page...

this is the code..


<?php

/**
* Implementation of hook_menu().
*/
function content_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array(
'title' => t('Display all contents'),
'path' => 'content',
'callback' => 'content_article',
'access' => user_access('authenticated user')
);

$items[] = array(
'title' => t('page'),
'path' => 'content/page',
'callback' => 'content_page',
'access' => user_access('authenticated user')
);



$items[] = array(
'title' => t('story'),
'path' => 'content/story',
'callback' => 'content_story',
'access' => user_access('authenticated user')
);
$items[] = array(
'title' => t('article'),
'path' => 'content/article',
'callback' => 'content1',
'access' => user_access('authenticated user')
);
$items[] = array(
'title' => t('sample1'),
'path' => 'content/sample1',
'callback' => 'content_sample1',
'access' => user_access('authenticated user')
);
$items[] = array(
'title' => t('sample2'),
'path' => 'content/sample2',
'callback' => 'content_sample2',
'access' => user_access('authenticated user')
);

}
return $items;
}

function content_article(){

 $pageQuery = "SELECT n.created, n.title, n.type, n.created, n.nid, n.uid, n.changed
  FROM node n
  WHERE n.status = 1 order by n.type desc";
 
  $countQuery=" SELECT count( nid )FROM node ";
 //echo $pageQuery,"<br>",$countQuery;
  
   $result=db_query($pageQuery);
   
   $num=db_num_rows($result);
  // echo "<br>".$num;
   
   
   if($num>0){
  // 	echo "<br>If greater";
	
	
	$output .= "<div class=\"item-list\"><table width=600 cellspacing=0 cellpadding=0 border=0><tr><td width=10><input type=checkbox name=checkbox id=checkbox /></td><td width=190><b>Title</b></td><td width=100><b>Type</b></td><td width=60><b>Author</b></td><td width=170><b>Published Date</b></td><td width=50><b>Operations</b></td></tr><ul>";
	  $color="1";
	  
	   $result1 = pager_query($pageQuery,10,"0",$countQuery);
	//   echo "<br>"."This is Result 1".$result1;
	   
	   
	   while ($node = db_fetch_object($result1)) {
			   $user_id=$node->uid;
			   $authername="SELECT name FROM users WHERE uid =$user_id";
			   $affect=db_query($authername);
			 //  echo "<br>This is".$affect;
			   
			   
			   while($row = db_fetch_object($affect))
					  {
						  $author=$row->name;
						 // echo "<br>This is the author &nbsp;".$author;
					  }
			  $created=$node->created;
			  $created_date=date("D, j M, Y \a\\t G:i", $created);
			 // echo "This is create date".$created_date;
			  
			  
			  if($color==1){

 							   $output .= "<tr bgcolor=#edf5fa><td width=10><input type=checkbox name=checkbox id=checkbox /></td><td width=190>" . l($node->title, "node/".$node->nid) ."</td><td width=100>". l($node->type, "node/".$node->nid) ."</td><td width=60>". l($author, "node/".$node->nid) ."</td><td width=200>". l($created_date, "node/".$node->nid) ."</td><td width=50>" . l("Edit", "node/".$node->nid."/edit")."</td></tr>";
//"&nbsp;&nbsp;&nbsp;" .  l("Delete", "node/".$node->nid."/delete")  .

$color="2";
}

			else
			{
							    $output .= "<tr bgcolor=#ffffff><td width=10><input type=checkbox name=checkbox id=checkbox /></td><td width=190>" . l($node->title, "node/".$node->nid) ."</td><td width=100>". l($node->type, "node/".$node->nid) ."</td><td width=60>". l($author, "node/".$node->nid) ."</td><td width=200>". l($created_date, "node/".$node->nid) ."</td><td width=50>" . l("Edit", "node/".$node->nid."/edit")."</td></tr>";
//"&nbsp;&nbsp;&nbsp;" .  l("Delete", "node/".$node->nid."/delete")  .

$color="1";


  }
}
$output .= "</table></ul></div>";
//return $output;		 
return $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
}
 else
{
    return t("<br><b>No record found</b>");
}  
}

Any idea plz share

WilliamB’s picture

I'm trying to add class and style to the ul and li tags issued from the agregator module when displayed in a block.
Apparently the module generate a basic

  • list through that code:
    Line 417 in agregator.module.
     $items[] = theme('aggregator_block_item', array('item' => $item));
    

    How can i add class and style to the ul and li tags?

aryashreep’s picture

So in this case something like

$class = "your-class-name-here";
print '' . theme('item_list',$items, NULL, 'ul', 'attributes' => array('class' => $class)) . '';

Jeff Burnz’s picture