SimplePortal

Customization => Custom Coding => Topic started by: ataru on December 14, 2015, 10:55:03 AM

Title: Check if a post is an article
Post by: ataru on December 14, 2015, 10:55:03 AM
Is there a quick way to check if a post is an article or not? where should i check it? in index.template.php of my theme? or in post.template.php of main?

i would add article's category image to post, and i don't know where to start.

Could someone help?
Title: Re: Check if a post is an article
Post by: ataru on December 14, 2015, 12:15:02 PM
ok. found it.

in Sources/Display.php I changed

Code: [Select]
// Is this already an article?
$request = $smcFunc['db_query']('','
SELECT id_message
FROM {db_prefix}sp_articles
WHERE id_message = {int:message}',
array(
'message' => $context['topic_first_message'],
)
);
list ($context['topic_is_article']) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

in

Code: [Select]
// Is this already an article?
$request = $smcFunc['db_query']('','
SELECT id_message, picture
FROM {db_prefix}sp_articles AS a
INNER JOIN {db_prefix}sp_categories AS c ON a.`id_category` = c.`id_category`
WHERE id_message = {int:message}',
array(
'message' => $context['topic_first_message'],
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if(!empty($row['id_message'])) {
$context['topic_is_article'] = $row['id_message'];
$context['article_image_url'] = $row['picture'];
}
}
$smcFunc['db_free_result']($request);

and in Templates/default/Display.template.php I changed

Code: [Select]
echo '
<div class="inner" id="msg_', $message['id'], '"', '>', $message['body'], '</div>
</div>';


in

Code: [Select]
if ($context['topic_is_article'])
echo '
<div class="inner" id="msg_', $message['id'], '"', '><div style="float:right"><img src="',$context['article_image_url'],'"></div>', $message['body'], '</div>
</div>';
else
echo '
<div class="inner" id="msg_', $message['id'], '"', '>', $message['body'], '</div>
</div>';
Title: Re: Check if a post is an article
Post by: ♦ Ninja ZX-10RR ♦ on December 14, 2015, 12:32:12 PM
Glad you are back, it had been a while!

Thanks for posting the solution you provided, didn't have time to dig, would have known the template part, but I hate queries ;D
Besides, moving to custom coding ;)

Regards
SimplePortal 2.3.8 © 2008-2024, SimplePortal