0

このphpコードを変更して、最初のタイトルではなく各タイトルの横に画像を表示しようとしています.

更新コード:

global $cache;

$count_limit = 5;
$title_limit = 30;
$title_limit2 = 48;
$time_limit = 86400;
$forum_ids_arr = array(4,5,7,19,10,11); // separate with commas e.g. 1,2,3

@ini_set('memory_limit', '256M');

if ( !empty($forum_ids_arr) ) {
foreach($forum_ids_arr as $fid) {
    $topic_with_img = array();
    $i = 0;

    while ( empty($topic_with_img) && $i < 20 ) {
        $sql = 'SELECT t.topic_id, t.topic_title, t.topic_poster,    t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_replies, p.post_text, p.bbcode_uid, p.poster_id
                        FROM ' . TOPICS_TABLE . ' t
                  LEFT JOIN ' . POSTS_TABLE . ' p
                              ON t.topic_first_post_id = p.post_id
                    WHERE t.forum_id = ' . $fid . '
                                AND p.bbcode_uid <> ""
                    ORDER BY t.topic_time DESC';

        $result = $db->sql_query_limit($sql, $count_limit, $count_limit*$i, $time_limit);

        while ($row = $db->sql_fetchrow($result)) {
            decode_message($row['post_text'], $row['bbcode_uid']);

            if ( strpos($row['post_text'], '[img]') === FALSE || strpos($row['post_text'], '[/img]') === FALSE ) {
                continue;
            } else {
                $row['post_text'] = " " . $row['post_text'];
              $ini = strpos($row['post_text'], "[img]");
              if ($ini == 0) {
                    $img_url = "";
                }
              $ini += strlen("[img]");
              $len = strpos($row['post_text'], "[/img]", $ini) - $ini;
              $img_url = substr($row['post_text'], $ini, $len);

                $topic_with_img['topic_id'] = $row['topic_id'];
                $topic_with_img['topic_title'] = $row['topic_title'];
                $topic_with_img['img_url'] = $img_url;


                $sql3 = 'SELECT forum_name
                                FROM ' . FORUMS_TABLE . '
                                WHERE forum_id = ' . $fid;
                $db->sql_query($sql3);
                $forum_name = $db->sql_fetchfield('forum_name');

                $topic_author_img       = get_username_string('full', $row['topic_poster'], $row['topic_first_poster_name'], $row['topic_first_poster_colour']);
                $topic_replies_img = ($auth->acl_get('is_registered', $topic_forum_id)) ? strval($row['topic_replies_real']) : strval($row['topic_replies']);
                $comment = (intval($topic_replies) == 1) ? $user->lang['TT_COMMENT'] : $user->lang['TT_COMMENTS'];
                $topic_replies_img .= $comment;

                $template->assign_block_vars('img_top_topic', array(
                    'TITLE'        => (strlen($row['topic_title']) > $title_limit) ? substr($row['topic_title'], 0, $title_limit).'…' : $row['topic_title'],
                    'U_LINK'  => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't='.$row['topic_id']),
                    'IMG'     => $img_url,
                    'FORUM_NAME'  => $forum_name,
                    'FORUM_LINK'  => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f='.$fid),
                    'TOPIC_AUTHOR_IMG'       => $topic_author_img,
                    'TOPIC_REPLIES_IMG'         => $topic_replies_img,
                ));

                $sql5 = 'SELECT t.topic_id, t.topic_title, t.topic_poster, t.topic_first_poster_name, t.topic_first_poster_colour, t.topic_replies, p.post_text, p.bbcode_uid, p.poster_id
                        FROM ' . TOPICS_TABLE . ' t
                  LEFT JOIN ' . POSTS_TABLE . ' p
                              ON t.topic_first_post_id = p.post_id
                    WHERE t.forum_id = ' . $fid . '
                                AND p.bbcode_uid <> ""
                    ORDER BY t.topic_time DESC';
                    $result2 = $db->sql_query_limit($sql5, $count_limit - 1, 1, $time_limit);


                while ($row2 = $db->sql_fetchrow($result2)) {
                    decode_message($row2['post_text'], $row2['bbcode_uid']);

                if ( strpos($row2['post_text'], '[img]') === FALSE || strpos($row2['post_text'], '[/img]') === FALSE ) {
                continue;
                } else {

                    $row2['post_text'] = " " . $row2['post_text'];
              $ini1 = strpos($row2['post_text'], "[img]");
              if ($ini1 == 0) {
                    $img_url1 = "";
                }
              $ini1 += strlen("[img]");
              $len1 = strpos($row2['post_text'], "[/img]", $ini1) - $ini1;
              $img_url1 = substr($row2['post_text'], $ini1, $len1);

                $topic_with_img1['topic_id'] = $row2['topic_id'];
                $topic_with_img1['topic_title'] = $row2['topic_title'];
                $topic_with_img1['img_url'] = $img_url1;


                $sql4 = 'SELECT forum_name
                                FROM ' . FORUMS_TABLE . '
                                WHERE forum_id = ' . $fid;
                $db->sql_query($sql4);
                $forum_name1 = $db->sql_fetchfield('forum_name');

                    $topic_author       = get_username_string('full', $row2['topic_poster'], $row2['topic_first_poster_name'], $row2['topic_first_poster_colour']);
                    $topic_replies = ($auth->acl_get('is_registered', $topic_forum_id)) ? strval($row2['topic_replies_real']) : strval($row2['topic_replies']);
                    $comment = (intval($topic_replies) == 1) ? $user->lang['TT_COMMENT'] : $user->lang['TT_COMMENTS'];
                    $topic_replies .= $comment;

                  $template->assign_block_vars('img_top_topic.last_top_topics', array(
                        'TITLE'        => (strlen($row2['topic_title']) > $title_limit2) ? substr($row2['topic_title'], 0, $title_limit2).'…' : $row2['topic_title'],
                        'TOPIC_AUTHOR'       => $topic_author,
                        'TOPIC_REPLIES'         => $topic_replies,  
                        'U_LINK'  => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't='.$row2['topic_id']),
                        'LAST_IMG'     => $img_url1,
                    ));
                    }
                }
                $db->sql_freeresult($result2);

                break;

            }
        }
        $db->sql_freeresult($result);

        if (empty($topic_with_img)) {
            $cache->destroy('sql');
        }

        $i++;
    }
}
}

希望する結果を得ることができましたが、上記のコードを単純化する方法はありますか? 私がしたことは、コードの上部と下部を複製することだけでした。

このコードの新しい結果は次のとおりです。

http://i1056.photobucket.com/albums/t365/iamthestreets/img_zps5732c7ed.png

このコードの新しい結果は次のとおりです。

http://i1056.photobucket.com/albums/t365/iamthestreets/newimg_zps36fdd004.png

すべてのタイトルの横に画像を表示したい。

私は誰かにコードを書くように頼んでいるわけではありませんが (あなたが望む場合を除きます)、誰かがそれを理解するのを手伝ってくれます. 私はまだPHPに非常に慣れていません。

編集:ここにHTMLがあります

<div class="tt">
<!-- BEGIN img_top_topic -->
<div class="tt_column<!-- IF img_top_topic.S_ROW_COUNT == 0 or     img_top_topic.S_ROW_COUNT == 3 --> one<!-- ELSEIF img_top_topic.S_ROW_COUNT == 1 or img_top_topic.S_ROW_COUNT == 4 --> two<!-- ELSEIF img_top_topic.S_ROW_COUNT == 2 or img_top_topic.S_ROW_COUNT == 5 --> three<!-- ENDIF -->">
    <h3 <!-- IF img_top_topic.S_ROW_COUNT > 2 -->style="margin-top: 20px;"<!-- ENDIF -->><a href="{img_top_topic.FORUM_LINK}">{img_top_topic.FORUM_NAME}</a></h3>


        <ul>
        <div class="imgresize"><a href="{img_top_topic.U_LINK}"><img src="{img_top_topic.IMG}" alt="{img_top_topic.TITLE}" /></a></div>
        <li class="one"><a class="img_title" href="{img_top_topic.U_LINK}">{img_top_topic.TITLE}</a></li>
        <li class="topic_title_span"><span>by {img_top_topic.TOPIC_AUTHOR_IMG} |{img_top_topic.TOPIC_REPLIES_IMG}</span></li>
        </ul>


    <!-- BEGIN last_top_topics -->
        <ul>
        <div class="imgresize"><a href="{last_top_topics.U_LINK}"><img src="{last_top_topics.LAST_IMG}" alt="{last_top_topics.TITLE}" /></a></div>
        <li class="one"><a class="img_title" href="{last_top_topics.U_LINK}">{last_top_topics.TITLE}</a></li>
        <li class="topic_title_span"><span>by {last_top_topics.TOPIC_AUTHOR} |{last_top_topics.TOPIC_REPLIES}</span></li>
        </ul>

    <!-- END last_top_topics -->        

</div>

4

0 に答える 0