views:

26

answers:

4

Im very new at drupal. My problem is that the block is consistent and not changing. It seems to be based on the user signed in as opposed to the page being visited (ie, in the multi-user blog, each block should reflect the page of the blogger being displayed and not the user who is signed in. I would like the info to be displayed based on the page that is being visited. Thanks!

+1  A: 

There are two popular modules, that was made to do this kind of stuff. What you want is to let your blocks be aware of their context, fx which user posted the blog post etc:

These modules are both very complex, and if you're new to Drupal you might have a hard time getting what you want.

If you have custom coded your blocks, and they are only placed on nodes (blog posts), you can quite easily load the node and get the info on who wrote it. You can do this, by using arg.

If you created the blocks with views, you need to pull the user info from the node, using relationships, instead of pulling the data from the logged in user.

googletorp
A: 

for example,

I cant figure out what im missing in this code to make each users recent blogs show up on their profile pages as opposed the the logged in user seeing theirs on all users pages where the block is activated...

global $user;

$node=node_load(arg(1));

$myuid=$node->uid;

$nlimit = 5; $query= "SELECT n.created, n.title, n.nid, n.created FROM {node} n WHERE n.uid = %d AND n.type = 'blog' AND n.status = 1 ORDER BY n.created DESC"; $result = db_query_range(db_rewrite_sql($query), $user->uid, 0, $nlimit); $result2 = db_query_range(db_rewrite_sql($query), $user->uid, 0, $nlimit); if (db_fetch_object($result2) == False) {

print 'This user has no blog entries';

}

else {

while ($node = db_fetch_object($result)) {

            print '<div class="tfont"><ul><h5><a href="';
            print '../' . drupal_get_path_alias('node/'.$node -> nid);
            print '">' . $node->title . "</a>&nbsp;-&nbsp;";
            print date('F d,y', $node->created) . '</h5></ul></div>'; 

        }

print 'More >'; }

MAds
A: 

This is best done with the views module

For your reference I have included a dump of a quick view that i have created, what it simply does is get the uid from the page being viewed whether it be a node or user profile and grabs any content (i have limited it to blog_posts, you might need to jig it to fit your type) created by the user being viewd.

It creates an automatic block which should be available block administration list.

Hopefully this is a starter. In order to use this, download and enable the views module and import the below code, it will create the view

$view = new view;
$view->name = 'recent_blogs';
$view->description = '';
$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(
  'title' => array(
    'label' => 'Title',
    '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' => 1,
    'exclude' => 0,
    'id' => 'title',
    'table' => 'node',
    'field' => 'title',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('sorts', array(
  'created' => array(
    'order' => 'ASC',
    'granularity' => 'second',
    'id' => 'created',
    'table' => 'node',
    'field' => 'created',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('arguments', array(
  'uid' => array(
    'default_action' => 'default',
    'style_plugin' => 'default_summary',
    'style_options' => array(),
    'wildcard' => 'all',
    'wildcard_substitution' => 'All',
    'title' => '',
    'breadcrumb' => '',
    'default_argument_type' => 'user',
    'default_argument' => '',
    'validate_type' => 'none',
    'validate_fail' => 'not found',
    'break_phrase' => 0,
    'not' => 0,
    'id' => 'uid',
    'table' => 'users',
    'field' => 'uid',
    'validate_user_argument_type' => 'uid',
    'validate_user_roles' => array(
      '2' => 0,
      '3' => 0,
      '7' => 0,
      '4' => 0,
      '8' => 0,
      '9' => 0,
      '5' => 0,
      '6' => 0,
    ),
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
    'default_options_div_prefix' => '',
    'default_argument_fixed' => '',
    'default_argument_user' => 1,
    'default_argument_php' => '',
    'validate_argument_node_type' => array(
      'blog_post' => 0,
      'member_org' => 0,
      'news_item' => 0,
      'project' => 0,
      'event' => 0,
      'promo_item' => 0,
      'discussion' => 0,
      'group' => 0,
      'page' => 0,
      'uprofile' => 0,
      'panel' => 0,
      'book' => 0,
      'story' => 0,
    ),
    'validate_argument_node_access' => 0,
    'validate_argument_nid_type' => 'nid',
    'validate_argument_vocabulary' => array(
      '1' => 0,
      '2' => 0,
      '4' => 0,
      '5' => 0,
      '3' => 0,
      '7' => 0,
      '6' => 0,
    ),
    'validate_argument_type' => 'tid',
    'validate_argument_transform' => 0,
    'validate_user_restrict_roles' => 0,
    'validate_argument_node_flag_name' => '*relationship*',
    'validate_argument_node_flag_test' => 'flaggable',
    'validate_argument_node_flag_id_type' => 'id',
    'validate_argument_user_flag_name' => '*relationship*',
    'validate_argument_user_flag_test' => 'flaggable',
    'validate_argument_user_flag_id_type' => 'id',
    'validate_argument_is_member' => 'OG_VIEWS_DO_NOT_VALIDATE_MEMBERSHIP',
    'validate_argument_group_node_type' => array(
      'group' => 0,
    ),
    'validate_argument_php' => '',
  ),
));
$handler->override_option('filters', array(
  'type' => array(
    'operator' => 'in',
    'value' => array(
      'blog_post' => 'blog_post',
    ),
    'group' => '0',
    'exposed' => FALSE,
    'expose' => array(
      'operator' => FALSE,
      'label' => '',
    ),
    'id' => 'type',
    'table' => 'node',
    'field' => 'type',
    'override' => array(
      'button' => 'Override',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
));
$handler->override_option('cache', array(
  'type' => 'none',
));
$handler->override_option('title', 'Recent blogs');
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
flk
exceptional! works perfectly. All I had to do was add the context as UID, and add a few more fields. Really brilliant.Thanks a MILLION!!!! Originally posted to the wrong answer!!!!
MAds
A: 

Ok moving right along...

Also sorted out context module for my blocks I was able to create a multi-user blogroll that appeared for each user based ont their blogroll on their blog page in the sidebar.

If anyone is interested, first i followed directions here http://drupal.org/node/123850

here is the exported view with my little tweaks to get it to work:

$view = new view; $view->name = 'blogroll_page'; $view->description = 'blogroll_page'; $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', 'default', 'default'); $handler->override_option('relationships', array( 'content_profile_rel' => array( 'label' => 'Content Profile', 'required' => 1, 'type' => 'blogroll_view', 'id' => 'content_profile_rel', 'table' => 'users', 'field' => 'content_profile_rel', 'override' => array( 'button' => 'Override', ), 'relationship' => 'none', ), )); $handler->override_option('fields', array( 'field_url_url' => array( 'label' => '', '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, 'label_type' => 'none', 'format' => 'default', 'multiple' => array( 'group' => 1, 'multiple_number' => '', 'multiple_from' => '', 'multiple_reversed' => 0, ), 'exclude' => 0, 'id' => 'field_url_url', 'table' => 'node_data_field_url', 'field' => 'field_url_url', 'override' => array( 'button' => 'Override', ), 'relationship' => 'none', ), )); $handler->override_option('sorts', array( 'title' => array( 'order' => 'ASC', 'id' => 'title', 'table' => 'node', 'field' => 'title', 'override' => array( 'button' => 'Override', ), 'relationship' => 'none', ), )); $handler->override_option('arguments', array( 'uid' => array( 'default_action' => 'default', 'style_plugin' => 'default_summary', 'style_options' => array(), 'wildcard' => 'all', 'wildcard_substitution' => 'All', 'title' => '', 'breadcrumb' => '', 'default_argument_type' => 'php', 'default_argument' => '', 'validate_type' => 'me', 'validate_fail' => 'ignore', 'break_phrase' => 0, 'not' => 0, 'id' => 'uid', 'table' => 'users', 'field' => 'uid', 'validate_user_argument_type' => 'either', 'validate_user_roles' => array( '2' => 0, '4' => 0, '3' => 0, ), 'me_redirect' => 0, 'me_validate_user_argument_type' => 'either', 'me_validate_user_roles' => array( '2' => 0, '4' => 0, '3' => 0, ), 'override' => array( 'button' => 'Override', ), 'relationship' => 'none', 'default_options_div_prefix' => '', 'default_argument_fixed' => '', 'default_argument_user' => 0, 'default_argument_php' => 'if (arg(0) == \'node\' && is_numeric(arg(1))) { $node = node_load(arg(1)); $uid = $node->uid; } return $uid;', 'validate_argument_node_type' => array( 'blog' => 0, 'activitystream' => 0, 'panel' => 0, 'blogroll_view' => 0, 'discussions' => 0, 'jobs' => 0, 'page' => 0, 'photogallery' => 0, 'profile' => 0, 'story' => 0, ), 'validate_argument_node_access' => 0, 'validate_argument_nid_type' => 'nid', 'validate_argument_vocabulary' => array( '3' => 0, '4' => 0, '1' => 0, ), 'validate_argument_type' => 'tid', 'validate_argument_transform' => 0, 'validate_user_restrict_roles' => 0, 'validate_argument_php' => '', 'me_validate_user_restrict_roles' => 0, ), )); $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', 'override' => array( 'button' => 'Override', ), 'relationship' => 'none', ), 'type' => array( 'operator' => 'in', 'value' => array( 'blogroll_view' => 'blogroll_view', ), 'group' => '0', 'exposed' => FALSE, 'expose' => array( 'operator' => FALSE, 'label' => '', ), 'id' => 'type', 'table' => 'node', 'field' => 'type', 'override' => array( 'button' => 'Override', ), 'relationship' => 'none', ), )); $handler->override_option('access', array( 'type' => 'none', )); $handler->override_option('cache', array( 'type' => 'none', )); $handler->override_option('title', 'My Blogroll'); $handler->override_option('use_pager', '1'); $handler = $view->new_display('page', 'blogroll_Page', 'page_1'); $handler->override_option('path', 'blogroll'); $handler->override_option('menu', array( 'type' => 'default tab', 'title' => 'blogroll', 'description' => 'list of your favourite blogs', 'weight' => '0', 'name' => 'navigation', )); $handler->override_option('tab_options', array( 'type' => 'tab', 'title' => 'blogroll', 'description' => 'a list of your favourite blogs', 'weight' => '0', 'name' => 'navigation', )); $handler = $view->new_display('block', 'blogroll_Block', 'block_1'); $handler->override_option('block_description', ''); $handler->override_option('block_caching', -1);

Goodluck!

MAds