日期:2014-05-16 阅读:13180
dmandwp系统 - wordpress系统和DM系统区块建站>>
views_get_view 文档: modules/views/views.module, line 871
views_embed_view其实调用的是views_get_view
本视频用到的代码:
require:
require (path_to_theme().'/templates/display/indexlist_ul.tpl.php');
----------------
得到对象:
新建一个views区块,并建 上下文过滤器 Has taxonomy term ID
$view = views_get_view('index_list');
$view->set_display('block_indexlist');
$view->set_arguments(array($taxoid)); //这就是Has taxonomy term ID
$view->set_items_per_page(8);
$view->pre_execute();
$view->execute();
//print $view->render();
//return $view->result;
----------------
foreach得到节点的字段:
if(sizeof($view->result)>0){
foreach($view->result as $id=>$v){
$nodeindex = node_load($v->nid); //得到节点对象,由于views_get_view得不到图片,所以通过node_load($v->nid)去得到节点的图片
$url = url('node/' . $v->nid); //得到链接
if(isset($nodeindex->field_image['und'][0]['uri'])){
$style = 'thumbnail';
$imgv = image_style_url($style, $nodeindex->field_image['und'][0]['uri']); //得到图片
}
else {
$imgv = $base_path.'/sites/default/files/grid.jpg';
}
if($id==0){ $img='<div class="first"> <img src="'.$imgv.'" /> </div>';}
else {$img='';}
?>
<li >
<?php echo $img?>
<span class="fr"><?php echo date('Y-m-d',$v->node_created);?></span> <!--这是日期-->
<a href="<?php echo $url;?>"><?php echo $v->node_title;?></a></li> <!--这是标题-->
<?php
}
}
else { echo '<li>no result..</li>';}
?>
----------------
关于分类--得到分类的字段:
<?php
$taxoid=11;
$term = taxonomy_term_load($taxoid);
//pre($term);
if(isset($term->field_image['und'][0]['uri'])){
$image_uri = $term->field_image['und'][0]['uri'];
$cateimg = file_create_url($image_uri);
}
else $cateimg = $base_path.'/sites/default/files/grid.jpg';
?>
标题: <?php echo $term->name;?>
链接:<a href="<?php echo url('taxonomy/term/' . $taxoid);?>">更多</a>
图片: <img src="<?php echo $cateimg?>" />
-----------------