blog_page_last

Versions
4.6 – 7
blog_page_last()

Menu callback; displays a Drupal page containing recent blog entries of all users.

Code

modules/blog/blog.pages.inc, line 68

<?php
function blog_page_last() {
  global $user;
  $build = array();

  if (user_access('create blog content')) {
    $items[] = l(t('Create new blog entry.'), "node/add/blog");
    $build['blog_actions'] = array(
      '#items' => $items,
      '#theme' => 'item_list',
      '#weight' => -1,
    );
  }

  $query = db_select('node', 'n')->extend('PagerDefault');
  $nids = $query
    ->fields('n', array('nid', 'sticky', 'created'))
    ->condition('type', 'blog')
    ->condition('status', 1)
    ->orderBy('sticky', 'DESC')
    ->orderBy('created', 'DESC')
    ->limit(variable_get('default_nodes_main', 10))
    ->addTag('node_access')
    ->execute()
    ->fetchCol();

  if (!empty($nids)) {
    $nodes = node_load_multiple($nids);
    $build += node_build_multiple($nodes);
    $build['pager'] = array(
      '#theme' => 'pager',
      '#weight' => 5,
    );
  }
  else {
    drupal_set_message(t('No blog entries have been created.'));
  }
  drupal_add_feed(url('blog/feed'), t('RSS - blogs'));

  return $build;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.