欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal7 teaser truncate strip_tags d7 截取 摘要 并且移除 img iframe embed br 等标签 自己亲自做的 有大用 有大大用 有大大大用


1) 先在后台进行截取的处理

image.png




2) 移除图像等标签
function
_strip_only($str, $tags) {
 
if(!is_array($tags)) {
   
$tags = (strpos($str, '>') !== false ? explode('>', str_replace('<', '', $tags)) : array($tags));
   
if(end($tags) == '') array_pop($tags);
 }
 
foreach($tags as $tag) $str = preg_replace('#</?'.$tag.'[^>]*>#is', '', $str);
 
return $str;
}
/**
* Override or insert variables into the node template.
*/
function bartik_clone_preprocess_node(&$variables) {
 
if ($variables['view_mode'] == 'full' && node_is_page($variables['node'])) {
   
$variables['classes_array'][] = 'node-full';
 }
 if(isset($variables['content']['body'][0]['#markup'])  && $variables['teaser']){
   
$variables['content']['body'][0]['#markup'] = _strip_only($variables['content']['body'][0]['#markup'], '<img><iframe><embed><br>');
 }

 
// var_dump($variables['field_accepter']);
}



image.png

普通分类: