Faffing about with loop counters is quite unpleasant and inelegant... these are the kind of problems you run into when your data-fetching is tightly coupled to your data-output. Instead put Stash to work. Here's how:

{!--  ============================================
STORE THE DATA into dynamic stash lists using context.
Avoid the temptation to put any markup here.
================================================== --}

{exp:channel:entries ...}   
    {related}
        {exp:stash:append_list name="related-items" context="{related:panel_type}"}
            {stash:the-title}{related:title}{/stash:the-title}
            {stash:a-custom-field}{related:a-custom-field}{/stash:a-custom-field}
        {/exp:stash:append_list}
    {/related}
{/exp:channel:entries}


{!--  ============================================
ASSEMBLE THE MARKUP and OUTPUT THE DATA
================================================== --}

{exp:stash:parse process="end"}     

    {if {exp:stash:not_empty name="related-items" context="products"}}
        &lt;h2&gt;Related Products&lt;/h2&gt;
        &lt;ul class="p"&gt;
           {exp:stash:get_list name="related-items" context="products"}
             &lt;li&gt;{the-title} | {a-custom-field}&lt;/li&gt;
           {/exp:stash:get_list}
        &lt;/ul&gt;
    {/if}

    {if {exp:stash:not_empty name="related-items" context="showcase"}}
        &lt;h2&gt;Related Showcase&lt;/h2&gt;
        &lt;ul class="s"&gt;
           {exp:stash:get_list name="related-items" context="showcase"}
             &lt;li&gt;{the-title} | {a-custom-field}&lt;/li&gt;
           {/exp:stash:get_list}
        &lt;/ul&gt;
    {/if}

{/exp:stash:parse}


If you were using a separate view template for your layout you wouldn't need the final stash:parse tag, but if you're setting and getting in the same template it helps to avoid parse order issues. (Full explanation and tutorials here: http://www.jamessmith.co.uk/articles/expressionengine-stash-tutorials)

Relationship field - {count} of type, and {total_results} of type
I'm developing a web application in Yii, now the client wants to integrate WordPress in it so he can manage contents on his own.

So how can I integrate WordPress in Yii?
