Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Hi KK,

how you doing?

Regarding my latest web project:

http://www.magicalquests.com

Remember me asking you about getting the party themes list (at the bottom of the party themes pages and actors pages) to update dynamically whenever the client adds a new cloned party page? You did give a suggestion as to how that could be achieved but the thing is the list is set in two columns, if you have a look at those pages you'll see what I mean, e.g:

list.gif
list.gif (26.93 KiB) Viewed 3927 times


I need that list to update automatically but still remain in the two level (as much as possible) columns, so the new parties wouldn't just be added to the one column each time, since that would result in that one column being considerably longer than the other.

Is this possible?

Thanks mate :D

Regards,

Marc
Hi Marc,

Following is HTML markup you are using to display the pages list in two columns (with each showing half the total number of pages).
Code: Select all
<div class="row begin-quest">
    <div class="w-2col m-1col themes">
        <ul>
            <li><a href="fairy-pixie-parties.html">Fairy Pixie Parties &amp; more</a></li>
            <li><a href="underwater-adventure-parties.html">Underwater Adventure Parties</a></li>
            <li><a href="dragons-knights-adventure-parties.html">Dragon Parties &amp; Other Knightly Adventures</a></li>
            <li><a href="superhero-parties.html">Superhero Parties</a></li>
            <li><a href="harry-potter-halloween-parties.html">Halloween Parties/Harry Potter Parties &amp; More</a></li>
            <li><a href="star-wars-space-parties.html">Star Wars Parties, Intergalactic Quests &amp; Missions</a></li>
            <li><a href="detective-mystery-parties.html">Detective Mystery Parties</a></li>
        </ul>
    </div>
   
    <div class="w-2col m-1col w-last themes-2">
        <ul>
            <li><a href="fairy-tale-princess-parties.html">Fairy Tale Princess Parties</a></li>
            <li><a href="musical-parties.html">Musical Parties</a></li>
            <li><a href="dance-parties.html">Dance Parties</a></li>
            <li><a href="christmas-seasonal-parties.html">Christmas Parties &amp; other seasonal fun</a></li>
            <li><a href="party-ideas-for-adults.html">Party ideas for adults</a></li>
            <li><a href="weddings-bespoke-events-parties.html">Weddings, Bar Mitzvahs and any bespoke event</a></li>
            <li><a href="shows-for-shools-workshops.html">Shows for schools and drama workshops</a></li>
        </ul>
    </div>
</div>

The solution to this problem would be to
1. Find the total number of pages available for listing (can use cms:pages with 'count_only' parameter)
2. Divide the total by two to find the number to display in a single column
3. In the left column - use cms:pages with the 'limit' parameter to show the number of pages calculated
4. In the right column - use cms:pages with the 'offset' parameter to skip the number of pages calculated and display only the remaining.

Of the four steps, only the 2nd is a little tricky because we cannot simply divide the total by two. If the result is a fraction (e.g. 7.5) we'll also have to round the result to the next higher number (8 in our example). To do this we'll make use of a little PHP.
Rest of the steps are straightforward.

Following is the complete code you can use (please make sure to specify your template name on the very first line of the code)-
Code: Select all
<cms:set template_to_list='themes.php' />

<cms:set total_rows="<cms:pages masterpage=template_to_list count_only='1' />" />
<cms:php>
    global $CTX;
    $total_rows = (int)"<cms:show total_rows />";
    if( $total_rows ){
        $rows_left = ceil( $total_rows/2 );
        $rows_right = $total_rows - $rows_left;
    }
    $CTX->set( 'rows_left', $rows_left, 'global' );
    $CTX->set( 'rows_right', $rows_right, 'global' );
</cms:php>

<div class="row begin-quest">
    <div class="w-2col m-1col themes">
    <cms:if rows_left >
        <ul>
        <cms:pages masterpage=template_to_list limit=rows_left >
            <li><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></li>
        </cms:pages>
        </ul>
    </div>
    </cms:if>
   
    <cms:if rows_right >
    <div class="w-2col m-1col w-last themes-2">
        <ul>
        <cms:pages masterpage=template_to_list offset=rows_left >
            <li><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></li>
        </cms:pages>
        </ul>
    </div>
    </cms:if>
</div>

Hope this helps.
Hi KK,

I've tried your suggestion. Here's what I now have at the top of the page:

Code: Select all
<?php require_once( '../cms/cms.php' ); ?>

<cms:template title='Party Themes' clonable='1'>
<cms:set template_to_list='index.php' />
<cms:set total_rows="<cms:pages masterpage=template_to_list count_only='1' />" />
<cms:php>
    global $CTX;
    $total_rows = (int)"<cms:show total_rows />";
    if( $total_rows ){
        $rows_left = ceil( $total_rows/2 );
        $rows_right = $total_rows - $rows_left;
    }
    $CTX->set( 'rows_left', $rows_left, 'global' );
    $CTX->set( 'rows_right', $rows_right, 'global' );
</cms:php>


And here at the point where the lists should appear:

Code: Select all
<div class="row begin-quest">
    <div class="w-2col m-1col themes">
    <cms:if rows_left >
        <ul>
        <cms:pages masterpage=template_to_list limit=rows_left >
            <li><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></li>
        </cms:pages>
        </ul>
    </div>
    </cms:if>
   
    <cms:if rows_right >
    <div class="w-2col m-1col w-last themes-2">
        <ul>
        <cms:pages masterpage=template_to_list offset=rows_left >
            <li><a href="<cms:show k_page_link />"><cms:show k_page_title /></a></li>
        </cms:pages>
        </ul>
    </div>
    </cms:if>
</div>


I've done all the usual steps, i.e.:

1. Deleting the old file from the server
2. Refreshing it in the browser to clear it out
3. Deleting the template from the admin panel (as superadmin)
4. Uploaded the edited version to the server
5. Refreshed it in the browser
6. Refreshed the admin panel so that it appears again.

I then added a new party as can be seen in screenshot 1, I then refreshed the edited page (drama-party-themes/index.php) to see if the new party theme appeared in the list since this is what we are trying to do here, but, as you can see from screenshot 1, it does not. There's just a bullet point with no party listed item.

Am I doing something wrong here? Please let me know.

Thanks.

Regards

Marc :D

Attachments

Hi Marc,

It seems you are not using the correct template name.
I think it is 'drama-party-themes/index.php' instead of 'index.php' that you have used in your code.
Please make it -
<cms:set template_to_list='drama-party-themes/index.php' />

If in doubt about a template's name, hover on its entry in the left sidebar of admin-panel and it'll show you its name in the tooltip.
Thanks for that KK,

I did what you suggested and it works!! :D

I've just run a test for now with dummy party theme pages (see screenshot attached) but as you can see it definitely works. The only problem at the moment is, as you can also see, the first party theme it picks up is the default template name i.e.:

Default page for drama-party-themes/index.php * PLEASE CHANGE THIS TITLE *

Clearly I don't want this displayed so can you please tell me what needs to be done to eliminate this?

Thanks so much for all your help. You;re a star!

Regards,

Marc :D
I am glad it worked :)
To hide the page you mentioned, please edit it and set its status to 'unpublished' (from the "Advanced setting' dropdown).
6 posts Page 1 of 1
cron