简体   繁体   English

joomla / k2 php模板覆盖

[英]joomla/k2 php template overrides

Really need some help after many hours of banging head against a brick wall! 经过几个小时撞击砖墙后真的需要一些帮助!

Basically I have a Joomla News page made in the K2 component. 基本上我有一个在K2组件中制作的Joomla新闻页面。 The page would have the top story, the next two, then the next four and the next four after that all with their own class so they can be styled differently for emphasis (like most news websites). 该页面将有顶级故事,接下来的两个,然后是接下来的四个,接下来的四个都有他们自己的类,所以他们的样式可以不同的重点(像大多数新闻网站)。

So there would be one row of one column - main news (with items image and text cut off after about 150 words with a 'read more') second row - two columns - next two news pieces (with items image and text cut off after about 150 words with a 'read more') third row - four columns - next four news pieces (with items image and text cut off after about 150 words with a 'read more') fourth row - one column of eight links (no image just the title linked) 因此,将有一行一列 - 主要新闻(项目图像和文本在大约150个单词之后切断,并且'阅读更多')第二行 - 两列 - 接下来两个新闻片段(项目图像和文本被切断后大约150个单词带有'阅读更多')第三行 - 四列 - 接下来的四个新闻片(项目图片和文字在大约150个单词后被删除,带有'更多')第四行 - 一列八个链接(没有图像只是标题链接)

This is the file I'm trying to amend: 这是我要修改的文件:

    <?php


// no direct access

defined('_JEXEC') or die;

$selectedFilters=$params->get('extraFieldsSelect'); //get selected fields in module params



?>

<div id="k2ModuleBox<?php echo $module->id; ?> k2FiltrifyContainer" class="k2Filtrify k2ItemsBlock<?php if($params->get('moduleclass_sfx')) echo ' '.$params->get('moduleclass_sfx'); ?>">

    <?php if($params->get('itemPreText')): ?>

    <p class="modulePretext"><?php echo $params->get('itemPreText'); ?></p>

    <?php endif; ?>



    <!--Filtrify Placeholder-->

    <div id="k2FiltrifyPlaceHolder"></div>



    <?php //set placeholder, if LEGEND is the selected callback method

    if($placeholder == 'legend'): ?>

        <!--Filtrify legend placeholder-->

        <div id="legend"><i><?php echo JText::_('K2_VIEWING_ALL'); ?></i></div>

    <?php endif; ?>



    <?php  //set placeholder, if PAGINATION is the selected callback method

    if($placeholder == 'pagination'): ?>

        <!--Filtrify pagination placeholder-->

        <div id="pagination"></div>

    <?php endif; ?>



    <?php if(count($items)): //Filtrify Container?>

      <ul id="k2FiltrifyContainer">

        <p>
          <?php foreach ($items as $keyItem=>$item):    ?>



            <?php

                // Define a CSS class for the last container on each row

                if( (($keyItem+1)%($params->get('num_columns'))==0) || count($items)<$params->get('num_columns') )

                    $lastContainer= ' itemContainerLast';

                else

                    $lastContainer='';

                ?>

          <li class="itemContainer<?php echo $lastContainer; ?>" <?php echo (count($items)==1) ? '' : ' style="width:'.number_format(100/$params->get('num_columns'), 1).'%;"'; ?>





          <?php 



          if( count($item->extra_fields) && $selectedFilters != ''): //check if there are extrafields and selected fields?>

                <?php foreach ($item->extra_fields as $key=>$extraField): //adding extrafields as data parameter?>

                    <?php if(in_array($extraField->id,(array)$selectedFilters, TRUE)) : ?>

                             data-<?php echo preg_replace("/[^A-Za-zA-yA-y0-9а-яА-Яa-zA-Z?-??-?sctzlldSCTZLD]/ui", "_", $extraField->name); ?>="<?php echo $extraField->value; //set the values, and remove special chars?>"

                    <?php endif; ?>

                <?php endforeach; ?>

            <?php endif; ?>





          <?php if($params->get('showCatFilter')==1): //check for param - show category filter?>

                data-<?php echo preg_replace("/[^A-Za-zA-yA-y0-9а-яА-Яá-źÁ-ŹΑ-Ωα-ωščťžľĺďŠČŤŽĹĎ]/ui", "_", JText::_('K2_CATEGORIES')); ?>="<?php echo $item->categoryname;?>"





            <?php endif; ?>



            <?php if($params->get('showTagFilter')==1): //check for param - show tag filter?>

                data-<?php echo preg_replace("/[^A-Za-zA-yA-y0-9а-яА-Яá-źÁ-ŹΑ-Ωα-ωščťžľĺďŠČŤŽĹĎ]/ui", "_", JText::_('K2_TAGS')); ?>="<?php foreach ($item->tags as $tag): ?><?php echo $tag->name; ?>, <?php endforeach; ?>"

            <?php endif; ?>



        >
        </p>
        <p>
          <?php if(isset($item->event->BeforeDisplay)): ?>

          <!-- Plugins: BeforeDisplay -->

          <?php echo $item->event->BeforeDisplay; ?>

          <?php endif; ?>





          <!-- K2 Plugins: K2BeforeDisplay -->

          <?php echo $item->event->K2BeforeDisplay; ?>



          <?php if($params->get('itemAuthorAvatar')): ?>

          <a class="k2Avatar moduleItemAuthorAvatar" rel="author" href="<?php echo $item->authorLink; ?>">

            <img src="<?php echo $item->authorAvatar; ?>" alt="<?php echo K2HelperUtilities::cleanHtml($item->author); ?>" style="width:<?php echo $avatarWidth; ?>px;height:auto;" />

          </a>

          <?php endif; ?>



          <?php if($params->get('itemTitle')): ?>

          <a class="moduleItemTitle" href="<?php echo $item->link; ?>"><?php echo $item->title; ?></a>

          <?php endif; ?>



          <?php if($params->get('itemAuthor')): ?>

        </p>
          <div class="moduleItemAuthor">

              <?php echo K2HelperUtilities::writtenBy($item->authorGender); ?>



                    <?php if(isset($item->authorLink)): ?>

                    <a rel="author" title="<?php echo K2HelperUtilities::cleanHtml($item->author); ?>" href="<?php echo $item->authorLink; ?>"><?php echo $item->author; ?></a>

                    <?php else: ?>

                    <?php echo $item->author; ?>

                    <?php endif; ?>



                    <?php if($params->get('userDescription')): ?>

                    <?php echo $item->authorDescription; ?>

                    <?php endif; ?>



                </div>

                <?php endif; ?>





            <?php if(isset($item->event->AfterDisplayTitle)): ?>

                 <!-- Plugins: AfterDisplayTitle -->

                 <?php echo $item->event->AfterDisplayTitle; ?>

            <?php endif; ?>



          <!-- K2 Plugins: K2AfterDisplayTitle -->

          <?php echo $item->event->K2AfterDisplayTitle; ?>





            <?php if(isset($item->event->BeforeDisplayContent)): ?>

              <!-- Plugins: BeforeDisplayContent -->

                <?php echo $item->event->BeforeDisplayContent; ?>

            <?php endif; ?>



          <!-- K2 Plugins: K2BeforeDisplayContent -->

          <?php echo $item->event->K2BeforeDisplayContent; ?>



          <?php if($params->get('itemImage') || $params->get('itemIntroText')): ?>

          <div class="moduleItemIntrotext">

              <?php if($params->get('itemImage') && isset($item->image)): ?>

              <a class="moduleItemImage" href="<?php echo $item->link; ?>" title="<?php echo JText::_('K2_CONTINUE_READING'); ?> &quot;<?php echo K2HelperUtilities::cleanHtml($item->title); ?>&quot;">

                <img src="<?php echo $item->image; ?>" alt="<?php echo K2HelperUtilities::cleanHtml($item->title); ?>"/>

              </a>

              <?php endif; ?>



            <?php if($params->get('itemIntroText')): ?>

            <?php echo $item->introtext; ?>

            <?php endif; ?>

          </div>

          <?php endif; ?>

          <div class="clr"></div>



          <?php if($params->get('itemExtraFields') && count($item->extra_fields)): ?>

          <div class="moduleItemExtraFields">

              <b><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></b>

              <ul>

                <?php foreach ($item->extra_fields as $extraField): ?>

                        <?php if($extraField->value): ?>

                        <li class="type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">

                            <span class="moduleItemExtraFieldsLabel"><?php echo $extraField->name; ?></span>

                            <span class="moduleItemExtraFieldsValue"><?php echo $extraField->value; ?></span>

                            <div class="clr"></div>

                        </li>

                        <?php endif; ?>

                <?php endforeach; ?>

              </ul>

          </div>

          <?php endif; ?>



          <div class="clr"></div>



          <?php if($params->get('itemVideo')): ?>

          <div class="moduleItemVideo">

            <?php echo $item->video ; ?>

            <span class="moduleItemVideoCaption"><?php echo $item->video_caption ; ?></span>

            <span class="moduleItemVideoCredits"><?php echo $item->video_credits ; ?></span>

          </div>

          <?php endif; ?>



          <div class="clr"></div>





            <?php if(isset($item->event->AfterDisplayContent)): ?>

                  <!-- Plugins: AfterDisplayContent -->

                  <?php echo $item->event->AfterDisplayContent; ?>

            <?php endif; ?>



          <!-- K2 Plugins: K2AfterDisplayContent -->

          <?php echo $item->event->K2AfterDisplayContent; ?>



          <?php if($params->get('itemDateCreated')): ?>

          <span class="moduleItemDateCreated"><?php echo JText::_('K2_WRITTEN_ON') ; ?> <?php echo JHTML::_('date', $item->created, JText::_('K2_DATE_FORMAT_LC2')); ?></span>

          <?php endif; ?>



          <?php if($params->get('itemCategory')): ?>

          <?php echo JText::_('K2_IN') ; ?> <a class="moduleItemCategory" href="<?php echo $item->categoryLink; ?>"><?php echo $item->categoryname; ?></a>

          <?php endif; ?>



          <?php if($params->get('itemTags') && count($item->tags)>0): ?>

          <div class="moduleItemTags">

            <b><?php echo JText::_('K2_TAGS'); ?>:</b>

            <?php foreach ($item->tags as $tag): ?>

            <a href="<?php echo $tag->link; ?>"><?php echo $tag->name; ?></a>

            <?php endforeach; ?>

          </div>

          <?php endif; ?>



          <?php if($params->get('itemAttachments') && count($item->attachments)): ?>

                <div class="moduleAttachments">

                    <?php foreach ($item->attachments as $attachment): ?>

                    <a title="<?php echo K2HelperUtilities::cleanHtml($attachment->titleAttribute); ?>" href="<?php echo $attachment->link; ?>"><?php echo $attachment->title; ?></a>

                    <?php endforeach; ?>

                </div>

          <?php endif; ?>



                <?php if($params->get('itemCommentsCounter') && $componentParams->get('comments')): ?>      

                    <?php if(!empty($item->event->K2CommentsCounter)): ?>

                        <!-- K2 Plugins: K2CommentsCounter -->

                        <?php echo $item->event->K2CommentsCounter; ?>

                    <?php else: ?>

                        <?php if($item->numOfComments>0): ?>

                        <a class="moduleItemComments" href="<?php echo $item->link.'#itemCommentsAnchor'; ?>">

                            <?php echo $item->numOfComments; ?> <?php if($item->numOfComments>1) echo JText::_('K2_COMMENTS'); else echo JText::_('K2_COMMENT'); ?>

                        </a>

                        <?php else: ?>

                        <a class="moduleItemComments" href="<?php echo $item->link.'#itemCommentsAnchor'; ?>">

                            <?php echo JText::_('K2_BE_THE_FIRST_TO_COMMENT'); ?>

                        </a>

                        <?php endif; ?>

                    <?php endif; ?>

                <?php endif; ?>



                <?php if($params->get('itemHits')): ?>

                <span class="moduleItemHits">

                    <?php echo JText::_('K2_READ'); ?> <?php echo $item->hits; ?> <?php echo JText::_('K2_TIMES'); ?>

                </span>

                <?php endif; ?>



                <?php if($params->get('itemReadMore') && $item->fulltext): ?>

                <a class="moduleItemReadMore" href="<?php echo $item->link; ?>">

                    <?php echo JText::_('K2_READ_MORE'); ?>

                </a>

                <?php endif; ?>



            <?php if(isset($item->event->AfterDisplay)): ?>

                 <!-- Plugins: AfterDisplayContent -->

                 <?php echo $item->event->AfterDisplay; ?>

            <?php endif; ?>



          <!-- K2 Plugins: K2AfterDisplay -->

          <?php echo $item->event->K2AfterDisplay; ?>

          <div class="clr"></div>

        </li>



        <?php if((($keyItem+1)%($params->get('num_columns'))==0) && (($placeholder != 'pagination'))) : ?>

        <div class="clr"></div>

        <?php endif; ?>





        <?php endforeach; ?>



        <li class="clearList"></li>

      </ul>

  <?php endif; ?>



    <?php if($params->get('itemCustomLink')): ?>

    <a class="moduleCustomLink" href="<?php echo $params->get('itemCustomLinkURL'); ?>" title="<?php echo K2HelperUtilities::cleanHtml($itemCustomLinkTitle); ?>"><?php echo $itemCustomLinkTitle; ?></a>

    <?php endif; ?>



    <?php if($params->get('feed')): ?>

    <div class="k2FeedIcon">

        <a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&format=feed&moduleID='.$module->id); ?>" title="<?php echo JText::_('K2_SUBSCRIBE_TO_THIS_RSS_FEED'); ?>">

            <span><?php echo JText::_('K2_SUBSCRIBE_TO_THIS_RSS_FEED'); ?></span>

        </a>

        <div class="clr"></div>

    </div>

    <?php endif; ?>



</div>

Like I say, I've tried and tried to make this template work, but have got nowhere! 就像我说的那样,我试过让这个模板起作用,但是无处可去!

You try it with wrong file! 你用错误的文件尝试它! This file belongs to Filtrify Module! 此文件属于Filtrify Module!

You must: 你必须:

  1. set as template for category "default" 设置为“默认”类别的模板
  2. edit K2 native category settings, 编辑K2原生类别设置,
  3. edit K2 native category item settings, 编辑K2原生类别项目设置,
  4. edit K2 native item settings, 编辑K2原生项目设置,

After you set all native K2 parameters, you must clone your default k2 template. 设置所有本机K2参数后,必须克隆默认的k2模板。 Do it so: 这样做:

  • go into components/com_k2/templates. 进入components / com_k2 / templates。
  • Copy all, what you see, locally. 在本地复制所有,你看到的内容。
  • Then create in you templates/your-template/html folder named com_k2. 然后在您的templates / your-template / html文件夹中创建名为com_k2的文件夹。
  • Copy into it all, what you got befor from components/com_k2/templates. 复制到所有内容,您从components / com_k2 / templates获得的内容。
  • Then duplicate folder named "default" and give them own name. 然后复制名为“default”的文件夹并为它们指定自己的名称。 This will be your K2 template for overrides. 这将是您的K2模板以进行覆盖。

Then go into K2 administration and change template of you category, which you set up befor, from default to the new name. 然后进入K2管理并将您设置的类别模板从默认更改为新名称。 Just now you can begin with template overrides, but ONLY inside of templates/your template/html/com_k2/your-k2-template. 刚才你可以从模板覆盖开始,但只能在模板/你的模板/ html / com_k2 / your-k2-template中。 The files you need to override are category-item.php for category view and item.php for single item view. 您需要覆盖的文件是类别视图的category-item.php和单项视图的item.php。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM