【问题标题】:Editing a php scripèt divs to output a table编辑 php 脚本 div 以输出表格
【发布时间】:2014-08-06 13:53:33
【问题描述】:

大家好,我正在为客户每周通讯工作,我正在使用 Joomla 2.5.19 并使用企业版的 acymailing 将其发送出去。由于前景,我现在正在努力,我正在使用 Jreviews 的一个模块,该模块在时事通讯中发布提交给该站点的最新评论,除了 Outlook 之外,它一切正常。

脚本的输出是一个包含 4 条最新评论的 2x2table。唯一的问题是 Outlook 似乎讨厌我使用 Div 作为表格并将 2x2 表格堆叠成一个 verticle kaotic 混乱。

我要编辑的代码是:

'>

<?php /* root element for the items */ ?>
<div class="jrModuleItems <?php echo $orientation . ' jrThumbnail'.ucfirst($tn_position); ?>">

    <?php /* new page starts here */
        $pages = array_chunk($reviews,$limit);
        $j=0;
        foreach($pages AS $page):
        ?>

    <div class="jr-results jrResults jrModuleContainer jrReviewsModule">

        <?php $i=0;
              while(!empty($page)):
                $i++; $j++; $review = array_shift($page); ?>

            <?php
            // Process link title
            $listing_title = ($listing_title_chars && mb_strlen($review['Listing']['title'])>$listing_title_chars) ? $Text->truncate($review['Listing']['title'],$listing_title_chars) : $review['Listing']['title'];
            $review_title = ($review_title_chars && mb_strlen($review['Review']['title'])>$review_title_chars) ? $Text->truncate($review['Review']['title'],$review_title_chars) : $review['Review']['title'];
            $link_title = str_replace('{listing_title}',$listing_title,$link_title_format);
            $link_title = str_replace('{review_title}',$review_title,$link_title);

            // Create the thumbnail
            $tn_show and $mainMediaThumb = $Media->thumb(Sanitize::getVar($review,'MainMedia'),array('listing'=>$review,'size'=>$tn_size,'mode'=>$tn_mode,'css_size'=>true));
            ?>

            <?php $lastItem = ($i == $columns) ? ' jrLastItem' : ''; ?>

            <div class="jrModuleItem<?php echo $lastItem; ?>" style="width: <?php echo $item_width; ?>%; padding-right: <?php echo $item_padding; ?>%;">

                <?php if($show_numbers):?><div class="jrModuleItemNumber"><?php echo $j;?>.</div><?php endif;?>

                <?php if($tn_show && $mainMediaThumb && $tn_position != 'bottom'):?>

                    <!-- Listing Thumbnail -->
                    <div class="jrModuleItemThumbnail">
                        <?php echo $Html->sefLink($mainMediaThumb,$review['Listing']['url']);?>
                        <?php // Uncomment line below to show reviewer avatar. You can comment or remove the thumbnail code above
                            // echo $Community->avatar($review);
                        ?>
                    </div>

                <?php endif;?>

                <div class="jrModuleItemContent">

                    <!-- Listing Title -->
                    <div class="jrModuleItemTitle">

                        <?php echo $Html->sefLink($link_title,$review['Listing']['url']);?>

                        <?php if(Sanitize::getString($review['Listing'],'tag')):?>

                            <span class="jrComponentLabel jrStatusLabel jrBlue">

                                <?php echo Sanitize::getString($review['Listing'],'tag');?>

                            </span>

                        <?php endif;?>

                    </div>

                    <!-- Rating -->
                    <?php if ( $review['Criteria']['state'] == 1 ):?>
                    <div class="jrOverallRatings">
                        <?php if($review['Review']['editor'] == 1):?>
                            <?php
                                $rating_stars = $Rating->drawStars($review['Rating']['average_rating'], $this->Config->rating_scale, 'editor');
                                $rating_value = $Rating->round($review['Rating']['average_rating'],$this->Config->rating_scale);
                            ?>
                            <div class="jrOverallEditor" title="<?php  __t("Editor rating"); ?>">
                                <div class="jrRatingStars"><?php echo $rating_stars ?></div>
                                <span class="jrRatingValue"><?php echo $rating_value?></span>
                            </div>
                        <?php else:?>
                            <?php
                                $rating_stars = $Rating->drawStars($review['Rating']['average_rating'], $this->Config->rating_scale, 'user');
                                $rating_value = $Rating->round($review['Rating']['average_rating'],$this->Config->rating_scale);
                            ?>
                            <div class="jrOverallUser" title="<?php  __t("User rating"); ?>">
                                <div class="jrRatingStars"><?php echo $rating_stars ?></div>
                                <span class="jrRatingValue"><?php echo $rating_value?></span>
                            </div>
                        <?php endif;?>
                    </div>
                    <?php endif;?>

                    <!-- Reviewer name -->
                    <div class="jrModuleItemReviewer">
                        <span class="reviewer"><?php __t("Reviewed by");?> <?php echo $Community->screenName($review);?></span>
                    </div>

                    <?php if($fields): ?>

                    <!-- Custom Fields -->
                    <div class="jrModuleFields">

                        <?php
                            foreach ($fields as $field):
                            $field = trim($field);
                            $field_value = $CustomFields->field($field,$review);
                        ?>
                        <?php if($field_value != ''):?>
                        <div class="jrModuleFieldDiv <?php echo lcfirst(Inflector::camelize($field)); ?>">
                            <span class="jrModuleFieldTitle"><?php echo $CustomFields->label($field, $review); ?>: </span>
                            <span class="jrModuleFieldValue"><?php echo $field_value; ?></span>
                        </div>
                        <?php endif;?>

                        <?php endforeach; ?>

                    </div>

                    <?php endif;?>


                    <?php if($show_comments && trim($review['Review']['comments'])!=''):?>
                    <!-- Review Comments -->
                    <div class="jrModuleItemInfo">
                        <?php
                            // Uncomment line below to show review title
                            // echo '<strong>' . $review['Review']['title'] . '</strong><br />';
                        ?>
                        <span class="comments">"<?php echo $Text->truncateWords($review['Review']['comments'],$comments_words,'...');?>"</span>
                    </div>
                    <?php endif;?>
                </div>

                <?php if($tn_show && $mainMediaThumb && $tn_position == 'bottom'):?>

                    <!-- Listing Thumbnail -->
                    <div class="jrModuleItemThumbnail">
                        <?php echo $Html->sefLink($mainMediaThumb,$review['Listing']['url']);?>
                        <?php // Uncomment line below to show reviewer avatar. You can comment or remove the thumbnail code above
                            // echo $Community->avatar($review);
                        ?>
                    </div>

                <?php endif;?>

            </div>

           <?php  /*end of row , start new row*/
                if(!empty($page) && ($i == $columns || $total == $j)):?>
                <div class="jrDivider"></div>
                <?php $i=0; endif;?>

        <?php endwhile;?>

    </div>

    <?php endforeach; /* new page ends here */?>

</div><?php /* end items root element */?>

有没有人知道我怎么能把它变成一个输出表格的for循环?

【问题讨论】:

  • 可能能够通过输出缓冲和正则表达式破解某些东西以将 div 替换为表格单元格,但我希望您会发现通过上述代码更容易并用表格替换 div
  • 非常感谢您的回答,是的,我一直在编辑 div 试图渲染一个表格,但它现在让我发疯了哈,

标签: php html joomla2.5


【解决方案1】:

从 A 到 B 的最快路径是编辑附加代码以呈现表格而不是堆叠的 div。

* 编辑 *

您的评论的答案并不像将所有“A”替换为“B”那么简单。一个 div 是一个“自包含”的 HTML 元素,而一个 table 是一个有语法规则的分组。

HTML 表格的构造如下:

<table>
    <thead>
        <tr>
            <th>Header 1</th>
            <th>Header 2</th>
        </tr>
    </thead>        
    <tbody>
        <tr>
            <td>Row 1 - Column 1</td>
            <td>Row 1 - Column 2</td>
        </tr>
        <tr>
            <td>Row 2 - Column 1</td>
            <td>Row 2 - Column 2</td>
        </tr>
    </tbody>
</table>

代码中的 foreach 循环应在每次迭代中创建一行。这意味着您需要在此循环代码之外呈现您的表格、thead 和 tbody 标记。在循环内部,每次迭代都会渲染一个新行,这需要行的开始/结束标记和每列的开始/结束。

希望这会有所帮助。

【讨论】:

  • 谢谢,但我是否只需在每个 div 中添加 ?大声笑似乎简单而凌乱,感谢您的时间
猜你喜欢
  • 2014-12-11
  • 2020-03-04
  • 2015-03-05
  • 1970-01-01
  • 1970-01-01
  • 2014-04-28
  • 2023-01-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多