如何在 Drupal 中链接自定义结果
作为 Drupal 和编程新手,我第一次来到这里。
所以我有一个问题需要帮助。
function query_results($searchstring, $datefrom) {
$tidresult = db_query("SELECT tid FROM {term_data} WHERE LOWER(name) = '%s'", strtolower($searchstring));
$resultarray = array();
while ($obj = db_fetch_object($tidresult)) {
$tid = $obj->tid;
$noderesults = db_query("SELECT n.nid, n.title FROM {node} n
INNER JOIN {term_node} tn ON tn.nid = n.nid
WHERE tn.tid='%s'", $tid);
while ($nodeobj = db_fetch_object($noderesults)) {
$resultarray[$nodeobj->nid] = $nodeobj->title;
}
}
$header = array(
array('data' => 'Nr.'),
array('data' => 'Name'),
);
$rows = array();
$i = 0;
foreach($resultarray as $nid => $title) {
$i++;
$rows[] = array('data' =>
array(
$i,
$title,
),
);
}
$output = theme('table', $header, $rows);
print theme("page", $output);
}
这让我发疯,我没有输入所有搜索代码,但它从数据库中获取分类标签(您在具有自动完成功能的文本框中输入“$searchstring”)和日期(您选择一个时间线,例如一天,昨天等。 ,'$datefrom')。
例如,假设当您单击搜索时,它看起来像这样示例。
我无法发布我的一张图片,但我只是给了我标题(如上所示,但未列出),我无法单击这些标题来引导我找到内容。
但我不希望它看起来像内容(故事)那样的结果,所以你有一个可点击的标题和一些描述,就像这样 点击查看示例 其中写着 lorem ipsum 和下面的文字。
如果很难像图片中那样制作,有人可以告诉我如何将不可点击标题的结果(如第一张图片所示)制作成可点击链接,引导我找到内容。
My first time here an a newbee in Drupal and programming .
So I have a problem I need to some help with.
function query_results($searchstring, $datefrom) {
$tidresult = db_query("SELECT tid FROM {term_data} WHERE LOWER(name) = '%s'", strtolower($searchstring));
$resultarray = array();
while ($obj = db_fetch_object($tidresult)) {
$tid = $obj->tid;
$noderesults = db_query("SELECT n.nid, n.title FROM {node} n
INNER JOIN {term_node} tn ON tn.nid = n.nid
WHERE tn.tid='%s'", $tid);
while ($nodeobj = db_fetch_object($noderesults)) {
$resultarray[$nodeobj->nid] = $nodeobj->title;
}
}
$header = array(
array('data' => 'Nr.'),
array('data' => 'Name'),
);
$rows = array();
$i = 0;
foreach($resultarray as $nid => $title) {
$i++;
$rows[] = array('data' =>
array(
$i,
$title,
),
);
}
$output = theme('table', $header, $rows);
print theme("page", $output);
}
It's driving me crazy , i dint put all of the search code but it takes taxonomy tags from the database ( you type in textbox that has autocomplete, '$searchstring' ) and date ( you choose a time line like one day , yesterday ect. , '$datefrom').
For example reasons lets say it looks like this example when you click search.
I can't post my one pictures but I just gives me the titles ( like above but the are not listed) that I cannot click to lead me to the content.
But I wont it to look like result that is like content ( story ) so you have a clickable Title and some description , like this click to see example
where it says lorem ipsum and that text belowe.
If it is hard to make like in the picture can someone show me just how to make( like in the first picture) the results that are non clickable titles into clickable links that lead me to the content.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获取链接标题,您需要使用
l()
函数。查看您提供的代码,我不完全确定您如何获得任何结果,因为您将标题保存在
$resultArray
中,但在渲染表格时使用$rows
。除非在其他地方指定了 $rows,否则
$resultarray[$nodeobj->nid] = $nodeobj->title;
应变为$rows[$nodeobj->nid] = $nodeobj->标题;
为了使其与您的表标题匹配,您需要为数字列添加另一个“单元格”。
为了提供摘录,您需要加入 node_revisions 表并获取正文或预告列,然后将其添加到您的行中,如下所示:
假设你收到了预告片。
编辑
之前的答案仍然成立。您还可以通过直接在 $noderesults 循环中处理 $rows 来稍微简化代码。
函数 query_results($searchstring, $datefrom) {
$tidresult = db_query("从 {term_data} WHERE LOWER(name) = '%s' 中选择 tid", strtolower($searchstring));
-或者-
将其全部移动到一个查询中(注意:我没有机会测试这一点,但我通常第一次就做对了):
To get linked titles you need to use the
l()
function.looking at the code you provided, I am not entirely sure how you are getting any results since you save the titles in
$resultArray
but use$rows
when rendering the table.Unless, $rows is specified somewhere else,
$resultarray[$nodeobj->nid] = $nodeobj->title;
should become$rows[$nodeobj->nid] = $nodeobj->title;
To make it match your table header, you need to add another 'cell' for the number column
To provide the excerpt too, you need to join the node_revisions table and get either the body or teaser column, then add it to your rows like this:
assuming you get the teaser.
EDIT
the previous answer still holds. You can also simplify the code a bit by processing $rows straight in the $noderesults loop.
function query_results($searchstring, $datefrom) {
$tidresult = db_query("SELECT tid FROM {term_data} WHERE LOWER(name) = '%s'", strtolower($searchstring));
-OR-
move it all in one query (note: I did not get a chance to test this, but I usually get it right the first time):