I have a view built into my profile page. It shows the forum topics the user has participated in and lists all of them in descending order. The problem is that some people are forum stalwarts and this means their profile pages look a real mess.

I thought that the line $view->nodes_per_page = '5'; would limit this but alas no.

Please, how can I modify this view so it only shows, say the last five forum posts?

Many thanks!

$view = new stdClass();
  $view->name = 'user_tracker';
  $view->description = 'Shows posts started by or participated in by a given user';
  $view->access = array (
);
  $view->view_args_php = 'global $user;
// Make the first argument the current user if not already set
if (!$args[0]) {
  $args[0] = $user->uid;
}
';
  $view->page = TRUE;
  $view->page_title = 'My Posts';
  $view->page_header = 'What i said was...';
  $view->page_header_format = '1';
  $view->page_footer = '';
  $view->page_footer_format = '1';
  $view->page_empty = 'No posts found.';
  $view->page_empty_format = '1';
  $view->page_type = 'table';
  $view->url = 'user/$arg/tracker';
  $view->use_pager = TRUE;
  $view->nodes_per_page = '5';
  $view->sort = array (
    array (
      'tablename' => 'node_comment_statistics',
      'field' => 'last_comment_timestamp',
      'sortorder' => 'DESC',
      'options' => 'normal',
    ),
  );
  $view->argument = array (
    array (
      'type' => 'uidtouch',
      'argdefault' => '7',
      'title' => '',
      'options' => '',
      'wildcard' => '',
      'wildcard_substitution' => '',
    ),
  );
  $view->field = array (
    array (
      'tablename' => 'node',
      'field' => 'title',
      'label' => 'Title',
      'handler' => 'views_handler_field_nodelink_with_mark',
      'options' => 'link',
    ),
    array (
      'tablename' => 'users',
      'field' => 'name',
      'label' => 'Poster',
    ),
    array (
      'tablename' => 'node_comment_statistics',
      'field' => 'comment_count',
      'label' => 'Replies',
      'handler' => 'views_handler_comments_with_new',
    ),
    array (
      'tablename' => 'node_comment_statistics',
      'field' => 'last_comment_timestamp',
      'label' => 'Updated',
      'handler' => 'views_handler_field_since',
    ),
  );
  $view->filter = array (
    array (
      'tablename' => 'node',
      'field' => 'status',
      'operator' => '=',
      'options' => '',
      'value' => '1',
    ),
    array (
      'tablename' => 'node',
      'field' => 'type',
      'operator' => 'OR',
      'options' => '',
      'value' => array (
  0 => 'forum',
),
    ),
  );
  $view->exposed_filter = array (
  );
  $view->requires = array(node_comment_statistics, node, users);
  $views[$view->name] = $view;

Comments

nevets’s picture

How are you displaying the view in the profile?

mouse77e’s picture

      $view = views_get_view('user_tracker');
      print views_build_view('embed', $view, array(strval($profileuser->uid)), false, false);
      
nevets’s picture

Change

 print views_build_view('embed', $view, array(strval($profileuser->uid)), false, false);

to

 print views_build_view('embed', $view, array(strval($profileuser->uid)), false, $view->nodes_per_page );
mouse77e’s picture

Nevets, I-O-U 1 Beer! many thanks!