前尘往事一笔勾销 發表於 2024-4-4 00:00:00

dedecms编辑修改文章后使发布时间更新为最新时间的解决方法

<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        在使用dedecms程序的时候,我们经常会编辑会修改文章,通常发布之后时间为最新的当前时间,但是dedecms默认的时间还是以前的发布时间,我们如何来实现编辑文章后使发布时间自动变为当前最新时间呢?而且文章会自动更新到最前面!</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        这个实现的教程其实很简单,只需修改一行代码即可,对应的文件即为网站根目录 下的 /dede/templets/article_edit.htm,通过名字我们可以了解到article_edit.htm 这个文件就是文章编辑对应的文件。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        首先查找article_edit.htm里的代码,如果没有修改的话默认应该在365行左右</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <code style='margin: 3px auto 0px; padding: 2px 4px; outline: none; font-style: inherit; font-weight: inherit; background: rgb(249, 242, 244); width: 640px; line-height: 1.5; clear: both; font-size: 12px; border: 1px solid rgb(204, 204, 204); color: rgb(199, 37, 78); border-radius: 0px; font-family: Menlo, Monaco, Consolas, "Courier New", monospace;'>$nowtime = GetDateTimeMk(time());</code></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        将其改为</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <code style='margin: 3px auto 0px; padding: 2px 4px; outline: none; font-style: inherit; font-weight: inherit; background: rgb(249, 242, 244); width: 640px; line-height: 1.5; clear: both; font-size: 12px; border: 1px solid rgb(204, 204, 204); color: rgb(199, 37, 78); border-radius: 0px; font-family: Menlo, Monaco, Consolas, "Courier New", monospace;'>$nowtime = GetDateTimeMk($arcRow["pubdate"]);</code></p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        修改后,上传到源文件目录下覆盖,然后我们再次修改编辑文章时间就会变为当前最新文章了!</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        小编补充:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        有时候我们不一定需要每一篇文章都需要更新为当前时间,可以通过js加载一个按钮来实现</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:js;">
function getnow(){
var hours, minutes, seconds, xfile;
var intHours, intMinutes, intSeconds;
var today, theday;
today = new Date();
var toyear=(today.getYear() &lt; 1900 ) ? ( 1900 + today.getYear() ) : today.getYear();
theday = toyear+"-" + +"-" +today.getDate();
intHours = today.getHours().toString();
if (intHours.length&lt;2){inHours="0"+intHours.toString()}
intMinutes = today.getMinutes().toString();
if (intMinutes.length&lt;2){intMinutes="0"+intMinutes.toString()}
intSeconds = today.getSeconds().toString();
if (intSeconds.length&lt;2){intSeconds="0"+intSeconds.toString()}
timeString = theday+" "+intHours+":"+intMinutes+":"+intSeconds;
form1.pubdate.value = timeString;
}</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        下面这个是获取文章发布日期到提交日期</p>
<div class="jb51code" style='margin: 0px; padding: 0px; outline: none; line-height: 25.2px; font-size: 14px; width: 660px; overflow: hidden; clear: both; font-family: tahoma, arial, "Microsoft YaHei";'>
        <pre class="brush:js;">
function getup(){

timeString = document.form1.senddate.value;
form1.pubdate.value = timeString;
}</pre>
</div>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        效果如下图所示:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        <img style="max-width:100%!important;height:auto!important;"title="dedecms编辑修改文章后使发布时间更新为最新时间的解决方法" alt="dedecms编辑修改文章后使发布时间更新为最新时间的解决方法" src="https://zhuji.jb51.net/uploads/img/202305/66306e8f35c277849d650d166b8eb8da.jpg"></p>
頁: [1]
查看完整版本: dedecms编辑修改文章后使发布时间更新为最新时间的解决方法