top-image

OLDER ARTICLES

在 PbootCMS 中,可以使用特定的标签来获取当前站点的网址和当前页面的 URL。这对于需要使用网站路径前缀或者获取当前页面地址的场景非常有用。

1. 当前站点网址

  • 标签{pboot:httpurl}
  • 功能: 自适应获取当前访问的网址。

2. 当前页面

  • 标签{pboot:pageurl}
  • 功能: 获取当前访问页面的地址。

示例代码

1. 获取当前站点网址

html
 
<!-- 获取当前站点网址 -->
<p>当前站点网址: {pboot:httpurl}</p>

2. 获取当前页面地址

html
 
<!-- 获取当前页面地址 -->
<p>当前页面地址: {pboot:pageurl}</p>

使用说明

  1. 当前站点网址 ({pboot:httpurl})

    • 这个标签会返回当前站点的完整 URL,包括协议(HTTP 或 HTTPS)。
    • 例如:如果用户访问的是 https://example.com/page.html,则 {pboot:httpurl} 返回 https://example.com
  2. 当前页面地址 ({pboot:pageurl})

    • 这个标签会返回当前页面的完整 URL,包括协议(HTTP 或 HTTPS)。
    • 例如:如果用户访问的是 https://example.com/page.html,则 {pboot:pageurl} 返回 https://example.com/page.html

完整示例

假设你有一个简单的 HTML 页面,需要展示当前站点的网址和当前页面的地址:

html
 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>当前网址示例</title>
</head>
<body>
<h1>当前网址示例</h1>

<!-- 获取当前站点网址 -->
<p>当前站点网址: {pboot:httpurl}</p>

<!-- 获取当前页面地址 -->
<p>当前页面地址: {pboot:pageurl}</p>
</body>
</html>

应用场景

  1. 链接构建

    • 可以用来构建绝对路径的链接。
    • 例如:<img src="{pboot:httpurl}/images/logo.png" />
  2. 资源引用

    • 可以用来引用静态资源,如 CSS、JavaScript 文件。
    • 例如:<link rel="stylesheet" href="{pboot:httpurl}/css/style.css" />
  3. 表单提交

    • 可以用来设置表单的提交地址。
    • 例如:<form action="{pboot:pageurl}" method="post">

通过这些标签,你可以轻松地获取当前站点的网址和当前页面的地址,从而更好地管理和构建网站的各种链接和资源引用。

在 PbootCMS 中,可以使用不同的参数来控制内容的截取和显示。特别是针对中文和英文字符的不同长度问题,提供了 len=* 和 lencn=* 参数来分别处理普通长度截取和中文字符长度截取。

常用参数说明

  1. len=*

    • 用于普通长度截取,每个字符按一个单位计算。
    • 例如:[list:title len=10] 将截取标题的前 10 个字符。
  2. lencn=*

    • 用于中文字符长度截取,中文字符按一个单位计算,英文字符按半个单位计算。
    • 例如:[list:title lencn=10] 将截取标题的前 10 个“中文字符单位”。
  3. more=*

    • 设置省略号内容,通常用于截取后添加省略号。
    • 例如:[list:title len=10 more="..."] 将截取标题的前 10 个字符,并在末尾添加省略号。
  4. more=''

    • 不显示省略号。
    • 例如:[list:title len=10 more=""] 将截取标题的前 10 个字符,不添加任何省略号。
  5. substr=x,y

    • 用于截取字符串的一部分。
    • 第一个数字表示起始位置(从 0 开始计数),第二个数字表示截取长度。
    • 例如:[list:title substr=5,10] 将截取标题从第 6 个字符开始的 10 个字符。

为了实现居中裁剪图片的功能,可以通过修改 cut_img 方法来实现。具体步骤如下:

  1. 定位并修改 cut_img 方法

    • 文件位置:/core/function/file.php
    • 修改 cut_img 方法,使其支持居中裁剪。
  2. 修改后的 cut_img 方法

    • 在裁剪前先进行缩放处理,然后从中心位置裁剪。

以下是修改后的 cut_img 方法代码:

php
 
// 剪切图片
function cut_img($src_image, $out_image = null, int $new_width = null, int $new_height = null, $img_quality = 90)
{
// 输出地址
if (! $out_image)
$out_image = $src_image;

// 读取配置文件设置
if (! $new_width && ! $new_height)
return;

// 获取图片属性
list ($width, $height, $type, $attr) = getimagesize($src_image);

switch ($type) {
case IMAGETYPE_GIF:
$img = imagecreatefromgif($src_image);
break;
case IMAGETYPE_JPEG:
$img = imagecreatefromjpeg($src_image);
break;
case IMAGETYPE_PNG:
$img = imagecreatefrompng($src_image);
break;
}

// 不限定是等比例缩放
if (! $new_width) {
$new_width = floor($width * ($new_height / $height));
}
if (! $new_height) {
$new_height = floor($height * ($new_width / $width));
}

// 创建画布
$new_img = imagecreatetruecolor($new_width, $new_height);

// 创建透明画布,避免黑色
if ($type == IMAGETYPE_GIF || $type == IMAGETYPE_PNG) {
$color = imagecolorallocate($new_img, 255, 255, 255);
imagefill($new_img, 0, 0, $color);
imagecolortransparent($new_img, $color);
}

// 先缩放
$scale = max($new_width / $width, $new_height / $height);
$scale_width = floor($scale * $width);
$scale_height = floor($scale * $height);
$scale_img = imagecreatetruecolor($scale_width, $scale_height); // 创建画布
if (function_exists("imagecopyresampled")) {
imagecopyresampled($scale_img, $img, 0, 0, 0, 0, $scale_width, $scale_height, $width, $height);
} else {
imagecopyresized($scale_img, $img, 0, 0, 0, 0, $scale_width, $scale_height, $width, $height);
}

// 再裁剪
$start_x = ($scale_width - $new_width) / 2;
$start_y = ($scale_height - $new_height) / 2;

// 拷贝剪切的图像数据到画板,生成剪切图像
imagecopy($new_img, $scale_img, 0, 0, $start_x, $start_y, $new_width, $new_height);

check_dir(dirname($out_image), true); // 检查输出目录

switch ($type) {
case IMAGETYPE_GIF:
imagegif($new_img, $out_image, $img_quality);
break;
case IMAGETYPE_JPEG:
imagejpeg($new_img, $out_image, $img_quality);
break;
case IMAGETYPE_PNG:
imagepng($new_img, $out_image, $img_quality / 10); // $quality参数取值范围0-99 在php 5.1.2之后变更为0-9
break;
default:
imagejpeg($new_img, $out_image, $img_quality);
}
imagedestroy($new_img);
imagedestroy($img);
return true;
}

使用方法

使用 {pboot:list} 标签时,添加 width 和 height 参数来生成居中裁剪的图片:

html
 
{pboot:list scode=*}
<a href="[list:link]"><img src="[list:ico width=600 height=400]" alt="[list:title]" /></a>
{/pboot:list}

说明

  1. width 和 height 参数

    • 设置图片的宽度和高度,裁剪后的图片将居中裁剪为指定大小。
  2. 居中裁剪

    • 通过计算裁剪起始点 $start_x 和 $start_y,确保裁剪从中心位置开始。

通过以上修改,你可以实现居中裁剪图片的功能,无论图片是横图还是竖图,都能得到理想的裁剪效果。

在PbootCMS中,要一次性获取一个栏目下所有专题模型(即单页内容),可以使用模板标签 {pboot:nav} 和 {pboot:content} 来实现。下面是一个具体的示例代码,展示了如何获取一个栏目下的所有单页内容,并且可以排除指定编号的单页。

示例代码

  1. 获取所有单页内容
html
 
<!-- 获取所有单页内容 -->
{pboot:nav parent="栏目编号"}
{pboot:if('[nav:type]' == 1)}
{pboot:content scode="[nav:scode]"}
[content:content]
{/pboot:content}
{/pboot:if}
{/pboot:nav}

说明

  • {pboot:nav parent="栏目编号"}:获取指定栏目的所有子栏目。
  • {pboot:if('[nav:type]' == 1)}:判断子栏目类型是否为单页(专题模型)。
  • {pboot:content scode="[nav:scode]"}:获取指定单页的内容。
  • [content:content]:显示单页的内容。
  1. 排除指定编号的单页
html
 
<!-- 排除指定编号的单页 -->
{pboot:nav parent="栏目编号"}
{pboot:if('[nav:type]' == 1 && '[nav:scode]' != "需要排除的编号")}
{pboot:content scode="[nav:scode]"}
[content:content]
{/pboot:content}
{/pboot:if}
{/pboot:nav}

说明

  • {pboot:if('[nav:type]' == 1 && '[nav:scode]' != "需要排除的编号")}:判断子栏目类型是否为单页,并且排除指定编号的单页。
首页/列表标签:
 
列表页时间:[list:date]   效果:2021-12-06 09:12:30
 
列表页时间:[list:date style=Y-m-d]   效果:2021-12-06
 
列表页时间:[list:date style=Y   效果:2021
 
列表页时间:[list:date style=m-d]   效果:12-06
 
列表页时间:[list:date style=y-m-d]   效果:21-12-06
 
 
内容页:
 
详情页:{content:date}   效果:2021-12-06 09:12:30
 
详情页:{content:date style=Y-m-d}   效果:2021-12-06
 
详情页:{content:date style=m-d}   效果:12-06

在PbootCMS中,你可以使用特定的模板标签来实现留言板功能。以下是如何使用留言板标签来实现留言提交表单和留言记录列表的具体方法。

1. 留言提交表单

示例代码

html
 
<!-- 留言提交表单 -->
<form action="{pboot:msgaction}" method="post">
<label for="contacts">联系人:</label>
<input type="text" name="contacts" id="contacts" required>

<label for="mobile">手机:</label>
<input type="text" name="mobile" id="mobile" required>

<label for="content">内容:</label>
<textarea name="content" id="content" rows="4" required></textarea>

<label for="checkcode">验证码:</label>
<input type="text" name="checkcode" id="checkcode">
<img title="点击刷新" src="{pboot:checkcode}" onclick="this.src='{pboot:checkcode}?'+Math.round(Math.random()*10);" />

<button type="submit">提交</button>
</form>

说明

  • 表单提交方式:使用 POST 方法提交表单。
  • 表单字段:确保表单中的字段名称与后台自定义表单中添加的字段一致。
  • 验证码:使用 {pboot:checkcode} 获取验证码图片地址,并提供刷新功能。

2. 留言记录列表

示例代码

html
 
<!-- 留言记录列表 -->
{pboot:message num="10" page="1"}
<div class="message-item">
<p>序号:[message:i]</p>
<p>联系人:[message:contacts]</p>
<p>手机:[message:mobile substr=1,3]****[message:mobile substr=8]</p>
<p>内容:[message:content]</p>
<p>留言时间:[message:askdate]</p>
<p>回复内容:[message:recontent]</p>
<p>回复时间:[message:replydate]</p>
</div>
{/pboot:message}

说明

  • 控制参数
    • num="10":每页显示的留言数量,默认为10条。
    • page="1":启用分页,默认为开启状态。
  • 可用标签
    • [message:i]:留言序号,从1开始。
    • [message:contacts]:联系人。
    • [message:mobile]:手机号。
    • [message:content]:留言内容。
    • [message:recontent]:回复内容。
    • [message:askdate]:留言时间。
    • [message:replydate]:回复时间。
    • [message:mobile substr=1,3]****[message:mobile substr=8]:手机号隐私保护,显示为 187****6563

pbootcms详情页常见标签调用

标题:{content:title}
浏览量:{content:visits}

发布时间:{content:date style=Y-m-d}
来源:{content:source}
作者:{content:author}

文章内容:{content:content}

上一篇:{content:precontent}
下一篇:{content:nextcontent}

返回栏目页:{sort:link}

相关资讯:
{pboot:list scode={sort:scode} num=4}
[list:title]
{/pboot:list}

pbootcms模板时间调用主要是用date标签,具体操作方法如下,下面AB模板网列举了详细的调用方法:

列表页时间:[list:date]   效果:2021-12-06 09:12:30
列表页时间:[list:date style=Y-m-d]   效果:2021-12-06
列表页时间:[list:date style=Y]   效果:2021
列表页时间:[list:date style=m-d]   效果:12-06
列表页时间:[list:date style=y-m-d]   效果:21-12-06
 
详情页:{content:date}   效果:2021-12-06 09:12:30
详情页:{content:date style=Y-m-d}   效果:2021-12-06
详情页:{content:date style=m-d}   效果:12-06

在PbootCMS中,如果你遇到后台输入的换行符(如 <br>)在前端显示时变成了文本(如 &lt;br&gt;),可以通过使用格式化标签来解决这个问题。

解决方案

  1. 使用解码标签

    • 在模板中使用 {sort:subname decode=1} 这样的格式化标签来解码HTML实体。
  2. 具体示例

    • 假设你需要显示一个包含换行符的内容。

在PbootCMS中,你可以使用 {pboot:slide} 标签来调用幻灯片轮播图。以下是如何在模板中使用该标签的具体方法:

幻灯片轮播图标签示例

1. 基本用法

假设你需要在一个页面上显示某个分组的幻灯片轮播图,可以按照以下方式编写模板代码:

html
 
<!-- 示例:幻灯片轮播图 -->
<div class="carousel">
<div class="carousel-inner">
{pboot:slide gid="group1" num="5"}
<div class="carousel-item{if [slide:index]==1} active{/if}">
<img src="[slide:src]" alt="[slide:title]" />
<div class="carousel-caption">
<h3>[slide:title]</h3>
<p>[slide:description]</p>
</div>
</div>
{/pboot:slide}
</div>
</div>

说明

  1. 基本结构

    • <div class="carousel"> 和 <div class="carousel-inner"> 是轮播图的基本结构。
    • {pboot:slide gid="group1" num="5"} 开始循环遍历指定分组的幻灯片。
    • {/pboot:slide} 结束循环。
  2. 控制参数

    • gid="group1":指定幻灯片分组,必填。
    • num="5":指定输出数量,默认为5个。
  3. 模板变量

    • [slide:src]:获取幻灯片图片的路径。
    • [slide:title]:获取幻灯片的标题。
    • [slide:description]:获取幻灯片的描述。
    • [slide:index]:获取当前幻灯片的索引。
  4. 条件判断

    • {if [slide:index]==1} active{/if}:用于设置第一个幻灯片为默认激活状态。
Page 904 of 1049:« First« 901 902 903 904 905 906 907 »Last »
bottom-img