[support] how to use the 2 blocks in single module

bharani kumar bharanikumariyerphp at gmail.com
Tue Jun 24 17:49:58 UTC 2008


Dears i want to use the two blocks in a single module this is my code ,

in 2 block are displayed in the blocks setting place,


i enable both , its not displaying,

Any idea..

<?php
// $Id$
/**
* Implementation of hook_block().
*
* Displays the most recent (x) blog titles on the user profile page. (x) is
set in block configuration admin section.
*/
function ptHeadlines_block($op = 'list', $delta = 0, $edit = array()) {
  global $user;
  switch ($op) {
    case 'list':
      $block[0]['info'] = t('More Headline ');
      $block[0]['title'] = t('More Headline ');

      $block[1]['info'] = t('Top Headline');
      $block[1]['title'] = t('Top Headline');

      return $block;

    case 'configure':
      $form['ptHeadlines_blog_num_posts'] = array(
        '#type' => 'textfield',
        '#title' => t('Number of Headlines to display'),
        '#default_value' => variable_get('ptHeadlines_blog_num_posts', 5),
      );
      return $form;

    case 'save':
      if ($delta == 0) {
        variable_set('ptHeadlines_blog_num_posts', (int)
$edit['ptHeadlines_blog_num_posts']);
      }
      return;

    case 'view':


      if (user_access('access content') && $delta == 0 && arg(0)=='user') {
        $num_posts = variable_get('ptHeadlines_blog_num_posts', 5);
//        $current_user_profile = arg(1);
        $result = db_query_range("select
cn.nid,cn.title,nr.title,nr.timestamp,nr.body,nr.teaser from node as
cn,node_revisions as nr where cn.nid=nr.nid and cn.type='article'ORDER BY
nr.timestamp DESC", NULL, 0,$num_posts);

drupal_set_message("This is the more headline",$result);
        if (db_num_rows($result)) {
          $moreHead = array();
          while ($blog_posts = db_fetch_object($result)) {
            $moreHead[] = "<p>".l(ucwords($blog_posts->title), 'node/'.
$blog_posts->nid)."</p>".substr($blog_posts->teaser, 0,
175)."&nbsp;&nbsp;&nbsp;".l("More","node/".$blog_posts->nid)."<br>";
        //    $moreHead[]=substr($blog_posts->title, 0, 175)."<br><br><br>";

          }
          $block['subject'] = t('More Headlines test');
          // Theme our array of links as an unordered list
          $block['content'] = theme('item_list_ameex', $moreHead);
        //  if (db_num_rows($result) == $num_posts) {
       //     //$block['content'] .= '<div class="block-view-more">'.
l(t('View more'), 'blog/'. $current_user_profile, array(), NULL, NULL,
FALSE, FALSE) .'</div>';
        //  }
        }
      }



      //this is block for top Headlines

        if (user_access('access content') && $delta == 0 && arg(0)=='user')
{
        $num_posts = variable_get('ptHeadlines_blog_num_posts', 5);
//        $current_user_profile = arg(1);
        $result = db_query_range("select
cn.nid,cn.title,nr.title,nr.timestamp,nr.body,nr.teaser from node as
cn,node_revisions as nr where cn.nid=nr.nid and cn.type='article'ORDER BY
nr.timestamp DESC", NULL, 0,1);
        drupal_set_message("This is the top headline",$result);


        if (db_num_rows($result)) {
          $topHead = array();
          while ($blog_posts = db_fetch_object($result)) {
            $topHead[] = "<p>".l(ucwords($blog_posts->title), 'node/'.
$blog_posts->nid)."</p>".substr($blog_posts->teaser, 0,
175)."&nbsp;&nbsp;&nbsp;".l("More","node/".$blog_posts->nid)."<br>";
        //    $topHead[]=substr($blog_posts->title, 0, 175)."<br><br><br>";

          }
          $block['subject'] = t('Top Headlines');
          // Theme our array of links as an unordered list
          $block['content'] = theme('item_list_ameex', $topHead);

        }
      }


      return $block;
  }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20080624/32ec41a9/attachment.htm 


More information about the support mailing list