External pages

All web design discussion, including Ultimate Quiz MOD support.

Moderator: CricketMX Forum Moderators

External pages

Postby Scribbles » Tue Nov 24, 2009 2:12 pm

Hi there, I stumbled across this very useful guide whilst designing a website. I've implemented example 2(Original article), and it works, fantastic.

It's not however doing quite what I'd like it to, but what I'd like it to do is more a cross of example 3 and 2. On the website I'm designing, I have a "featured" block, followed by 4 "recent articles"

I was wondering if there was a way of displaying an 'announcement' (The top most topic) in the featured block, and then the rest of the 'news' forum in the recent article's block. The way I've got it split at the moment is basically, in the template file:

Code: Select all
<!--Featured Block-->
<!-- BEGIN announcements(0,0) -->
Title: {announcements.TOPIC_TITLE}<br />
Post author: {announcements.POST_AUTHOR}<br />
Post date: {announcements.POST_DATE}<br />
Last post text: {announcements.POST_TEXT}<br />
Post link: {announcements.POST_LINK}
<!-- END announcements -->

<!--Recent articles block-->
<!-- BEGIN announcements(1,4) -->
Title: {announcements.TOPIC_TITLE}<br />
Post author: {announcements.POST_AUTHOR}<br />
Post date: {announcements.POST_DATE}<br />
Last post text: {announcements.POST_TEXT}<br />
Post link: {announcements.POST_LINK}
<!-- END announcements -->


The loop specification probably isnt the best way to do it, but eh, it works.

I'm fairly inept when it comes down to writing php, but I have/do program, so if you explain something, I'll probably get it.
Scribbles
Greenhorn
Greenhorn
 
Posts: 2
Joined: Tue Nov 24, 2009 1:54 pm

Re: External pages

Postby Scribbles » Sat Dec 05, 2009 7:10 am

Poke?
Scribbles
Greenhorn
Greenhorn
 
Posts: 2
Joined: Tue Nov 24, 2009 1:54 pm

Re: External pages

Postby moongirl » Mon Dec 14, 2009 4:06 am

Welcome to CMX Scribbles :)

The answer you need is with Battye...who I am sure will be with us soon.
Image
That's not the man in the moon...that's me ;)
Click To Play Online-Scrabble - Click To Play Quizzes
~~~In the year 2040...I'll have 100,000 posts!!~~~
User avatar
moongirl
Moderator
Moderator
 
Posts: 18744
Joined: Mon Jan 12, 2004 8:07 am

Re: External pages

Postby battye » Mon Dec 14, 2009 5:30 am

Hi, sorry for the delay in replying :)
I appreciate your patience.

I take it all of the topics are in the same forum? Say the "news" forum. And the most recent topic is to be the featured topic and the four topics thereafter are to just be shown regularly.

I think the best way to do it would be to just use an IF/ELSE inside the templating code, so something like this:

Code: Select all
$posts_ary = array(
        'SELECT'    => 'p.*, t.*, u.username, u.user_colour',
   
        'FROM'      => array(
            POSTS_TABLE     => 'p',
        ),
   
        'LEFT_JOIN' => array(
            array(
                'FROM'  => array(USERS_TABLE => 'u'),
                'ON'    => 'u.user_id = p.poster_id'
            ),
            array(
                'FROM'  => array(TOPICS_TABLE => 't'),
                'ON'    => 'p.topic_id = t.topic_id'
            ),
        ),
   
        'WHERE'     => $db->sql_in_set('t.forum_id', array_keys($auth->acl_getf('f_read', true))) . '
                        AND t.topic_status <> ' . ITEM_MOVED . '
                         AND t.topic_approved = 1',
   
        'ORDER_BY'  => 'p.post_id DESC',
    );
   
   $posts = $db->sql_build_query('SELECT', $posts_ary);

   $posts_result = $db->sql_query_limit($posts, $search_limit);

      while( $posts_row = $db->sql_fetchrow($posts_result) )
      {
         $is_featured = false;

         if( $i == 0 )
         {
            $is_featured = true;
            $i++;
         }

         $topic_title       = $posts_row['topic_title'];
         $post_author       = get_username_string('full', $posts_row['poster_id'], $posts_row['username'], $posts_row['user_colour']);
         $post_date          = $user->format_date($posts_row['post_time']);
         $post_link       = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "p=" . $posts_row['post_id'] . "#p" . $posts_row['post_id']);

         $post_text = nl2br($posts_row['post_text']);

         $bbcode = new bbcode(base64_encode($bbcode_bitfield));         
         $bbcode->bbcode_second_pass($post_text, $posts_row['bbcode_uid'], $posts_row['bbcode_bitfield']);

         $post_text = smiley_text($post_text);

         $template->assign_block_vars('announcements', array(
         'IS_FEATURED'              => $is_featured,
         'TOPIC_TITLE'       => censor_text($topic_title),
         'POST_AUTHOR'       => $post_author,
         'POST_DATE'       => $post_date,
         'POST_LINK'       => $post_link,
         'POST_TEXT'         => censor_text($post_text),
         ));
      }


What I've done there is just added a counter to make sure only the first topic is classed as featured, and can be checked using the {announcements.IS_FEATURED} template variable.

So in the template code you would have something like:

Code: Select all
<!-- BEGIN announcements -->
     <!-- IF announcements.IS_FEATURED -->
     Featured_Title: {announcements.TOPIC_TITLE}<br />
     Featured_Post author: {announcements.POST_AUTHOR}<br />
     Featured_Post date: {announcements.POST_DATE}<br />
     Featured_Last post text: {announcements.POST_TEXT}<br />
     Featured_Post link: {announcements.POST_LINK}
     <!-- ELSE -->
     Title: {announcements.TOPIC_TITLE}<br />
     Post author: {announcements.POST_AUTHOR}<br />
     Post date: {announcements.POST_DATE}<br />
     Last post text: {announcements.POST_TEXT}<br />
     Post link: {announcements.POST_LINK}
     <!-- ENDIF -->
<!-- END announcements -->


Inside the if/else statements you can put the styling you want for the respective topics.

Sorry again for the delay in replying, if you have any more questions please let me know :)
CricketMX.com.. home of bat's, rat's and other farmyard animals...
My articles: view all articles by battye

"OK, life [as you chose to define it] repeats until there are no more lessons to be learned." - nrnoble (June 12, 2005)
"the new forum looks awesome, it's getting bigger & better" - p2p-sharing-rules (11 Jan, 2008)
"Looks like CMX is not only getting bigger...but, also getting better!!" - moongirl (14 Dec, 2007)
User avatar
battye
Site Admin
Site Admin
 
Posts: 14249
Joined: Sun Jan 11, 2004 8:26 am
Location: Victoria Falls, Zimbabwe


Return to Web Design

Who is online

Users browsing this forum: No registered users and 1 guest

cron