无法在面板中显示块

发布于 2024-10-31 05:23:59 字数 1503 浏览 0 评论 0原文

我对 drupal 很陌生,对面板也很陌生。我有一个自定义模块,它根据用户分类显示 RSS 提要项目。它将正确的信息显示为块,但它需要位于使用面板的用户仪表板页面上。当我尝试插入它时,它总是空白。

该代码插入了我已经创建的默认视图,将所有提要项目 (1_feeds_defaults_feed_items) 显示到一个块中。我无法编辑它以在面板中工作。我想象我可能做错了 10 件不同的事情,但我已经尝试了我能想到的每一种排列。

<?php
//.this function generates a block and calls the second 
//function for the content of this block

function custom_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
  $block[0]['info'] = 'Custom View';
        $block[2]['cache'] = BLOCK_NO_CACHE;

  return $block;
   break;
case 'view':

            switch ($delta) {
      case 0:
        $block['subject'] = '';
        $block['content'] = custom_userfeeds() ;
        break;
    }

  return $block;
}
}


function custom_userfeeds() {
//finds the user id from argument on user page.  
//You can also find the user id the way the page you linked me to did, 
//but if you do it the way I am below it would allow admins 
//to view other users feeds
$uid = arg(1);
//loads the profile node -- 'profile' is the profile content type.

$node = content_profile_load('profile', $uid);
//find the terms associated with the user's profile

if ($node && $node->taxonomy) {
foreach($node->taxonomy as $term) {
  $terms[] = $term->tid;
}
}

//embeds a view with those terms passed to it.  
View display is something like block_1 or page_1
if($terms) {
$t = implode('+',$terms);
 return views_embed_view("1_feeds_defaults_feed_items","page_1", $t);
}

}

I'm new to drupal, and very new to panels. I have a custom module which displays rss feed items based on user taxonomy. It displays the correct info as a block, but it needs to be on the users' dashboard page, which uses panels. When I try to insert it, it is always blank.

The code inserts a default view I already created, showing all feed items (1_feeds_defaults_feed_items) into a block. I can't edit it to work in a panel. I imagine that there are 10 different things I may have done wrong, but have tried every permutation I can think of.

<?php
//.this function generates a block and calls the second 
//function for the content of this block

function custom_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
  $block[0]['info'] = 'Custom View';
        $block[2]['cache'] = BLOCK_NO_CACHE;

  return $block;
   break;
case 'view':

            switch ($delta) {
      case 0:
        $block['subject'] = '';
        $block['content'] = custom_userfeeds() ;
        break;
    }

  return $block;
}
}


function custom_userfeeds() {
//finds the user id from argument on user page.  
//You can also find the user id the way the page you linked me to did, 
//but if you do it the way I am below it would allow admins 
//to view other users feeds
$uid = arg(1);
//loads the profile node -- 'profile' is the profile content type.

$node = content_profile_load('profile', $uid);
//find the terms associated with the user's profile

if ($node && $node->taxonomy) {
foreach($node->taxonomy as $term) {
  $terms[] = $term->tid;
}
}

//embeds a view with those terms passed to it.  
View display is something like block_1 or page_1
if($terms) {
$t = implode('+',$terms);
 return views_embed_view("1_feeds_defaults_feed_items","page_1", $t);
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榆西 2024-11-07 05:23:59

这是我在视图中修复它的方法:
-添加参数->分类->分类术语 ID
- 提供默认参数
-PHP代码
-PHP 参数代码:

global $user;
$query = "SELECT tid FROM {term_user} WHERE uid = %d";
$result = db_query($query, $user->uid);
if ($result) {
  $terms = array();
  while ($term = db_fetch_array($result)) {
  $terms[] = $term['tid'];
  }
if ($terms) {
   $termargs = implode("+", $terms);
   return $termargs;
  }
}
 else {
 return FALSE;
}

-检查“每个参数允许多个术语”。

Here is how I fixed it in a view:
-Add Argument -> Taxonomy -> Taxonomy Term ID
-Provide default argument
-PHP Code
-PHP argument code:

global $user;
$query = "SELECT tid FROM {term_user} WHERE uid = %d";
$result = db_query($query, $user->uid);
if ($result) {
  $terms = array();
  while ($term = db_fetch_array($result)) {
  $terms[] = $term['tid'];
  }
if ($terms) {
   $termargs = implode("+", $terms);
   return $termargs;
  }
}
 else {
 return FALSE;
}

-Check "Allow multiple terms per argument."

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文