维昂 發表於 2024-3-1 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列表页调用文章正文内容的方法。分享给大家供大家参考。具体分析如下:</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        一般来说,在列表页面要获取文章内容简单描述的话我们可以直接使用description标签就可以了,但是如果要有很多估计我们需要进行一些简单的修改。</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        在制作织梦模板的时候,有的时候我们需要调用文章部分内容,用标签字数不够多(数据库设计字段是varchar(255)的),另外修改了文章内容但是摘要还需要手动修改,所以只能调用文章正文内容了.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        实现织梦DedeCMS列表页调用文章正文的方法有两种,不过都是使用的dede:arclist标签,如果使用dede:list标签的话,第一种方法是调用不出结果的.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        以下是织梦DedeCMS列表页调用文章正文的第一种方法,代码如下:<br>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode15" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        {dede:arclist flag='h' row='10′} <br>
        &lt;h1&gt;&lt;a href=''&gt;&lt;/a&gt;&lt;/h1&gt; <br>
        &lt;p&gt; $aid = @me; $row = $GLOBALS['dsql']-&gt;GetOne("Select body From 'dede_addonarticle' where aid='$aid' "); @me = <br>
        cn_substr(strip_tags("{$row['body']}"),400);&lt;a href=''&gt;【阅读详细】&lt;/a&gt;&lt;/p&gt;<br>
        {/dede:arclist}</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>代码中的数字400是用来设置需要调用多少内容的,因为调用的是body里面的内容,如果有里面包含代码的话也会被调用出来,这点比较不好,不过可以使用html2tex()函数解决一下.</span>
<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";'>
        <strong>第二种方法则是利用了织梦可以自定义模型内容数据,并调用的原理,把文章模板的body字段看做在自定义的</strong>,调用的代码如下:<br>
         </p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <div class="right">
                <span><u>复制代码</u></span>
</div>
        代码如下:</div>
<div class="msgborder" id="phpcode16" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        {dede:arclist row='10' addfields='body' channelid='1'} <br>
        &lt;p&gt; ...&lt;/p&gt; <br>
        &lt;span class="more"&gt; <br>
        &lt;a href=" "&amp; gt; [详 情] <br>
        &lt;/a&gt; <br>
        &lt;/span&gt; <br>
        {/dede:arclist}</div>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><strong style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>以下是这种方法的详细说明:</strong><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'> </span>
<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";'>
        1.addrields=”字段一,字段二…”</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        2.idlist:文章编号,调用指定内容</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        3.function=’cn_substr(html2text(@me),600)’ 将文章内容转化为文字格式</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        4.channelid,模型编号,文章默认为1,查看位置:后台–核心–内容模型管理</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        两种方法各有优劣,第一种方法比较繁琐,不是那么容易看懂,还是比较推荐采用第二种方法实现织梦DedeCMS列表页调用文章正文的功能的.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        谁说dede:list 标签不能调用body内容,现在就告诉你,直接就可以调用</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        第一步,打开后台 核心--&gt;频道模型--&gt;内容模型管理--&gt;普通文章,在列表附加字段中添加body.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        第二步,在dede:list语句中指定addfields='body',然后直接用调用全部内容.</p>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        实例代码如下:</p>
<blockquote>
        <ol class="dp-c">
<li class="alt">
                        <span><span>{dede:list pagesize=</span><span class="string">'18'</span><span> addfields=</span><span class="string">'body'</span><span>}  </span></span>
</li>
                <li>
                        <span>&lt;li&gt;  </span>
</li>
                <li class="alt">
                        <span>&lt;p&gt;&lt;/p&gt;  </span>
</li>
                <li>
                        <span>&lt;p&gt;&lt;a href=<span class="string">""</span><span> title=</span><span class="string">""</span><span>&gt;&lt;/a&gt;&lt;/p&gt;  </span></span>
</li>
                <li class="alt">
                        <span>&lt;/li&gt;  </span>
</li>
                <li>
                        <span>{/dede:list} </span>
</li>
        </ol>
</blockquote>
<p>
        <span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>另外,如果像摘要一样调用可以用,代码如下:</span></p>
<blockquote>
        <ol class="dp-c">
<li class="alt">
                        <span><span> </span></span>
</li>
        </ol>
</blockquote>
<p>
        <br><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>替代:</span></p>
<blockquote>
        <ol class="dp-c">
<li class="alt">
                        <span><span> </span></span>
</li>
        </ol>
</blockquote>
<br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>调出文章前200个字符内容,经过这两步,可以彻底关掉系统默认的文章摘要功能,最后还有就是官方的一个字段了,这个如果对于要求几十个字的完全可以了,但是如果太多字此字段就无效了.</span>
<p style='margin: 0px; padding: 5px 0px; outline: none; font-size: 14px; line-height: 30px; font-family: tahoma, arial, "Microsoft YaHei";'>
        希望本文所述对大家的dedecms建站有所帮助。</p>
頁: [1]
查看完整版本: dedecms列表页调用文章正文内容的方法