Page 1 of 1

External pages

PostPosted: Tue Nov 24, 2009 2:12 pm
by Scribbles
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.

Re: External pages

PostPosted: Sat Dec 05, 2009 7:10 am
by Scribbles
Poke?

Re: External pages

PostPosted: Mon Dec 14, 2009 4:06 am
by moongirl
Welcome to CMX Scribbles :)

The answer you need is with Battye...who I am sure will be with us soon.

Re: External pages

PostPosted: Mon Dec 14, 2009 5:30 am
by battye
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 :)