How to create a view for Author content type of those with blogs?

Events happening in the community are now at Drupal community events on www.drupal.org.
pkcho's picture

I have a site with article and blog content types. Each of those content types has a node reference to an Author content type that allows me to associate authors to an article or blog.

I am trying to create a view for the Author content type that will allow me to only display authors with blogs.

I'm not that savvy with arguments and I'm pretty sure that is what is needed to get this to work. I was hoping that someone here could point me in the right direction.

Thank you,
Joe

Comments

Use Relationships for this

wizonesolutions's picture

Actually, I don't think you need arguments at all here. What I would do is add a Relationship based on your Author node reference field on the blogs.

Then simply make the View return distinct results for the author's node reference nid - I think you do this in the table options or it might be its own setting...I'm not looking at it right now, and I forget if it can apply to specific fields...but I hope this gets you going.

In this case, all your fields will be using that Author relationship you created, but you will want to also filter for nodes of type Blog rather than Author. This way you only get back authors who have blogs.

I hope this nudges you in the right direction. Let me know if you have any questions.

WizOne Solutions - https://wizone.solutions - Drupal module development, theme implementation, and more
FillPDF Service - https://fillpdf.io - Hosted solution for FillPDF

I have only one blog entry, but you can try import this.

dmarkcox's picture

$view = new view;
$view->name = 'authors_with_blogs';
$view->description = 'Authors with Blogs';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'type' => array(
'label' => 'Type',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 0,
'machine_name' => 0,
'exclude' => 1,
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'name' => array(
'label' => 'Name',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_user' => 1,
'overwrite_anonymous' => 0,
'anonymous_text' => '',
'exclude' => 0,
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'type' => array(
'order' => 'ASC',
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'name' => array(
'order' => 'ASC',
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
'type' => array(
'operator' => 'in',
'value' => array(
'blog' => 'blog',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('distinct', 1);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'grouping' => 'title_1',
'override' => 1,
'sticky' => 0,
'order' => 'asc',
'columns' => array(
'title' => 'title',
'title_1' => 'title_1',
),
'info' => array(
'title' => array(
'sortable' => 1,
'separator' => '',
),
'title_1' => array(
'sortable' => 1,
'separator' => '',
),
),
'default' => 'title_1',
));
$handler = $view->new_display('page', 'Page', 'page_1');
$handler->override_option('path', 'events');
$handler->override_option('menu', array(
'type' => 'normal',
'title' => 'Family functions',
'description' => 'Family functions description',
'weight' => '0',
'name' => 'primary-links',
));
$handler->override_option('tab_options', array(
'type' => 'none',
'title' => '',
'description' => '',
'weight' => 0,
'name' => 'navigation',
));

Don

Actually I forgot to remove a page, try this one instead.

dmarkcox's picture

$view = new view;
$view->name = 'authors_with_blogs';
$view->description = 'Authors with Blogs';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'type' => array(
'label' => 'Type',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_node' => 0,
'machine_name' => 0,
'exclude' => 1,
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'name' => array(
'label' => 'Name',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_user' => 1,
'overwrite_anonymous' => 0,
'anonymous_text' => '',
'exclude' => 0,
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'type' => array(
'order' => 'ASC',
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
'name' => array(
'order' => 'ASC',
'id' => 'name',
'table' => 'users',
'field' => 'name',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'status' => array(
'operator' => '=',
'value' => '1',
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'status',
'table' => 'node',
'field' => 'status',
'relationship' => 'none',
),
'type' => array(
'operator' => 'in',
'value' => array(
'blog' => 'blog',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'type',
'table' => 'node',
'field' => 'type',
'relationship' => 'none',
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('items_per_page', 0);
$handler->override_option('distinct', 1);
$handler->override_option('style_plugin', 'table');
$handler->override_option('style_options', array(
'grouping' => 'title_1',
'override' => 1,
'sticky' => 0,
'order' => 'asc',
'columns' => array(
'title' => 'title',
'title_1' => 'title_1',
),
'info' => array(
'title' => array(
'sortable' => 1,
'separator' => '',
),
'title_1' => array(
'sortable' => 1,
'separator' => '',
),
),
'default' => 'title_1',
));

Don