Heim  >  Artikel  >  php教程  >  dede channelartlist 中引用channel 并且设置当前选择类的样式,currentstyle暂时没有效果.特发求助!!!! - samcao

dede channelartlist 中引用channel 并且设置当前选择类的样式,currentstyle暂时没有效果.特发求助!!!! - samcao

WBOY
WBOYOriginal
2016-05-20 10:19:201319Durchsuche

在dede中需要达到当前选择了该类,样式不同的话.如果是channelartlist 的话. 可以使用下面的情况:

<span style="color: #008080;">1</span> {dede:channelartlist typeid='6' row='3' currentstyle='current'<span style="color: #000000;">}
</span><span style="color: #008080;">2</span>     
  • class='{dede:field.currentstyle/}'> 3 4 {dede:field name='typename'/} 5 6
  • 7 {/dede:channelartlist}

    这个默认没有效果.需要在channelartlist.lib.php中做下面的步骤:

    在这行的下面添加

    <span style="color: #008080;">1</span> <span style="color: #800080;">$pv</span>->Fields['typeurl'] = GetOneTypeUrlA(<span style="color: #800080;">$typeids</span>[<span style="color: #800080;">$i</span>]);
    <span style="color: #008080;"> 1</span>         <span style="color: #008000;">#</span><span style="color: #008000;">#########################################################</span>
    <span style="color: #008080;"> 2</span>         
    <span style="color: #008080;"> 3</span>          <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$typeids</span>[<span style="color: #800080;">$i</span>]['id'] == <span style="color: #800080;">$refObj</span>->TypeLink->TypeInfos['id'] || <span style="color: #800080;">$typeids</span>[<span style="color: #800080;">$i</span>]['id'] == <span style="color: #800080;">$refObj</span>->TypeLink->TypeInfos['topid'<span style="color: #000000;">] ){ 
    </span><span style="color: #008080;"> 4</span>             <span style="color: #800080;">$pv</span>->Fields['currentstyle'] = <span style="color: #800080;">$currentstyle</span> ? <span style="color: #800080;">$currentstyle</span> : 'current'<span style="color: #000000;">; 
    </span><span style="color: #008080;"> 5</span> <span style="color: #000000;">        } 
    </span><span style="color: #008080;"> 6</span>         <span style="color: #0000ff;">else</span><span style="color: #000000;">{ 
    </span><span style="color: #008080;"> 7</span>             <span style="color: #800080;">$pv</span>->Fields['currentstyle'] = ''<span style="color: #000000;">; 
    </span><span style="color: #008080;"> 8</span> <span style="color: #000000;">        } 
    </span><span style="color: #008080;"> 9</span>         
    <span style="color: #008080;">10</span>         <span style="color: #008000;">#</span><span style="color: #008000;">##########################################################</span>

    添加上面的代码才可以.

     如果只是使用channel的话. 可以使用下面来实现. 在此引用 "元曦" 的图. 也谢谢"元曦"的帮助.

     

     
    但是.如果两个套一起. 就实现不了.以下帖上我的代码.
     
    <span style="color: #008080;"> 1</span> {dede:channelartlist typeid='6' row='3' currentstyle='current'<span style="color: #000000;">}
    </span><span style="color: #008080;"> 2</span>     
  • class='{dede:field.currentstyle/}'> 3 4 {dede:field name='typename'/} 5 6
      class="faq_ul2"> 7 {dede:channel type='son' noself='yes' currentstyle=" 8
    • 9 >~typename~ 10
  • 11 "} 12
  • 13 --[field:typename/] 14
  • 15 {/dede:channel} 16 17 18 {/dede:channelartlist}

     

    这样channelartlist 会有class的样式. 但是内部 channel 并不会有class="testclass" ,甚是不解。

    于是决定至底层的php文件中查看一下。在channel.lib.php中输出测试一下。

     

    <span style="color: #008080;"> 1</span>                 <span style="color: #008000;">//</span><span style="color: #008000;">处理同级栏目中,当前栏目的样式</span>
    <span style="color: #008080;"> 2</span>                 <span style="color: #0000ff;">if</span>( (<span style="color: #800080;">$row</span>['id']==<span style="color: #800080;">$typeid</span> || (<span style="color: #800080;">$topid</span>==<span style="color: #800080;">$row</span>['id'] && <span style="color: #800080;">$type</span>=='top') ) && <span style="color: #800080;">$currentstyle</span>!=''<span style="color: #000000;"> )
    </span><span style="color: #008080;"> 3</span> <span style="color: #000000;">                {
    </span><span style="color: #008080;"> 4</span>                     <span style="color: #0000ff;">print</span> 'test_4';  <span style="color: #008000;">//</span><span style="color: #008000;">测试输出</span>
    <span style="color: #008080;"> 5</span>                     <span style="color: #800080;">$linkOkstr</span> = <span style="color: #800080;">$currentstyle</span><span style="color: #000000;">;
    </span><span style="color: #008080;"> 6</span>                     <span style="color: #800080;">$row</span>['typelink'] = GetOneTypeUrlA(<span style="color: #800080;">$row</span><span style="color: #000000;">);
    </span><span style="color: #008080;"> 7</span>                     <span style="color: #800080;">$linkOkstr</span> = <span style="color: #008080;">str_replace</span>("~rel~",<span style="color: #800080;">$row</span>['rel'],<span style="color: #800080;">$linkOkstr</span><span style="color: #000000;">);
    </span><span style="color: #008080;"> 8</span>                     <span style="color: #800080;">$linkOkstr</span> = <span style="color: #008080;">str_replace</span>("~id~",<span style="color: #800080;">$row</span>['id'],<span style="color: #800080;">$linkOkstr</span><span style="color: #000000;">);
    </span><span style="color: #008080;"> 9</span>                     <span style="color: #800080;">$linkOkstr</span> = <span style="color: #008080;">str_replace</span>("~typelink~",<span style="color: #800080;">$row</span>['typelink'],<span style="color: #800080;">$linkOkstr</span><span style="color: #000000;">);
    </span><span style="color: #008080;">10</span>                     <span style="color: #800080;">$linkOkstr</span> = <span style="color: #008080;">str_replace</span>("~typename~",<span style="color: #800080;">$row</span>['typename'],<span style="color: #800080;">$linkOkstr</span><span style="color: #000000;">);
    </span><span style="color: #008080;">11</span>                     <span style="color: #800080;">$likeType</span> .= <span style="color: #800080;">$linkOkstr</span><span style="color: #000000;">;
    </span><span style="color: #008080;">12</span> <span style="color: #000000;">                }
    </span><span style="color: #008080;">13</span>                 <span style="color: #0000ff;">else</span>
    <span style="color: #008080;">14</span> <span style="color: #000000;">                {
    </span><span style="color: #008080;">15</span>                     <span style="color: #0000ff;">print</span> 'test_5'; <span style="color: #008000;">//</span><span style="color: #008000;">测试输出</span>
    <span style="color: #008080;">16</span>                     <span style="color: #800080;">$row</span>['typelink'] = <span style="color: #800080;">$row</span>['typeurl'] = GetOneTypeUrlA(<span style="color: #800080;">$row</span><span style="color: #000000;">);
    </span><span style="color: #008080;">17</span>                     <span style="color: #0000ff;">if</span>(<span style="color: #008080;">is_array</span>(<span style="color: #800080;">$dtp2</span>-><span style="color: #000000;">CTags))
    </span><span style="color: #008080;">18</span> <span style="color: #000000;">                    {
    </span><span style="color: #008080;">19</span>                         <span style="color: #0000ff;">foreach</span>(<span style="color: #800080;">$dtp2</span>->CTags <span style="color: #0000ff;">as</span> <span style="color: #800080;">$tagid</span>=><span style="color: #800080;">$ctag</span><span style="color: #000000;">)
    </span><span style="color: #008080;">20</span> <span style="color: #000000;">                        {
    </span><span style="color: #008080;">21</span>                             <span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$row</span>[<span style="color: #800080;">$ctag</span>->GetName()])) <span style="color: #800080;">$dtp2</span>->Assign(<span style="color: #800080;">$tagid</span>,<span style="color: #800080;">$row</span>[<span style="color: #800080;">$ctag</span>-><span style="color: #000000;">GetName()]);
    </span><span style="color: #008080;">22</span> <span style="color: #000000;">                        }
    </span><span style="color: #008080;">23</span> <span style="color: #000000;">                    }
    </span><span style="color: #008080;">24</span>                     <span style="color: #800080;">$likeType</span> .= <span style="color: #800080;">$dtp2</span>-><span style="color: #000000;">GetResult();
    </span><span style="color: #008080;">25</span>                     
    <span style="color: #008080;">26</span>                 }

     

    看是输出的test_5. 不解. 暂做记录.也希望大家给上上课.

     

    不要单个效果的.已经实现 .或者小弟那里有理解不对的地方. 请指出.

    主要是需要

    11111111111111111

          1-2

          1-3

    22222222222222222
          2-1
          2-2
    如果上面有选择2-1的时候.2-1的样式发生变化 .
     
     

     

    Stellungnahme:
    Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn