
正文
包含thinkphp实现面包屑的词条
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
如何在controller中的before
仅是一个action的时候没必要直接在那个方法中直就好,beforeFilter主要是在多个页面中执需要执行同一个功能时,(如面包屑导航条,就是每个页面都要)不用在每个写多次同样的代码。
一般在AppController.php中预先写好,在需要加载该方法的控制器中添加回调函数
以下适用于CakePHP2.X系列AppController.phppre t="code" l="php"?php
class AppController extends Controller {
App::uses('Controller', 'Controller');
function beforeFilter()
{
parent::beforeFilter();
// 调用Search模型中的getId函数
$this-Search-getId();
}
???
ContentsController.phppre t="code" l="php"?php
App::uses('AppController', 'Controller');
class ContentsController extends AppController {
var $name = 'Contents';
var $uses = array('TestModel');
/**
* 控制器处理开始前的回调函数
*/
function beforeFilter()
{
parent::beforeFilter();
}
function add()
{
// 由于写在了AppController.php的beforeFilter中,下一行无需再写
// $this-Search-getId();
}
function edit()
{
// 由于写在了AppController.php的beforeFilter中,下一行无需再写
// $this-Search-getId();
}
???
相关问答
Q1: 关于php制作面包屑导航(网页当前位置)
每次查询或处理数据的时候,向一个数组压导航数据,最后显示
Q2: wordpress 主题怎么添加面包屑导航
wordpress主题添加面包屑导航一般有两种方法,一种是通过使用插件来实现,另一种是不使用插件,纯代码实现,下面我来介绍一下这两种方法。
一,纯代码实现
在functions中添加
function get_breadcrumbs()
{
global $wp_query;
if ( !is_home() ){
// Start the UL
echo 'ul class="breadcrumbs"';
// Add the Home link
echo 'lia href="'. get_settings('home') .'"网站首页/a/li';
if ( is_category() )
{
$catTitle = single_cat_title( "", false );
$cat = get_cat_ID( $catTitle );
echo "li raquo; ". get_category_parents( $cat, TRUE, " raquo; " ) ."/li";
}
elseif ( is_archive() !is_category() )
{
echo "li raquo; Archives/li";
}
elseif ( is_search() ) {
echo "li raquo; Search Results/li";
}
elseif ( is_404() )
{
echo "li raquo; 404 Not Found/li";
}
elseif ( is_single() )
{
$category = get_the_category();
$category_id = get_cat_ID( $category[0]-cat_name );
echo 'li raquo; '. get_category_parents( $category_id, TRUE, " raquo; " );
echo the_title('','', FALSE) ."/li";
}
elseif ( is_page() )
{
$post = $wp_query-get_queried_object();
if ( $post-post_parent == 0 ){
echo "li raquo; ".the_title('','', FALSE)."/li";
} else {
$title = the_title('','', FALSE);
$ancestors = array_reverse( get_post_ancestors( $post-ID ) );
array_push($ancestors, $post-ID);
foreach ( $ancestors as $ancestor ){
if( $ancestor != end($ancestors) ){
echo 'li raquo; a href="'. get_permalink($ancestor) .'"'. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'/a/li';
} else {
echo 'li raquo; '. strip_tags( apply_filters( 'single_post_title', get_the_title( $ancestor ) ) ) .'/li';
}
}
}
}
// End the UL
echo "/ul";
}
}
在有需要添加面包屑插件的页面适当位置添加
php get_breadcrumbs();
打开主题所在的style.css,添加
ul.breadcrumbs {
list-style: none;
padding: 0;
margin: 0;
font-size:12px;
}
ul.breadcrumbs li {
float: left;
margin: 0 5px 0 0;
padding: 0;
}
通过上述三步就可以实现无插件面包屑效果,稍微的样式和布局可以修改。
二,用插件实现
这里我推荐的插件是Breadcrumb NavXT,它提供5种面包屑导航样式,如下图所示
插件的设置界面如下
看不懂英文的用翻译工具翻译一下也能大概知道意思了,其它具体的使用您可以自己去安装一下这款插件体验一下,如果有不懂再问吧。
Q3: 如何用纯代码方法实现WordPress面包屑导航效果
1、层级较深的网站,面包屑导航适合层级较深的网站,如果只有一级分类的话,通过主导航就可以起到快速定位的作用。比如“豆瓣网”类型扁平构架的网站就没有使用面包屑导航的作用。
2、独立不交叉的网站机构,由于面包屑网站导航路径是线性结构的,因此网站内容必须划分的非常清晰,且不存在交叉;否则,面包屑导航的路径就不是唯一的,同一分类可能出现在不同的路径中,让用户感到困惑。
在wordpress中添加面包屑导航的话,可以直接使用插件来实现,不过很多站长都不喜欢用插件,还是认为如果能用代码解决的话是最理想的。我最近也找了一些关于面包屑导航的资料。下文中就有详细解决怎么用代码来实现wordpress面包屑导航:
一、在wordpress博客当前主题的functions.php文件(没有就创建一个)中添加以下代码:
//面包屑导航
functionget_breadcrumbs()
{
global$wp_query;
if(!is_home()){
//StarttheUL
echo'ulclass="breadcrumbs"';
//AddtheHomelink
echo'liahref="'.get_settings('home').'"'.get_bloginfo('name').'/a/li';
if(is_category())
{
$catTitle=single_cat_title("",false);
$cat=get_cat_ID($catTitle);
echo"li?".get_category_parents($cat,TRUE,"?")."/li";
}
elseif(is_archive()!is_category())
{
echo"li?Archives/li";
}
elseif(is_search()){
echo"li?SearchResults/li";
}
elseif(is_404())
{
echo"li?404NotFound/li";
}
elseif(is_single())
{
$category=get_the_category();
$category_id=get_cat_ID($category[0]-cat_name);
echo'li?'.get_category_parents($category_id,TRUE,"?");
echothe_title('','',FALSE)."/li";
}
elseif(is_page())
{
$post=$wp_query-get_queried_object();
if($post-post_parent==0){
echo"li?".the_title('','',FALSE)."/li";
}else{
$title=the_title('','',FALSE);
$ancestors=array_reverse(get_post_ancestors($post-ID));
array_push($ancestors,$post-ID);
foreach($ancestorsas$ancestor){
if($ancestor!=end($ancestors)){
echo'li?ahref="'.get_permalink($ancestor).'"'.strip_tags(apply_filters('single_post_title',get_the_title($ancestor))).'/a/li';
}else{
echo'li?'.strip_tags(apply_filters('single_post_title',get_the_title($ancestor))).'/li';
}
}
}
}
//EndtheUL
echo"/ul";
}
}
二、在显示面包屑导航的位置添加以下调用代码:
?php
if(function_exists('get_breadcrumbs')){
get_breadcrumbs();
}
?
三、在主题的css样式文件中添加以下样式代码:
ul.breadcrumbs{list-style:none;font-size:12px;}
ul.breadcrumbsli{float:left;margin-right:5px;}
Q4: 织梦怎么修改网站面包屑导航position属性
1、如果只是需要修改前台样式,那么就直接写css就可以了
2、如果是要修改此标签的系统文件,duosucai.com建议参看下面的教程:
3、打开 /include/typelink.class.php 文件,找到如下代码:
//获得某类目的链接列表 如:类目一类目二 这样的形式
//islink 表示返回的列表是否带连接
function GetPositionLink($islink=true)
{
$indexpage = "a href='".$this-indexUrl."'".$this-indexName."/a";
4、好了,需要如何修改,你自己根据需要修改吧
多素材织梦模板
为您解答
望采纳
Q5: 怎么面包屑怎么修改
一、修改{dede:field name='position'/}的文字间隔符,官方默认的是
在include/typelink.class.php第101行左右将修改为你想要的符号即可
二、去掉{dede:field name='position' /}最后的分隔符
{dede:field name='position' runphp='yes'}
$a=mb_strlen(@me);//计算字符串的长度
@me=cn_substr(@me,$a-2,-1);//截取字符
{/dede:field}
三、{dede:field name='position'/} 中去掉 并去掉最后一个文本的链接的解决方案
{dede:field name='position' runphp='yes'}
$tc=" ";
$tf=split($tc,@me);
$tn=count($tf);
for($iij=0;$iij($tn-1);$iij++){
if($iij==($tn-2)){$tf[$iij]=strip_tags($tf[$iij]);}
$tl=$tl.$tf[$iij];
}
@me=$tl;
echo @me;
{/dede:field}
如果还需要分隔符的话,就把$tl=$tl.$tf[$iij]; 换成
$tl=$tl."空格分隔符空格".$tf[$iij];
thinkphp实现面包屑的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、thinkphp实现面包屑的信息别忘了在本站进行查找喔。






