想了解PHP实现多级分类生成树的方法示例的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于php实现多级分类生成树的方法示例图的相关问题,此外,我们还将为您介绍关于destoon实现调用当前栏
想了解PHP实现多级分类生成树的方法示例的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于php实现多级分类生成树的方法示例图的相关问题,此外,我们还将为您介绍关于destoon实现调用当前栏目分类及子分类和三级分类的方法_php实例、Hexo主题实现多级分类显示、laravel 5.4中实现无限级分类的方法示例、laravel 框架实现无限级分类的方法示例的新知识。
本文目录一览:- PHP实现多级分类生成树的方法示例(php实现多级分类生成树的方法示例图)
- destoon实现调用当前栏目分类及子分类和三级分类的方法_php实例
- Hexo主题实现多级分类显示
- laravel 5.4中实现无限级分类的方法示例
- laravel 框架实现无限级分类的方法示例
PHP实现多级分类生成树的方法示例(php实现多级分类生成树的方法示例图)
本文实例讲述了PHP实现多级分类生成树的方法。分享给大家供大家参考,具体如下:
条件,数据库里分类是按id,fid(父ID)实现多级分类的!
使用方法:
使用结果:
代码如下:
PS:
为方便读者阅读源码,上述代码使用了在线工具进行了格式化处理。更多关于PHP相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》及《》
希望本文所述对大家PHP程序设计有所帮助。
destoon实现调用当前栏目分类及子分类和三级分类的方法_php实例
调用当前栏目分类及子分类和三级分类是程序设计里常用的方法,本文就来详细讲述destoon实现调用当前栏目分类及子分类和三级分类的方法。具体操作如下:
在destoon中提供了如下的调用语句:
一级分类名:
{$m[catname]}
二级分类名:
{$c[catname]}
三级分类名:
立即学习“PHP免费学习笔记(深入)”;
{$b[catname]}
具体调用示例如下:
一、直接调用分类名称和链接:
{loop $maincat $i $m}<dl> {php $child = get_maincat($maincat, $CATEGORY, 1);} <dt><a href="{$MOD[linkurl]}{$m[linkurl]}" rel="external nofollow" rel="external nofollow" >{$m[catname]}</a></dt> {php $childs = get_maincat($m[catid], $CATEGORY, 1);} {loop $childs $i $c}<dd><a href="{$MOD[linkurl]}{$c[linkurl]}" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{$c[catname]}</a></dd>{/loop} </dl>{/loop}
二、调用分类名和其下最新文章:
{loop $maincat $i $m} {php $child = get_maincat($maincat, $CATEGORY, 1);} <div> <div> <p><h4>{$m[catname]}</h4> {php $a = get_maincat($m[catid], $CATEGORY, 1);} {loop $a $g} {php $f = get_maincat($g[catid], $CATEGORY, 1);} {loop $f $i $b} <span><a href="{$MOD[linkurl]}{$c[linkurl]}" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{$b[catname]}</a></span> {/loop} {/loop} <span><a href="{$MOD[linkurl]}{$m[linkurl]}" rel="external nofollow" rel="external nofollow" >[更多]</a></span> </p> </div> <div></div> {php $childs = get_maincat($m[catid], $CATEGORY, 1);} {loop $childs $i $c} <div> <!--{php $tags=tag("moduleid=$moduleid&condition=status=3&areaid=$cityid&length=40&catid=".$c[catid]."&order=".$MOD[order]."&pagesize=5&datetype=2&target=_blank&template=null")}--> <ul> <li><span><a href="{$MOD[linkurl]}{$c[linkurl]}" rel="external nofollow" rel="external nofollow" rel="external nofollow" >---更多</a></span>{$c[catname]}</li> {loop $tags $t} <li><!-- <span>{date(''Y-m-d'', $t[addtime])} </span> --> <a href="{$t[linkurl]}" rel="external nofollow" {if $target} target="{$target}"{/if}>{$t[title]}</a> </li> {/loop} </ul> </div> {/loop} <div></div> </div> <div></div> {/loop}
希望本文所述方法对大家destoon开发有所帮助。
Hexo主题实现多级分类显示
前言
最近在搞一个博客,是托管在github和gitcafe上的,利用Hexo生成的。
之后,发现一个问题,显示的分类都是一级的。而我想要的是:能显示多级分类
,层次分明`的那样。
问题
基本主题自带的分类显示都是一级的,如何显示多级?
解决方案
所以,研究了一下,找到了理想的方法,方法如下:
利用系统的list_categories([categories], [options])辅助函数生成分类列表;
利用css实现样式.
示例
说明:我使用的是jacman主题,以这个主题为例说明。
-
在主题文件夹下找到
layout/_widget/category.ejs
文件,内容如下:<% if (site.categories.length){ %> <div> <p><%= __(''categories'') %></p> <ul> <% site.categories.sort(''name'').each(function(item){ %> <% if(item.posts.length){ %> <li><a href="<%- config.root %><%- item.path %>" title="<%= item.name %>"><%= item.name %><sup><%= item.posts.length %></sup></a></li> <% } %> <% }); %> </ul> </div> <% } %>
-
修改内容,利用上面提到的
list_categories([categories], [options])
辅助函数:<% if (site.categories.length){ %> <div> <h3><%= __(''categories'') %></h3> <%- list_categories(site.categories) %> </div> <% } %>
修改样式文件
在主题文件夹下找到
source/css/_partial/aside.styl
文件,其他的也可能是source/css/_partial/sidebar.styl
。反正,能在页面显示即可。-
添加新的样式,我的如下:
//categories .category-block>ul>li border-bottom 1px solid #ccc .category-block li margin-bottom 8px .category-list @media mini width 45% float left margin 0 5% 0 0 @media tablet width 100% float none margin .5em 0 0 .categoriy-list-item padding .5em 5% .category-list-count top -.5em padding-left .3em font-size 75% line-height 0 position relative vertical-align baseline ul, ol, dl list-style none ul, ol, dl background-color #f9f9fa margin-left 20px li border-bottom 1px dashed #ccc .category-list-child border-top 1px dashed #ccc margin-bottom 8px
想实现不同的样式,自己可以修改。
效果图
原文来自:http://git.seay.me
laravel 5.4中实现无限级分类的方法示例
前言
本文主要给大家介绍的是关于laravel 5.4中实现无限级分类的相关内容,分享出来供有需要的朋友们参考学习,下面话不多说,来一起看看详细的介绍吧。
方法如下:
1、建立表
php artisan make:migration create_category_table --create=category
在database/migrations/下找到你的迁移文件
建入:
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateCategoryTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create(''categorys'', function (Blueprint $table) { $table->increments(''id''); $table->integer(''parent_id''); $table->string(''code''); $table->string(''name''); $table->string(''path''); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists(''categorys''); } } php artisan migrate
2、建Model 在app/Category.php
php artisan make: model Category -m
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Category extends Model { public function childCategory() { return $this->hasMany(''App\Category'', ''parent_id'', ''id''); } public function allChildrenCategorys() { return $this->childCategory()->with(''allChildrenCategorys''); } }
3、调用
$categorys = App/Category::with(''allChildrenCategorys'')->first();
或
$categorys->allChildrenCategorys;
或
$categorys->allChildrenCategorys->first()->allChildrenCategorys;
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者使用laravel能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对的支持。
- laravel 框架实现无限级分类的方法示例
- laravel7学习之无限级分类的最新实现方法
laravel 框架实现无限级分类的方法示例
本文实例讲述了laravel 框架实现无限级分类的方法。分享给大家供大家参考,具体如下:
模型中的代码
namespace App\models\wxj; use Illuminate\Support\Facades\DB; use Session; class Wxjlx { public function r(){ //输出数据库的所有内容 $sql=DB::table(''wxjlx'')->get(); //调用fl方法 $result=self::fl($sql,$pid=0); return $result; } //创建方法 $data参数是数据库所有数据 $pid参数是数据库pid $le参数是为了区分显示级别的 public function fl($data,$pid=0,$le=0){ //创建一个静态数组保存数据 static $array=array(); //循环出所有的有关数据保存进数组 foreach ($data as $v){ //当第一循环是pid==0 因为上面已经设置pid==0 if($v->pid==$pid){ //这里是为了区分级别 $v->le=$le; //将有关数据保存如数据 $array[]=$v; //为了将有关数据保存数据,这里使用递归 self::fl($data,$v->id,$le+1); } } //将最后的内容输出返回 return $array; } }
控制器代码,只是为了调用模型中方法
class WxjlxController extends BaseController { public function r(){ //实例化模型 $p=new Wxjlx(); //调用模型方法 $a=$p->r(); //将数据返回视图 return view(''wxj/r'',[''list''=>$a]); } }
视图中的方法,实现效果
@foreach($list as $v) {{str_repeat(''-|'',$v->le)}} {{$v->id}} {{$v->typename}} {{$v->pid}} <?php echo ''<br>''?> @endforeach
更多关于Laravel相关内容感兴趣的读者可查看本站专题:《Laravel框架入门与进阶教程》、《php优秀开发框架总结》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。
- laravel 5.4中实现无限级分类的方法示例
- laravel7学习之无限级分类的最新实现方法
今天关于PHP实现多级分类生成树的方法示例和php实现多级分类生成树的方法示例图的介绍到此结束,谢谢您的阅读,有关destoon实现调用当前栏目分类及子分类和三级分类的方法_php实例、Hexo主题实现多级分类显示、laravel 5.4中实现无限级分类的方法示例、laravel 框架实现无限级分类的方法示例等更多相关知识的信息可以在本站进行查询。
本文标签: