phpBB.com     phpBB Academy     phpBB Modders     phpBB Weekly     ktuk     phpBB Hacks     Vlad Studio  

[FUNCTION] get_announcements

Pull latest X topic titles from a certain forum and diplay them on any page.

Not enough for a full proper MOD, but too useful not to share
Forum rules
Please read over our forum guidelines

[FUNCTION] get_announcements

Postby kenny » 21 Sep 2008, 16:13

1st of all, your testing.php file has a small error
Code: Select all
$template->set_filenames(array(
   'body' => 'testing_body.html'
$template->assign_vars(array(
'ANNOUNCEMENT' => get_announcements('8', '24', 'Insert Block Title Here'),
));

Should look like this:
Code: Select all
$template->set_filenames(array(
   'body' => 'testing_body.html'
));

$template->assign_vars(array(
'ANNOUNCEMENT' => get_announcements('8', '24', 'Insert Block Title Here'),
));

2nd, your testing_body.html file :shock:
You have included overall_header.html, then declared another Doctype further down
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

Donate to 6 String MODs
If you like any of the work that I do here, please consider donating.
click the image on the left for a list of some of the advantages of donating



[FUNCTION] get_announcements

Postby Lunatic Zorr » 21 Sep 2008, 17:33

kenny wrote:and in there add our function :)
Code: Select all
   'ANNOUNCEMENT'    => get_announcements('2', '5', 'Insert Block Title Here'),

The numbers in the brackets corresponds to our function file. The 1st number is the forum id we want to take the announcements from and the 2nd number is the amount of announcements.



Ok, So this could be used to show news in the mainpage of my website, right? I mean, post the news in the forum, and they appear in the mainpage.

But, couldn't it be possible to show news (announcements) from various forums? Im mean, instead of:

Code: Select all
   'ANNOUNCEMENT'    => get_announcements('2', '5', 'Insert Block Title Here'),


Something like:

Code: Select all
   'ANNOUNCEMENT'    => get_announcements('2', '8', '13', '20'; '5', 'Insert Block Title Here'),


Where '2', '8', '13', '20' indicates the forums from were the announcements are shown, and where '5' means the number of announcements shown in total...


Or another way, couldn't it be possible to indicate any member group/-s (for example, "reporters"), and select the forums and the number of announcements that are shown? So any announcements posted in any of the selected forums be any member of the group "reporters" would appear in the main page. I think that would be nice for forums that are about more than one thing... For example, a froum about Anime, Games, design and culture. I this cases, you could use:

Code: Select all
   'ANNOUNCEMENT'    => get_announcements('2'; '8', '13', '20', '22'; '5', 'Insert Block Title Here'),


Where the first number indicates the member groups (in this case, "reporters"); the second numbers indicates the forums ("Anime news", "Games news", "design news", "culture news"), and the third number, indicates the total number of announcements shown...



I don't know if this is possible... I'm just asking, because I think that it would be great :)


Kevin.
User avatar
Lunatic Zorr
Registered User
Registered User
 
Posts: 5
Joined: 21 Sep 2008, 17:04

[FUNCTION] get_announcements

Postby kenny » 21 Sep 2008, 18:32

So this could be used to show news in the mainpage of my website, right?

Yes. As long as your main page make use of phpBB's sessions, then you can use it :)
Lunatic Zorr wrote:But, couldn't it be possible to show news (announcements) from various forums?

It is possible, you just create a 2nd call to the function. Something like this:
Code: Select all
  'ANNOUNCEMENT'    => get_announcements('2', '5', 'Announcements'),
  'LATEST_POSTS'    => get_announcements('10', '10', 'Latest Posts'),

The only problem is that calling the function more than once on page doesn't work properly at the moment (you can run a test to see what happens).
Lunatic Zorr wrote:couldn't it be possible to indicate any member group/-s (for example, "reporters"), and select the forums and the number of announcements that are shown?

This should be possible. If I get some spare time, I'll have a look into it ;)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

[FUNCTION] get_announcements

Postby Lunatic Zorr » 21 Sep 2008, 19:45

OK, I'll try it :)

Would be nice to be able to set a member group :)
User avatar
Lunatic Zorr
Registered User
Registered User
 
Posts: 5
Joined: 21 Sep 2008, 17:04

[FUNCTION] get_announcements

Postby Lucky » 21 Sep 2008, 19:48

I am really trying to get this to show posts from more then one forum id. Or even have it in more then one spot. Spot one would show general chat and then the other spot would show a different forum. I suppose I could just copy the instructions again and just rename the files I am calling.
St. Cloud Scoots is Central Minnesota's Online Scooter Community.
St. Cloud Scoots
User avatar
Lucky
Registered User
Registered User
 
Posts: 4
Joined: 21 Sep 2008, 05:19

[FUNCTION] get_announcements

Postby kenny » 21 Sep 2008, 19:54

For now that's how I did it - see the latest code snippets on my home page :P
I have to rename the function and a few of the variables inside the functions file too :)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

[FUNCTION] get_announcements

Postby Lucky » 21 Sep 2008, 19:56

You did a fantastic job with it. Just if you give a kid a cookie that kid is going to want a glass of milk as well.
St. Cloud Scoots is Central Minnesota's Online Scooter Community.
St. Cloud Scoots
User avatar
Lucky
Registered User
Registered User
 
Posts: 4
Joined: 21 Sep 2008, 05:19

[FUNCTION] get_announcements

Postby kenny » 21 Sep 2008, 20:11

Hehe. it's easy enough to do.
Start by re-naming your file to something like functions_news.php. Now open the file and re-name your functions to get_news() - you can keep the parameter names the same. Now find the while loop (while ($announce = . . .) and change all occurences of $announce to $news.
Lastly, replace this it of code:
Code: Select all
   $template->set_filenames(array(
      'content' => 'announce_body.html',
   ));

   // Thanks Vic ^_^
   $content = $template->assign_display('content', '', true);

   return $content;

With something like:
Code: Select all
   $template->set_filenames(array(
      'news => 'news_body.html',
   ));

   // Thanks Vic ^_^
   $news = $template->assign_display('news', '', true);

   return $news;

You'll need to rename the announce_body.html file to what ever you called it in the above code (news_body.html). Inside that, replace all occurrences of 'announce_row' with 'news_row', save, upload and we're done. You don't have to use news of course, you can choose something else more descriptive. Hope this helps :)
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

[FUNCTION] get_announcements

Postby Lucky » 21 Sep 2008, 21:49

Thanks a bunch. You are a great help Wish I could do all of this on my own. Your site is very easy and clean.
St. Cloud Scoots is Central Minnesota's Online Scooter Community.
St. Cloud Scoots
User avatar
Lucky
Registered User
Registered User
 
Posts: 4
Joined: 21 Sep 2008, 05:19

[FUNCTION] get_announcements

Postby kenny » 21 Sep 2008, 21:57

Thanks. I like to make things as simple as possible :mrgreen:
|| 6 String Romance || Myspace || phpBB.com || Need Freelance Work? ||
If you need one of my MODs installed - click here


Are you a musician in the Glasgow area interested in acoustic events? The ArtBox
User avatar
kenny kenny is probably rawking out on RockBand \m/
Project Leader
Project Leader
 
Posts: 647
Joined: 06 Jun 2008, 11:38
Location: Airdrie, UK

PreviousNext



Return to Code Snippets

Who is online

MSN [Bot], Yahoo [Bot]


cron