Topic: How can use hook in_forum_loop_start ?

Hello,

Sorry for my English pitiful! (Thanks Google)

But I try to use that hook to add a feature at the top of each category on the main page and I faced a strange result.

So I have been testing directly in the source code, and I am more and more perplexed.       

Test beginning at line 109 in index.php

while ($cur_forum = $db->fetch_assoc($result))
{
    ($hook = get_hook('in_forum_loop_start')) ? eval($hook) : null;
    echo '<p>test 1</p>';

    $pun_page['item_mods'] = '';
    ++$pun_page['item_count'];
    echo '<p>test 2</p>';
    if ($cur_forum['cid'] != $pun_page['cur_category'])    // A new category since last iteration?
    {
    echo '<p>test 3</p>';
        if ($pun_page['cur_category'] != 0)
        {

?>
            </tbody>
        </table>
    </div>
<?php

        }
    echo '<p>test 4</p>';

And the result in html source code.

    <h1><span>Dev Beta</span></h1>
<p>test 1</p><p>test 2</p><p>test 3</p><p>test 4</p>    <div class="main-head">
        <h2><span>truc</span></h2>

    </div>

    <div id="category1" class="main-content category">
        <table cellspacing="0" summary="Listing of forums in the category truc.">
            <thead>
                <tr>
                    <th class="tcl" scope="col">Forum</th>
                    <th class="tc2" scope="col">Topics</th>

                    <th class="tc3" scope="col">Posts</th>
                    <th class="tcr" scope="col">Last post</th>
                </tr>
            </thead>
            <tbody class="statused">
                <tr id="forum3" class="odd normal">
                    <td class="tcl"><span class="status normal" title="Forum"><img src="http://localhost/punbb13/style/Oxygen/status.png" alt="Forum" /></span> <h3><a href="http://localhost/punbb13/viewforum.php?id=3"><span>test</span></a></h3></td>

                    <td class="tc2">0</td>
                    <td class="tc3">0</td>
                    <td class="tcr">Never</td>
                </tr>
<p>test 1</p><p>test 2</p><p>test 3</p>            </tbody>
        </table>

    </div>
<p>test 4</p>    <div class="main-head">
        <h2><span>tyu</span></h2>
    </div>

    <div id="category2" class="main-content category">
        <table cellspacing="0" summary="Listing of forums in the category tyu.">
            <thead>

                <tr>
                    <th class="tcl" scope="col">Forum</th>
                    <th class="tc2" scope="col">Topics</th>
                    <th class="tc3" scope="col">Posts</th>
                    <th class="tcr" scope="col">Last post</th>
                </tr>
            </thead>

            <tbody class="statused">
                <tr id="forum4" class="odd normal">
                    <td class="tcl"><span class="status normal" title="Forum"><img src="http://localhost/punbb13/style/Oxygen/status.png" alt="Forum" /></span> <h3><a href="http://localhost/punbb13/viewforum.php?id=4"><span>azerty</span></a></h3></td>
                    <td class="tc2">0</td>
                    <td class="tc3">0</td>
                    <td class="tcr">Never</td>

                </tr>
            </tbody>
        </table>
    </div>

What do you think? I missed a step?

Thx.

Re: How can use hook in_forum_loop_start ?

I'm not seeing anything wrong. You'll have to be more specific.

3 (edited by mangafan 2008-02-04 02:25)

Re: How can use hook in_forum_loop_start ?

In fact if I want to make sure to display information just before the <h2> of each category through the hook.

I can't. And even reading the source code several times I do not understand why paragraphs "test 1", "test 2", and "test 3" displayed above and below the first <h2>.

While "test 4" appears well above the first and second category.

H1 Forum Name

P test 1
P test 2
P test 3
P test 4

H2 Category 1

P test 1
P test 2
P test 3

Forum     Topics     Posts     Last post
Forum 1 0     0     Never

P test 4

H2 Category 2

Forum     Topics     Posts     Last post
Forum 1    0     0     Never

Re: How can use hook in_forum_loop_start ?

There isn't a hook to output stuff right before

    <div class="main-head">
        <h2><span><?php echo htmlspecialchars($cur_forum['cat_name']) ?></span></h2>
    </div>

which is I assume what you're trying to do.
The stuff you directly edited in to the code is doing exactly what it's supposed to do if you follow how the code works. #1, 2, and 3 are before the block starting with

if ($pun_page['cur_category'] != 0)

so they output before that block outputs. #4 is correctly placed for what you want to do, since it's after that block.
If you think a hook there would be something useful and beneficial to a large number of people, you should request it in the hook request sticky.

Re: How can use hook in_forum_loop_start ?

It was to display image with a id to use it for a collapse.

Because all h2 tag has a unique class and is not practical with javascript.

But I still understand why the condition allows the display of "test 4" since it is closed before the echo.

This is the effect of the output buffering?

Re: How can use hook in_forum_loop_start ?

I assume you mean you don't understand why test 4 happened where it did wink
It has nothing to do without output buffering and everything to do with where you put the code. You put the code inside of

if ($cur_forum['cid'] != $pun_page['cur_category'])

but after

if ($pun_page['cur_category'] != 0)

which shares the if statement.

Re: How can use hook in_forum_loop_start ?

I just understand ... I saw the loop too simple. I have an early idea which should work.

Thank you. I will still read the code a dozen times. It's going to come!