欢迎各位兄弟 发布技术文章
这里的技术是共享的
https://www.drupal.org/project/suggestedterms 这是网友建议的模块
https://www.drupal.org/project/inlinetags
https://www.drupal.org/project/powertagging
https://www.drupal.org/project/popular_tags
http://www.drupalla.com/project/tag_editor 好像有问题,至少中文有问题
http://www.drupalla.com/project/community_tags 感觉不理想
http://www.drupalla.com/project/active_tags 我自己亲自做的 这个有大用
来自 http://www.drupalla.com/node/2484
模块介绍:
一般标签都需要手动输入并自己用逗号分隔,这个模块可以让卷标变成输入、加入这样较为易用的方式。
并且另外有热门卷标可作为推荐卷标,一点就可以新增。可加速标签的选择,减少过多重复的同义词。
来自 http://www.drupalla.com/project/active_tags
社区标签模块,这个模块实现的功能是允许用户对内容进行贴标签操作,而且可以查看用户的标签记录:谁在什么时候贴了什么标签。
来自 http://www.drupalla.com/project/community_tags
在输入标签时,回车即可添加标签(不用切换到英文状态输入逗号了)。还附带自动完成功能。类似 WordPress 的效果。
来自 http://www.drupalla.com/project/tag_editor
赞成!0否决! | 我这里有个自定义的表单,其中有一项是让用户自己输入tags,用逗号隔开的。但我不清楚怎么入库和定义每个tag的url路径,并一起存到node里。代码片断如下: if(isset($content['small_tags'])){ $small_tags = trim($content['small_tags']); $small_tags = str_replace(',', ',', $small_tags); $arr_tags = explode(',', $small_tags); if(!empty($arr_tags)){ foreach ($arr_tags as $value) { $value = trim($value); //只匹配中文,英文的tags if(!empty($value) && preg_match("/^[\x{4e00}-\x{9fa5}A-Za-z]{2,}$/u",$value)){ //到这里就不会写了,url路径和入库,还要保存多个tag的问题! $term = new stdClass(); $term->name = $value; $term->vid = 8; $tid = taxonomy_term_save($term); $node->field_small_tags ['und'] [] ['tid']= array ( 'value' => intval($term->tid), ); ); } } } }请问用哪到哪些API呢? drupal | ||
赞成!0否决! | ?
$node=node_load($nid);$tags = array();foreach ($node->field_tags['und'] as $item) { $tags[$item['tid']] = isset($item['taxonomy_term']) ? $item['taxonomy_term'] : taxonomy_term_load($item['tid']);}$form['tags'] = array( '#type' => 'textfield', '#default_value' => taxonomy_implode_tags($tags), '#title' => 'Add Tags', '#autocomplete_path' => 'taxonomy/autocomplete/field_tags', '#maxlength' => 1024, '#element_validate' => array('taxonomy_autocomplete_validate'),page); 主要是这句:taxonomy/autocomplete/field_tags | ||
分头诗人LV 17
|
| 赞成!0否决! | 好的,谢谢诗人。 这似乎是查询吧,不是存入。 我这边的需求是用户在某个node输入"你,我,他“的时候,将这些作为术语入表,并与该node关联。 典型的应该如系统核心自带的内容类型article的tags那一项。 然后这三个term分别有个url别名,对应aaa/ni,aaa/wo,aaa/ta 最后保存到对应的数据表里,比如node表,taxonomy有关的表,url_alias表 谢谢了! |
| 赞成!0否决! | 给你一个例子: ?
function ask_form_submit($form, &$form_state) { global $user; $node = new stdClass(); $node->type = "question"; $node->title = $form_state['values']['title']; $node->body[LANGUAGE_NONE][0]['value'] = $form_state['values']['body']['value']; //$node->body[LANGUAGE_NONE][0]['summary'] = 'Here goes a summary'; $node->body[LANGUAGE_NONE][0]['format'] = 'plain_text'; $node->language = "zh-hans"; $node->uid = $user->uid; node_object_prepare($node); ; $tags = explode(',', $form_state['values']['tags']); foreach ($tags as $tag) { $node->field_tags[LANGUAGE_NONE][] = array ( 'vid' => 1, 'tid' => get_term_id($tag), 'name' => $tag, 'vocabulary_machine_name' => 'tags' ); } $node = node_submit($node); // Prepare node for a submit node_save($node); // After this call we'll get a nid drupal_set_message(t('问题'.$node->nid.'已经发表。我们将以最快的速度回复。<br> <a href="/">回到首页</a>')); $form_state['redirect'] = 'node/'.$node->nid;} |
| 赞成!0否决! | 谢谢诗人,我看了你的代码,MS在tag不存在的时候,并没有入相关表 我现在写的 foreach ($arr_tags as $key=>$tag) { $tag = trim($tag); if(!empty($tag) && preg_match("/^[\x{4e00}-\x{9fa5}A-Za-z]{2,}$/u",$tag)){ if ($term = taxonomy_get_term_by_name($tag)) { $terms_array = array_keys($term); $node->field_group_tags[LANGUAGE_NONE][] = array( 'tid'=>$terms_array[0], 'vid'=>intval($vid), 'name'=>$tag, ); } else { $term = new stdClass(); $term->name = $tag; $term->vid = intval($vid); if (! empty ( $term->name )) { $term = taxonomy_term_save ( $term ); $tid = $term->tid; $node->field_group_tags [LANGUAGE_NONE] [] = array ( 'tid' => $tid, 'vid' => intval ( $vid ), 'name' => $tag, ); } }当输入”恭喜,发财"的时候,field_group_tags表为什么只能保存一个tag呢? | ||
| |
| 赞成!0否决! | 因为你引用的部分错了,就是表单错了。 给你表单代码,留意tag 那个: function ask_form($form, &$form_state) { $form['title'] = array( '#type' => 'textfield', '#title' => '标题', '#required' => TRUE, ); $form['body'] = array( '#type' => 'text_format', //'#default_value' => $my_richtext_field['value'], '#format' => 'plain_text', '#required' => TRUE, ); /*$form['tags'] = array( '#type' => 'textfield', '#title' => '请填写合适的标签', '#autocomplete_path' => 'taxonomy/autocomplete/field_tags', '#maxlength' => 1024, '#required' => TRUE, );*/ $form['tags'] = array( '#type' => 'autocomplete_deluxe', '#title' => '请填写合适的标签', '#autocomplete_deluxe_path' => url('autocomplete_deluxe/taxonomy/field_tags', array('absolute' => TRUE)), '#multiple' => TRUE, '#maxlength' => 1024, '#required' => TRUE, ); // Add the buttons. $form['buttons'] = array(); $form['buttons']['#weight'] = 100; $form['buttons']['submit'] = array( '#type' => 'submit', '#value' => t('提交问题'), '#weight' => 5, '#submit' => array('ask_form_submit'), '#prefix' => '<div class="ask_form clearfix">', '#suffix' => '</div>', ); $form['#validate'][] = 'ask_form_validate'; return $form;} | ||
| 赞成!0否决! | 还有autocomplete_deluxe这种类型的表单元素?真心搞不懂了。 |
| 赞成!0否决! | 这个是辅助的,用了autocomplete_deluxe ,效果更好,仅此而已。 |
来自 http://www.drupalla.com/node/2684
| 赞成!0否决! | 通过 print render($content['field_tags']); 输出给文章添加的标签 默认是<a>xx</a> <a>xxx</a>两两间是空格隔开的 现在我想让他们之间由“/”反斜线分开,改怎么改呢? taxonomytagstag |
| 赞成!0否决! | 建议重写。直接foreach field_tags 然后重新输出格式。 |
| 赞成!0否决! | 直接用foreach输出的话会不会跳过cache执行,而影响效率呢(之前我用theme()复写form后,试过在.tpl.php输出build_id,由于不是从cache里读取,效率很低,本地测试打开直接空白页面了)? 有没有直接在template里函数复写的方法呢? |