Hello, I'm creating a mod that features posts to homepage with thumbnail and excerpt just like WordPress.
Now, I ran a query e.g
function Featured(){
$request = $smcFunc['db_query']('','
SELECT * FROM {db_prefix}messages' LIMIT 10);
while($row = $smcFunc['db_fetch_assoc']($request))
$context['ft] = $row;
}
Featured();
The template I created is actually for modificationcenter, it is supposed to display all post there but it does not show.
Then I ran to my template file name Featured.template.php
template_featured_main(){
echo $context['ft'];
}
Nothing shows. I need help immediately. Thank you.
I'm running my custom area I.e action=moderate;area=featured
In both cases you need to make $context global.
Also please note, everyone here is a volunteer, there is no such thing as 'immediate' help, it just happened that I checked and responded. Again I would recommend looking through existing code which will demonstrate all of the things SMF does.
It is global, can you look at The code I posted above. Sorry for the immediate stuff
Quote from: Arantor on July 07, 2018, 07:23:16 AM
In both cases you need to make $context global.
Also please note, everyone here is a volunteer, there is no such thing as 'immediate' help, it just happened that I checked and responded. Again I would recommend looking through existing code which will demonstrate all of the things SMF does.
I couldn't sleep for 5hrs trying to fix it. So it became frustrating.
You'll get help as soon as we can, but please avoid double posting when not necessary. Thank you :)
Quote from: mattizzy on July 07, 2018, 07:26:49 AM
Quote from: Arantor on July 07, 2018, 07:23:16 AM
In both cases you need to make $context global.
Also please note, everyone here is a volunteer, there is no such thing as 'immediate' help, it just happened that I checked and responded. Again I would recommend looking through existing code which will demonstrate all of the things SMF does.
I couldn't sleep for 5hrs trying to fix it. So it became frustrating.
Yet you are repeating behavior Arantor was referring to. ;) Arantor meant you should allow for time to pass, before expecting replies. That is the nature of completely volunteer run support.
Quote from: mattizzy on July 07, 2018, 07:25:50 AM
It is global, can you look at The code I posted above. Sorry for the immediate stuff
No, it isn't. If that's your exact code, it will guaranteed fail since neither $context nor $smcFunc are pulled into scope. Not to mention the multiple syntax errors in that code.
You might have more luck with:
function Featured()
{
global $smcFunc, $context;
$request = $smcFunc['db_query']('','
SELECT *
FROM {db_prefix}messages
ORDER BY id_msg DESC
LIMIT 1');
while($row = $smcFunc['db_fetch_assoc']($request))
{
$context['ft'] = $row;
}
$smcFunc['db_free_result']($request);
}
Featured();
function template_featured_main() {
echo $context['ft'];
}
Not that any of that will work the way you expect, because the code is trying to print an array which it won't be able to do (for debugging, try var_dump or print_r, and then print the bits of the array you care about)
Or the fact you were trying to get 10 rows out of the database but only ever keeping one of them (and you were getting the oldest 10 messages in the database, which seems unlikely to be what you're trying to get)
Posting because you're getting frustrated only guarantees you getting more frustrated. Go have some rest, come back when you're feeling more positive.
Quote from: Arantor on July 07, 2018, 07:32:04 AM
Quote from: mattizzy on July 07, 2018, 07:25:50 AM
It is global, can you look at The code I posted above. Sorry for the immediate stuff
No, it isn't. If that's your exact code, it will guaranteed fail since neither $context nor $smcFunc are pulled into scope. Not to mention the multiple syntax errors in that code.
You might have more luck with:
function Featured()
{
global $smcFunc, $context;
$request = $smcFunc['db_query']('','
SELECT *
FROM {db_prefix}messages
ORDER BY id_msg DESC
LIMIT 1');
while($row = $smcFunc['db_fetch_assoc']($request))
{
$context['ft'] = $row;
}
$smcFunc['db_free_result']($request);
}
Featured();
function template_featured_main() {
echo $context['ft'];
}
Not that any of that will work the way you expect, because the code is trying to print an array which it won't be able to do (for debugging, try var_dump or print_r, and then print the bits of the array you care about)
Or the fact you were trying to get 10 rows out of the database but only ever keeping one of them (and you were getting the oldest 10 messages in the database, which seems unlikely to be what you're trying to get)
Posting because you're getting frustrated only guarantees you getting more frustrated. Go have some rest, come back when you're feeling more positive.
Thank you, I'll just get some rest
I figured it out. Thanks.