Sunday 28 October 2012

Change display based on vocabulary using views, Drupal 7

Let's say we have two vocabularies called A and B.
Now I would like to display nodes with terms from vocabulary A as teasers and for vocabulary B I would like to change display to table.

This is how it can be done.

Clone Taxonomy Term view and give it a new name.
Change format to table and add your fields.

Configure contextual filter: Content: Has taxonomy term ID (with depth)
In section called:
When the filter value IS in the URL or a default is provided
Specify validation criteria
Validator: PHP code, and paste below

$tid = $argument;
$vid = db_query("SELECT vid FROM {taxonomy_term_data} WHERE tid = :tid", array(':tid' => $tid))->fetchField();

// replace with your own $vid (vocabulary id) values
if ($vid == 1) { 

$view->display_handler->set_option('style_plugin', 'default');
$view->display_handler->set_option('row_plugin', 'node');

}
return TRUE;



Your view now for vocabulary with id 1 (vocabulary A) will display data as node teasers and for rest it will be table.

It can be done the other way around, but it slightly more tricky as you need to add fields for table format and then change it back to content format.

$tid = $argument;
$vid = db_query("SELECT vid FROM {taxonomy_term_data} WHERE tid = :tid", array(':tid' => $tid))->fetchField();
// replace with your own $vid (vocabulary id) values
if ($vid == 2) { 

$view->display_handler->set_option('style_plugin', 'table');

//export view to get style plugin names and other info
  $view->display_handler->set_option('style_options', array(
  'grouping' => '',
  'override' => 1,
  'sticky' => 0,
  'order' => 'desc',
  'columns' => array(
    'field_group_picture' => 'field_group_picture',
    'title' => 'title',
    'field_informations' => 'title',
  ),
  'info' => array(
    'field_group_picture' => array(
      'separator' => '',
    ),
    'title' => array(
      'sortable' => 0,
      'separator' => '<br />',
    ),
    'field_informations' => array(
      'sortable' => 0,
      'separator' => '<br />',
    ),
  ),
  'default' => '-1',
)
);
}
return TRUE;

Tuesday 19 October 2010

Move user picture to a seperate tab in user profile tab menus

Normally if you go to user/%/edit there are all the user settings put together, which might be little confusing. I decided to move User Picture fieldset to a new tab, just to make it easier for users to upload their avatars.

To accomplish this you need to create a helper module, let's call it custom_module.
Now inside custom_module directory create two files custom_module.info and custom_module.module



Sunday 17 October 2010

Drupal views title block with clickable "more" link

Ok, so you have a block created in views with i.e. last 10 comments and you want to add link to the page with the rest of the comments. You can add standard "more" link in views which will be included under the block, but you saw on Facebook nice "more" link included in the block title.
----------------------------------
Title                more>
----------------------------------
Here I will show you how you can do it.

We will create a small module called 'Block "more" link', which will add new display to views.

Friday 15 October 2010

How to display a Node Gallery in a grid?

If you use Node Gallery module, you probably wonder how to display images  in a grid? It's very simple and you can do this with CSS below:

.gallery-images-list {
  overflow: hidden; /* clear floats */
}

.gallery-images-list li {
  float: left;
  width: 24%; /* you can adjust this to your theme */
  min-height: 190px; /* if you use long titles which will be displayed under pictures some pictures may 'stuck' and not go to left, try lower value and you will see what I mean */
}

.gallery-images-list .image-thumbnail a {
  display: block;
  text-align: center;
}

.gallery-images-list .image-thumbnail img {
  margin: 5px;
}


Simply paste that code at the bottom of your style.css file.

Interesting article about CSS, images and grids click

Wednesday 13 October 2010

Disable OPML link/icon [Organic Groups]

There is a couple of ways removing this annoying OPML link and icon seen on the My Groups tab.

1. Use CSS, add in your style sheet:

.opml-icon {
  display:none;
}

2. Edit view and under 'Basic Setting' for Header or Footer insert:
<p></p> or <span></span> or any other html tags

3. Override theme_opml_icon() function in theme's template.php file:

function YOURTHEME_opml_icon($url) {
  return '';
}


All of these will work, but definitely number 3 is recommended solution, simple & that's how it should be done in Drupal.