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)." ".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)." ".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; } }
bharani kumar wrote:
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');
Here you are defining $delta. The "More Headline" block is $delta == 0, and the "Top Headline" block is $delta ==1
[snip] //this is block for top Headlines
if (user_access('access content') && $delta == 0 &&arg(0)=='user') {
You need to change this line to check for $delta == 1
A more common approach for the 'view' operation is to use a switch on $delta:
switch ($delta) { case 0: // do stuff for first block break; case 1: // do stuff for second block break;
} return $block;
Cheers,
Jonathan
but u see this is my entire, Already there i used the switch case,for the configure purpose ,view and so,
Then how can i use , for the $deleta...
<?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');
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, 1, $num_posts);
if (db_num_rows($result)) { $items = array(); while ($blog_posts = db_fetch_object($result)) { $items[] = "<p>".l(ucwords($blog_posts->title), 'node/'. $blog_posts->nid)."</p>".substr($blog_posts->teaser, 0, 175)." ".l("More","node/".$blog_posts->nid)."<br>"; // $items[]=substr($blog_posts->title, 0, 175)."<br><br><br>";
} $block['subject'] = t('More Headlines'); // Theme our array of links as an unordered list $block['content'] = theme('item_list_ameex', $items); // 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
return $block; } }