调用留言本标题的关键在于,前台显示的数据库缺少标题字段,所以,只要向数据库添加了标题字段,就方便调用了。
参考借鉴了http://bbs.dedecms.com/read.php?tid=31033&keyword=%C1%F4%D1%D4%B1%BE,感谢gufei。
修改LOOP标记完成感谢xiaoqi指导。
步骤:
1、用PHPMYADMIN登陆您的数据库,找到DEDE数据库中的"guestbook"表,增加一个"guesttitle"字段,设为"varchar",字段大小自定。
>>>如果不想JS调用达到实时更新的目的,可以跳过步骤2和6,完成步骤3、4、5后直接使用loop循环标记:
{dede:loop table=’dede_guestbook’ sort=’dtime’ row=’10′ if=’ischeck=1′}
<a rel="nofollow noopener noreferrer" href="[field:phpurl/]/guestbook/index.php" >[field:guesttitle function="cn_substr('@me',30)"/]</a><br>
{/dede:loop}
2、在/plus/guestbook/下新建一个js.php文件,js.php内容如下:
<?php
require_once(dirname(__FILE__)."/config.php");
require_once(dirname(__FILE__)."/../../include/pub_datalist_dm.php");
setcookie("GUEST_BOOK_MOVE",GetCurUrl(),time()+3600,"/");
function GetIsCheck($ischeck,$id)
{
if($ischeck==0) return "<br><a rel="nofollow noopener noreferrer" href=’edit.php?job=check&ID=$id’ style=’color:red’>[审核]</a>";
else return "";
}
if($userrank>0) $sql = "select * from dede_guestbook order by ID desc";
else $sql = "select * from dede_guestbook where ischeck=1 order by ID desc";
$dlist = new DataList();
$dlist->Init();
$dlist->pageSize =10;
$dlist->SetParameter("gotopagerank",$gotopagerank);
$dlist->SetSource($sql);
$mylist = $dlist->GetDataList();
while($row = $mylist->GetArray(‘dm’))
{
$xingming=$row['uname'];
$neirong=strip_tags($row['guesttitle']);
$neirong=str_replace(" ","",$neirong);
$neirong=cn_substr($neirong,25);
$neirong=str_replace("
","",$neirong);
$neirong=rawurldecode($neirong);
$link=$row['ID'];
echo "document.write("- <a rel="nofollow noopener noreferrer" href=’./plus/guestbook/index.php#$link’ target=’_blank’>$neirong</A><br>");";
}
$dlist->Close();
?>
3、在templetsplusguestbook.htm文件中加上命名锚记
找到
<?php
$mylist = $dlist->GetDataList();
while($row = $mylist->GetArray(‘dm’))
{
?>
在后边加入
CODE:
<a name="<?echo $row['ID']?>"></a>
4、在/templets/plus/guestbook.htm中加入读取留言本标题的代码"<?php echo $row['guesttitle']?>"到您想要的位置。
5、将savepost.php中的:
$dsql = new DedeSql(false);
$ip = GetIP();
$dtime = strftime("%Y-%m-%d %H:%M:%S",mytime());
$uname = trimMsg($uname);
$email = trimMsg($email);
$homepage = trimMsg($homepage);
$homepage = eregi_replace("http://","",$homepage);
$qq = trimMsg($qq);
$msg = trimMsg($msg,1);
$msg = cn_substr($msg,2000);
if($msg==""||$uname==""){
showMsg("你的姓名和留言内容不能为空!",-1);
exit();
}
$query = "INSERT INTO
dede_guestbook(uname,email,homepage,qq,face,msg,ip,dtime,ischeck)
VALUES (‘$uname’,’$email’,’$homepage’,’$qq’,’$img’,’$msg’,’$ip’,’$dtime’,’$needCheck’)";
$dsql->SetQuery($query);
$dsql->ExecuteNoneQuery();
$dsql->Close();
替换为(意在读取标题到数据库):
$dsql = new DedeSql(false);
$ip = GetIP();
$dtime = strftime("%Y-%m-%d %H:%M:%S",mytime());
$uname = trimMsg($uname);
$email = trimMsg($email);
$homepage = trimMsg($homepage);
$homepage = eregi_replace("http://","",$homepage);
$qq = trimMsg($qq);
$guesttitle = trimMsg($guesttitle);
$msg = trimMsg($msg,1);
$msg = cn_substr($msg,2000);
if($msg==""||$uname==""){
showMsg("你的姓名和留言内容不能为空!",-1);
exit();
}
$query = "INSERT INTO
dede_guestbook(uname,email,homepage,qq,face,guesttitle,msg,ip,dtime,ischeck)
VALUES (‘$uname’,’$email’,’$homepage’,’$qq’,’$img’,’$guesttitle’,’$msg’,’$ip’,’$dtime’,’$needCheck’)";
$dsql->SetQuery($query);
$dsql->ExecuteNoneQuery();
$dsql->Close();
6、在首页需要调用留言本内容的地方加入
CODE:
<script language="javascript" src="./plus/guestbook/js.php" ></script>
以上就是dede如何解决留言本标题调用到首页。点了盘鱼翅炒饭,换了三双筷子没找见一块鱼翅,厨师解释说“我叫鱼翅”。更多关于dede如何解决留言本标题调用到首页请关注haodaima.com其它相关文章!