SimplePortal

Customization => Custom Coding => Topic started by: ncoded on October 20, 2015, 12:30:50 PM

Title: How to edit a Block of type Articles
Post by: ncoded on October 20, 2015, 12:30:50 PM
My question is more generally applicable to any stock block. I am using topics from a "Blog" board to feed an "Articles" type block with the latest 5 entries (I call this block "Recent Blogs"), but I would like to customize the latter further by adding a column for time and date. Is it possible to edit this block within the portal settings? Or would I have to dig into the file directly (which file would that be)? Or could I just copy the code from this file and then create a custom php block that I can then edit from within the settings? Has anyone done this or similar in a simple way?

An easier task yet would be to add a link at the bottom of the "Recent blogs" block that takes the member to the "Blog" board in the forum area, where naturally all blogs ever are listed - but otherwise the same questions as above apply.

Regards to all.
Title: Re: How to edit a Block of type Articles
Post by: ccbtimewiz on October 20, 2015, 07:15:14 PM
Hello,

All the blocks are stored in /Sources/PortalBlocks.php, each with its own function.

You can modify the block in that file, or you can create a custom PHP block and do the same like you said, however you will need to make some adjustments as parameters don't need to be passed.
Title: Re: How to edit a Block of type Articles
Post by: ncoded on October 21, 2015, 11:52:41 AM
Thanks. I looked in the file, found the function, got lost in the code :), tried what little I thought might work (it didn't), so it's time to hit the books before I can move on. If and when I get this done, will post here again.
Title: Re: How to edit a Block of type Articles
Post by: ccbtimewiz on October 21, 2015, 01:08:02 PM
What did you try and do? I could help you with the edits.
Title: Re: How to edit a Block of type Articles
Post by: ncoded on October 21, 2015, 06:06:41 PM
I appreciate your offer and I will make use of it when I feel more prepared. Right now I am not up to speed but working on it.

So far I tried to identify the functions, the calls, the parameters and am looking into their relationship with the db. For a quick try, i wanted to add somewhere a line that puts "hello" at the bottom of my box, after the liat of items already there (failed to achieve that but threw no error either.

For easier practice going forward I want to install a copy of the forum in WAMP so I can try things while offline. I will surely be back soon.

Thanks again.
Title: Re: How to edit a Block of type Articles
Post by: ncoded on October 21, 2015, 11:10:07 PM
So far so good: I mirrored my forum offline and found out that what I wanted to do was actually easier than seemed: I simply inserted a link at the bottom of the list. Remains to work out the styling and this little project is all done!

Regards.
Title: Re: How to edit a Block of type Articles
Post by: ccbtimewiz on October 21, 2015, 11:13:36 PM
Could you post the edits you made? To help anyone else wanting to achieve the sme
Title: Re: How to edit a Block of type Articles
Post by: ncoded on October 21, 2015, 11:21:13 PM
At the moment Im working on the localhost and posting here from my mobile, but yes, I will.
Title: Re: How to edit a Block of type Articles
Post by: ncoded on October 22, 2015, 06:56:54 PM
I edited PortalBlocks.php and at almost the bottom of the function (line 2525 in my case) I added this:

Code: [Select]
// at bottom of blogs/article block add link to all topics
echo ' <hr>';
echo ' <table class="sp_fullwidth sp_articles">';
echo ' <tr>
<td class="sp_articles sp_center">';
echo ' <a href="http://localhost/myforum/index.php?board=28.0">',"see all blog entries",'</a>';
echo '
</td>
</tr>

I agree that it may not be the best way, and that it can be styled even further, but it works for me right now and allows me to quickly move on.

Should you be inclined to help, here's what I am thinking about: (1) what if I modify my boards and what's now board=28.0 changes, is there a way to write my code so I don't have to remember to come back here and hardcode it with the new value? and (2) instead of hardcoding the path/url, I'd rather use some already defined variable.

Hope this helps.

Regards.
Title: Re: How to edit a Block of type Articles
Post by: ccbtimewiz on October 22, 2015, 11:45:46 PM
Here, you could try doing this and tell me the result.

Open /Sources/PortalBlocks.php

Find:
Code: [Select]
$request = $smcFunc['db_query']('','
SELECT
m.id_topic, m.subject, m.poster_name, c.picture, c.name,
mem.id_member, mem.real_name, mem.avatar,
at.id_attach, at.attachment_type, at.filename

Replace with:
Code: [Select]
$request = $smcFunc['db_query']('','
SELECT
m.id_topic, m.subject, m.poster_name, m.id_board, c.picture, c.name,
mem.id_member, mem.real_name, mem.avatar,
at.id_attach, at.attachment_type, at.filename

Find:
Code: [Select]
$articles[] = array(
'id' => $row['id_topic'],

Replace with:
Code: [Select]
$articles[] = array(
'id' => $row['id_topic'],
'id_board' => $row['id_board'],

Find:
Code: [Select]
<td>
<span class="sp_articles_title">', $article['poster']['link'], '</span><br />
', $article['link'], '
</td>
</tr>';

Replace with:
Code: [Select]
<td>
<span class="sp_articles_title">', $article['poster']['link'], '</span><br />
', $article['link'], '
</td>
</tr>
<tr>
<td rowspan="2" align="center">
<span><a href="' . $scripturl . '?board=' . $article['id_board'] . '.0">View all entries...</a></span>
</td>
</tr>';
Title: Re: How to edit a Block of type Articles
Post by: ncoded on October 23, 2015, 09:38:24 AM
I commented out my edits and plugged in your code, and without seeing any errors, the link does not show up in the block... :( I see though what you're doing and right now I'm trying to understand why it doesn't work.

Thanks for your support!
Title: Re: How to edit a Block of type Articles
Post by: ncoded on October 23, 2015, 04:24:42 PM
Hm... It turns out that if I move the link-building code outside of the table structure it's in right now (and create a table structure for it just above the end of the function), the code works at least to the point that a link shows up in the block. I keep studying it...
Title: Re: How to edit a Block of type Articles
Post by: ccbtimewiz on October 24, 2015, 09:44:14 PM
You could do this instead:

Find:
Code: [Select]
<td>
<span class="sp_articles_title">', $article['poster']['link'], '</span><br />
', $article['link'], '
</td>
</tr>';

Replace with:
Code: [Select]
<td>
<span class="sp_articles_title">', $article['poster']['link'], '</span><br />
', $article['link'], ' <div style="align: right;"><a href="' . $scripturl . '?board=' . $article['id_board'] . '.0">View all entries...</a></div>
</td>
</td>
</tr>';
Title: Re: How to edit a Block of type Articles
Post by: ncoded on October 27, 2015, 09:34:24 AM
I tried the code and again, the link does not show up in the block. So again I moved it outside the loop/table to just above the end of the function, like this:

Find:
Code: [Select]
}
}
function sp_shoutbox($parameters, $id, $return_parameters = false)

Replace with:
Code: [Select]
}
    echo '  <hr /> <div style="text-align:center"><a href="' . $scripturl . '?board=' . $article['id_board'] . '.0">View all entries...</a></div> ';
}
function sp_shoutbox($parameters, $id, $return_parameters = false)

In building the link I gave up on the <table> structure (overkill) and <span> in favor of the <div> which acts as a block and takes all the width available to it.

Thanks again for your help; I believe I got all that I asked for.
Title: Re: How to edit a Block of type Articles
Post by: ncoded on October 28, 2015, 12:25:42 AM
I believe I managed to figure out why the link would not show the way you coded it for me: it has to do with the value of $image. Mine is empty (why is that so? Could it be because I use no avatar?). So at this point in the code

Code: [Select]
if (empty($image))
{
...
foreach
...
}
else
{
...
foreach
...
}

the first (top) foreach routine is executed, not the second (bottom) one.
Title: Re: How to edit a Block of type Articles
Post by: ccbtimewiz on October 28, 2015, 12:48:39 AM
$image is only set if you are using a category image.

If it's empty, you can edit it like so;

Find:
Code: [Select]
foreach ($articles as $article)
echo '
<li>', sp_embed_image('topic'), ' ', $article['link'], ' </li>';

Replace with:
Code: [Select]
foreach ($articles as $article)
echo '
<li>', sp_embed_image('topic'), ' ', $article['link'], ' <a href="' . $scripturl . '?board=' . $article['id_board'] . '.0">View all entries...</a></li>';
Title: Re: How to edit a Block of type Articles
Post by: ccbtimewiz on October 28, 2015, 01:00:13 AM
For something a bit more aesthetically pleasing, you could do this instead:

Code: [Select]
foreach ($articles as $article)
echo '
<li>', sp_embed_image('topic'), ' ', $article['link'], ' <span class="smalltext"><a href="' . $scripturl . '?board=' . $article['id_board'] . '.0">(view more)</a></span></li>';
Title: Re: How to edit a Block of type Articles
Post by: ncoded on October 28, 2015, 01:09:15 AM
Thanks, I am looking into this, also added author name following topic link, now trying to turn them the right color and into links as is everywhere else forum-wide.
Title: Re: How to edit a Block of type Articles
Post by: ccbtimewiz on October 28, 2015, 02:51:34 AM
Thanks, I am looking into this, also added author name following topic link, now trying to turn them the right color and into links as is everywhere else forum-wide.

You can use $article['poster']['link'], and it will display a link to the poster's profile and will be colored.
Title: Re: How to edit a Block of type Articles
Post by: ncoded on October 28, 2015, 03:58:16 AM
Yes, indeed. I used ['link'] instead of ['name'] and now everything's perfect. Thank you!
SimplePortal 2.3.8 © 2008-2024, SimplePortal