Ok folks, sorry to ask this. Ive spent ages readng through the block snippets but I just cant lay my hands on what Im after!
Basically, Im just getting to grips with blocks and such. What I have in my forum is a few boards. A couple of the boards have child boards called "news". I will post news as a new topic in each of these boards. Id like to be able to show the posts I do (not the replies, so first posts only), from each of these news sections on the front page. If it was a long post, it may also have a link at the end saying "read more" or something to that effect.
For example it could look like:
Latest News:
Section 1
News article here .......................... read more (link to forum post)
Section 2
News article here .......................... read more (link to forum post)
Section 3
News article here .......................... read more (link to forum post)
:-\
I think it is possible but just really need nudging in the direction of where I might get the code from.
Thanks in advance,
You'll need to create a phpbox and in it, use SMF's SSI functions to call those posts. I'm half awake and have no access to SMF a.t.m. so I can't help with the coding now. I'll check back later if nobody comes along to throw in the codes :P
I am attempting the same type of read more links at my site, so I'll be following this thread ...peace
Hi jawd, I'll just assume that you're new to SMF. SMF has some functions stored on SSI.php (do not edit at any point in time! unless you know what you're doing and can remember what you've done) that allows us to display pretty much information. The examples can be seen through calling ssi_examples.php.
http://www.tinyportal.net/smf/ssi_examples.php
More info here:
http://www.simplemachines.org/community/index.php?topic=14906.0
In your case, I'll use ssi_boardNews. To use it as it is (default), create a phpbox and drop in this line:
ssi_boardNews();
Follow this tutorial to learn how to cater to your needs:
http://www.simplemachines.org/community/index.php?topic=13016.0
To specify some conditions (specific), use this line instead:
ssi_boardNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
Change $board to your child board's number, $limit to how many post to show and $length to how many characters to show.
The xx Comments brings readers to the actual post. If you want to change it to Read More ..., you'll need to change more codes (customized)!!
1. Open SSI.php and look for:
function ssi_boardNews($board = null, $limit = null, $start = null, $length = null, $output_method = 'echo')
2. Copy the whole function into your phpbox block. It's a whole chunk so I'm not posting the full code here.
3. Rename ssi_boardNews to something else, say ssi_boardNews1 or ssi_boardNews_child1.
4. Change to TP's Read More... Look for:
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $row['numReplies'] . ' ' . ($row['numReplies'] == 1 ? $txt['smf_news_1'] : $txt['smf_news_2']) . '</a>',
And change to:
'link' => '<a href="' . $scripturl . '?topic=' . $row['ID_TOPIC'] . '.0">' . $txt['tp-readmore'] . '</a>',
5. Look for:
', $news['link'], $news['locked'] ? '' : ' | ' . $news['comment_link'], '
I honestly have no idea how to read this... but change it to:
', $news['link'],'
6. Remember to call for it:
ssi_boardNews_child1();
if you already specify your board, etc. in the codes, or
ssi_boardNews_child1($board = xx.0, $limit = xx, $start = null, $length = xxx, $output_method = 'echo')
if you have not specify.
7. If you want to modify the appearance further, take a look at the codes that comes after:
foreach ($return as $news)
8. Once you're happy with it, duplicate the whole function for ssi_boardNews_child2 and ssi_boardNews_child3. How you want to display them is really up to you.
echo 'This is my first child:<br/>';
ssi_boardNews_child1()<br/>;
echo 'This is my second child:<br/>';
ssi_boardNews_child2()<br/>;
echo 'This is my third child:<br/>';
ssi_boardNews_child3();
Lastly, phew, I've gave it a try and it's working fine :)
Quote from: hygron on August 04, 2006, 05:31:21 AM
I am attempting the same type of read more links at my site, so I'll be following this thread ...peace
Hi Hygron,
In case I got you wrong, these instructions are for showing forum posts from a certain forum board and the read more link will point users to the thread.
Hope it helps :)
Many thanks for that. works great! and yes, I am new to all this :D
Hope you are having fun so far :)
thanks for the heads-up...I am just trying to suck-up all the knowledge I can...peace
Hi again, run into a small issue. I've tried adding three blocks in total. This so I can show latest nes from three different boards. The first one worked like a charm and Ive been playing around with it no problem. the second two show the block title, but havent pulled the posts across. All I done was copy and paste the code from the first working block to the next two. I then changed the value for the board number. Ive since checked and double checked and I did get these numbers right, and they do have posts in them.
Any idea's what Ive overlooked?
Thanks,
Oh.. You want 3 blocks.. Did you change the function name (child1, 2, 3) and call for the right one for each one?
Alternatively, you can put all 3 blocks into one block, and you'll need the function code only once and save some work on your database :) Just need a little more code to make them look like 3 blocks. Of course not recommended if you want to move or on/off them too often :)
Well, literally all I done was get the first one working as you described. Then created a new block. Called news 2 etc, and copied that last piece of code into it. Changed the board number (in this case from 32 to 36).
I probably am going to sound lame, but could you post both block codes? Thanks
Course I can! I appreciate your input here:
Block 1 - this one works
$array = ssi_boardNews(32, 1, null, 500, 'array');
foreach ($array as $news)
{
echo '
<table border="0" width="100%" align="center" class="ssi_table">
<tr>
<td><b>', $news['subject'], '</b></td>
</tr>
<tr>
<td>', $news['body'], '<br /><br /></td>
</tr>
</table>
<br />';
if (!$news['is_last'])
echo '
<hr width="100%" />
<br />';
}
Block 2 - Shows block name but no content (also block 3 does this)
$array = ssi_boardNews(36, 1, null, 1000, 'array');
foreach ($array as $news)
{
echo '
<table border="0" width="100%" align="center" class="ssi_table">
<tr>
<td><b>', $news['subject'], '</b></td>
</tr>
<tr>
<td>', $news['body'], '<br /><br /></td>
</tr>
</table>
<br />';
if (!$news['is_last'])
echo '
<hr width="100%" />
<br />';
}
jawd, thanks for the code, but when you post code, please use the code icon so it wraps in a code block, it is esier for us to both view and copy the code that way ;)
I edited your post and wrapped it in a code box
Ah got it, the hash icon. Will do, and cheers.
jawd, the codes are working fine for me. silly checklist:
- make sure it's a phpbox
- make sure the board id exist and has appropriate view permission
:o
How dim do I feel.
Make sure you have given guest permissions in order to display news (walks away repeating to self.....)
Cheers Iwyen..
Oh.. considering I woke up 37.5 hours ago, I'm glad I could be of some help, though I was wondering why you were looking at your own site as a guest. That's so careful! I usually wait for someone to scream at me hee hee :D
Oh I was looking as a guest myself, I hadnt enabled guests to view the board. I think Im right in saying for this feature to work, the guests box has to be ticked.
if guests are not suppose to see the posts, then don't allow them to see the block so you'll get 1 block for guests and 3 blocks for logged in users