Page 1 of 2

News Page

PostPosted: Mon Dec 27, 2010 5:29 pm
by El Diablo
Hello:
I have been coming to this forum for various answers to php related questions and it has been very helpful l:D
I am now wondering if it would be possible to know how to make a News page similar to the one this forum uses. We are currently at www.poquer833.com I have tried the external page thing but have not been able to get it working as neatly as yours.

Thanks in advance
:D

Re: News Page

PostPosted: Mon Dec 27, 2010 6:23 pm
by battye
Hi El Diablo. Whereabouts on http://www.poquer833.com/ do you want your news articles to be displayed?

When you say you've tried the external page thing, do you mean you've tried this: http://blog.phpbb.com/2009/11/09/how-to ... nal-pages/

Have you also tried: http://www.cricketmx.com/articles/read/ ... in-phpbb3/ :?:

Re: News Page

PostPosted: Tue Dec 28, 2010 11:17 pm
by El Diablo
battye wrote:Hi El Diablo. Whereabouts on http://www.poquer833.com/ do you want your news articles to be displayed?


I would like for it to be the landing page.

battye wrote:When you say you've tried the external page thing, do you mean you've tried this: http://blog.phpbb.com/2009/11/09/how-to ... nal-pages/

Have you also tried: http://www.cricketmx.com/articles/read/ ... in-phpbb3/ :?:


I read the first one and tried the second one. I did manage to get it to work but desisted because I want to be able to show the posts as miniposts with an image included, something like a small fragment of the post with a read more link.

Thanks for your prompt response.

Re: News Page

PostPosted: Wed Dec 29, 2010 5:41 am
by battye
How familiar are you with PHP?

The fragment part isn't too difficult, you just need need to enclose the article text inside substr - http://www.php.net/manual/en/function.substr.php

Code: Select all
echo substr('abcdef', 0, 4);  // would output characters 0 to 4, ie: abcd


Where is the image to come from? Is it supposed to be random or fixed or something else?

Re: News Page

PostPosted: Wed Dec 29, 2010 8:14 am
by El Diablo
I am not good at php but will try.
The news I want displayed in the first page of the site are here:
http://poquer833.com/viewforum.php?f=17

An example of a topic would be something like this:
http://poquer833.com/viewtopic.php?f=17&t=175

There is a picture on the post (second link) and I would like for it to be displayed.

In the example you give me, is the text supposed to be placed there by me or can I make is so that it retrieves it by itself as I am not always the one posting the news and would like for them to refresh by themselves?

I have managed to make outside pages such as this: http://www.poquer833.com/convertido.php
Which will keep the format of the forum (header and footer, general looks), and I would like the first page, where the news are to be displayed, to keep the same format.

I might not be making much sense for English is not my first language, please do ask me to explain further if that is the case.

Re: News Page

PostPosted: Sun Jan 02, 2011 11:12 am
by battye
I understand what you mean, I just want to ascertain that you haven't actually made the .php file to display the news yet?

If not, have you downloaded the files that were available in this article? http://www.cricketmx.com/articles/read/ ... in-phpbb3/

If I recall there was a zip file to download, and you could use those files (the .php files) and they would work automatically. With a bit of tweaking we can get it to have the proper look of your site (header and footer, etc) as well :)

There won't be a problem with the images, as you can see from the www.cricketmx.com homepage bbCode will work perfectly :)

Re: News Page

PostPosted: Sun Jan 02, 2011 6:41 pm
by El Diablo
battye wrote:
If not, have you downloaded the files that were available in this article? http://www.cricketmx.com/articles/read/ ... in-phpbb3/

If I recall there was a zip file to download, and you could use those files (the .php files) and they would work automatically. With a bit of tweaking we can get it to have the proper look of your site (header and footer, etc) as well :)



I have installed both files but did not rename them so you can find it at: http://poquer833.com/home.php

I had been able to do that and even add the header and footer following this:
http://www.phpbb.com/kb/article/add-a-n ... -to-phpbb/

But it still feels hard to read and not user friendly: D

Re: News Page

PostPosted: Mon Jan 03, 2011 10:12 am
by battye
Okay, adding the header and footer so home.php looks more user friendly isn't too difficult. Go to: http://blog.phpbb.com/2009/11/09/how-to ... nal-pages/

Then scroll down and look for the paragraph near this code snippet (relating to templating), and read the paragraph starting with "By using the templating variables..."

Code: Select all
page_header('The title of your page goes here');

$template->set_filenames(array(
'body' => 'home_body.html'
));

page_footer();
?>


If you are unsure of where to go from here, let me know and I'll go into extra detail (just make sure to post the contents of the home.php code in your reply :))

Re: News Page

PostPosted: Mon Jan 03, 2011 2:37 pm
by El Diablo
Ok, header and footer have been included as you can see here:
http://poquer833.com/home.php

Now, I would like to only add the first post (not the replies) of the topic on these forums:
http://poquer833.com/viewforum.php?f=17
http://poquer833.com/viewforum.php?f=16
http://poquer833.com/viewforum.php?f=15

The code on home.php is:
Code: Select all
<?php
/*
* home.php
* Description: example file for displaying latest posts and topics
* by battye (for phpBB.com MOD Team)
* September 29, 2009
*/

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('viewforum');

$search_limit = 5;

$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) )
      {
         $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(
         'TOPIC_TITLE'       => censor_text($topic_title),
         'POST_AUTHOR'       => $post_author,
         'POST_DATE'       => $post_date,
         'POST_LINK'       => $post_link,
         'POST_TEXT'         => censor_text($post_text),
         ));
      }

page_header('External page');

    $template->set_filenames(array(
        'body' => 'external_body.html'
    ));

    page_footer();
?>

Re: News Page

PostPosted: Mon Jan 03, 2011 5:16 pm
by battye
So in all you want 3 posts to appear on your news page? The first post of the newest topic in forum 15, forum 16 and forum 17 - is this correct?

Re: News Page

PostPosted: Mon Jan 03, 2011 7:29 pm
by El Diablo
The number of posts to appear can be up to 5, maybe even more, I’m not too worried about that. What I meant was that I only want them to come from 15, 16 and 17. And the ones that come from them to be only the first post of the thread.

Re: News Page

PostPosted: Tue Jan 04, 2011 6:35 am
by battye
In the code, FIND

Code: Select all
'WHERE'     => $db->sql_in_set('t.forum_id', array_keys($auth->acl_getf('f_read', true))) . '


REPLACE WITH

Code: Select all
'WHERE'     => $db->sql_in_set('t.forum_id', array(15, 16, 17)) . '


Does that fix it?

Re: News Page

PostPosted: Tue Jan 04, 2011 8:45 am
by El Diablo
Yes, thank you, now I am getting the threads from the forums I want.
Is it now possible to get only the first post of the threads rather than the last post of the threads?

Re: News Page

PostPosted: Tue Jan 04, 2011 3:40 pm
by battye
See http://blog.phpbb.com/2009/11/09/how-to ... nal-pages/

Look for the heading "EXAMPLE 2: Display first post from the last five topics"

The code below that is the SQL code you need to use :)

ie.
Code: Select all
$posts_ary = array(
'SELECT' => 'p.*, t.*',

'FROM' => array(
POSTS_TABLE => 'p',
),

'LEFT_JOIN' => array(
array(
'FROM' => array(TOPICS_TABLE => 't'),
'ON' => 't.topic_first_post_id = p.post_id'
)
),

'WHERE' => $db->sql_in_set('t.forum_id', $forum_id_where) . '
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);


See where it says $forum_id_where in the code above, just near the bottom?

That is where you currently have your 15, 16, 17 listed... so to get around that, at the top of your code you need lines like this:

Code: Select all
$forum_id_where = array(15, 16, 17);

Re: News Page

PostPosted: Tue Jan 04, 2011 8:11 pm
by El Diablo
Excellent!

Thanks a lot it works great.

http://poquer833.com/home.php

Now I still need to format the information to look friendly but I will give it a try, any suggestions?

I will come back to show how it ends up or to beg for more help if I don’t get it to look good.