Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: marco.panichi - marraskuu 02, 2013, 09:29:53 AP

Otsikko: How to show last X topics on home page?
Kirjoitti: marco.panichi - marraskuu 02, 2013, 09:29:53 AP
I'm using SFM 2.0.6.

I'd like to put into my home page the X last topics published in any boards.

I've tried to use the $context variable inside the "// Show lots of posts" section of BoardIndex.template.php file, but I've understood after some tests that these are POSTS and not TOPIC.

I've seen in other discussion that I could use a Portal to make this customization but I'd prefer to hard code my theme instead.

Thank you for every suggestion.
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: margarett - marraskuu 02, 2013, 09:42:51 AP
If your home page is not part of the forum you need to use SSI.
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: emanuele - marraskuu 02, 2013, 10:36:49 AP
Did you already try: admin > configuration > current theme and change the "Number of recent posts to display on board index"?
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: marco.panichi - marraskuu 02, 2013, 10:54:03 AP
Hi guys, thank you for the quick reply, but it doesn't solve my problem.

LainaaIf your home page is not part of the forum you need to use SSI.

No, is the forum home page

LainaaDid you already try: admin > configuration > current theme and change the "Number of recent posts to display on board index"?

Yes I saw this setting but the problem is that I don't want POSTS, but TOPICS. I want to show the last (for example) 30 topics ordered by last update.
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: margarett - marraskuu 02, 2013, 10:58:57 AP
Ah, that.

Yeah, that's probably not existent right now, as that information isn't fetched anywhere, I believe.

This would require to add at least a DB query and show that information at BoardIndex.template.php
Something I can't do on the phone :P
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: emanuele - marraskuu 02, 2013, 11:01:54 AP
http://custom.simplemachines.org/mods/index.php?action=search;basic_search=topic+recent

maybe:
http://custom.simplemachines.org/mods/index.php?mod=3682
or:
http://custom.simplemachines.org/mods/index.php?mod=1414
or:
http://custom.simplemachines.org/mods/index.php?mod=1314
or:
http://custom.simplemachines.org/mods/index.php?mod=3288

Dunno if any of that is what you are looking for.
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: marco.panichi - marraskuu 03, 2013, 02:14:23 AP
Thank you again. I'd prefer not to use a modification. I'll do some tests and I'll let you know.
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: emanuele - marraskuu 03, 2013, 03:52:55 AP
Of course you are not forced to use one, but you can use it to see what it does.

Out of curiosity: why don't you want to use a mod?
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: marco.panichi - marraskuu 04, 2013, 04:04:54 AP
Ciao Emanuele,

I don't want to use mods when I use a system for the first time, mainly for these reasons:
- security: I want to know how mods (and the system itself) work before using lots of them
- customization: Using a mod is surely a time saver at the beginning, but could be a problem if more customizations are needed
- learning: I can learn lots hardcoding some features

Regarding my initial problem, I've solved with this query:
SELECT
t.id_topic, t.is_sticky, t.id_board, t.id_first_msg, t.id_last_msg, t.id_member_started, t.id_member_updated, t.id_poll,
t.id_previous_board, t.id_previous_topic, t.num_replies, t.num_views, t.locked, t.unapproved_posts, t.approved,

mf.id_msg AS mf_id_msg, mf.id_topic AS mf_id_topic, mf.id_board AS mf_id_board, mf.poster_time AS mf_poster_time,
mf.id_member AS mf_id_member, mf.id_msg_modified AS mf_id_msg_modified, mf.subject AS mf_subject, mf.poster_name AS mf_poster_name,
mf.poster_email AS mf_poster_email, mf.poster_ip AS mf_poster_ip, mf.smileys_enabled AS smileys_enabled, mf.modified_time AS mf_modified_time,
mf.modified_name AS mf_modified_name, mf.body AS mf_body, mf.icon AS mf_icon, mf.approved AS mf_approved,

ml.id_msg AS ml_id_msg, ml.id_topic AS ml_id_topic, ml.id_board AS ml_id_board, ml.poster_time AS ml_poster_time,
ml.id_member AS ml_id_member, ml.id_msg_modified AS ml_id_msg_modified, ml.subject AS ml_subject, ml.poster_name AS ml_poster_name,
ml.poster_email AS ml_poster_email, ml.poster_ip AS ml_poster_ip, ml.smileys_enabled AS smileys_enabled, ml.modified_time AS ml_modified_time,
ml.modified_name AS ml_modified_name, ml.body AS ml_body, ml.icon AS ml_icon, ml.approved AS ml_approved
FROM
[PREFIX]topics AS t
INNER JOIN [PREFIX]messages AS mf ON (mf.id_msg = t.id_first_msg)
INNER JOIN [PREFIX]messages AS ml ON (ml.id_msg = t.id_last_msg)
ORDER BY t.id_last_msg DESC
LIMIT 20


Yes I know! It's not good to do this. But the client absolutly required that particular conditions are satisfied in spite of my suggestions and alerts... ::)
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: emanuele - marraskuu 04, 2013, 06:37:29 AP
Lainaus käyttäjältä: marco.panichi - marraskuu 04, 2013, 04:04:54 AP
- learning: I can learn lots hardcoding some features
That's the only good reason in your list. :P

Lainaus käyttäjältä: marco.panichi - marraskuu 04, 2013, 04:04:54 AP
- security: I want to know how mods (and the system itself) work before using lots of them
You can check security of mods too, just read the code.

Lainaus käyttäjältä: marco.panichi - marraskuu 04, 2013, 04:04:54 AP
- customization: Using a mod is surely a time saver at the beginning, but could be a problem if more customizations are needed
A "mod" is not a magic thing, it's just code to be placed "somewhere", what you do is grab the code and add it. The package manager is a support to the installation of mods, but is not mandatory at all. I'm not using it in most of the forums I support (despite the fact that if anyone else would pick the support would have to learn how to use git), I just apply changes by hands (changing what I don't like) and then commit the changes to a git repo. ;)

Lainaus käyttäjältä: marco.panichi - marraskuu 04, 2013, 04:04:54 AP
Regarding my initial problem, I've solved with this query:
SELECT
t.id_topic, t.is_sticky, t.id_board, t.id_first_msg, t.id_last_msg, t.id_member_started, t.id_member_updated, t.id_poll,
t.id_previous_board, t.id_previous_topic, t.num_replies, t.num_views, t.locked, t.unapproved_posts, t.approved,

mf.id_msg AS mf_id_msg, mf.id_topic AS mf_id_topic, mf.id_board AS mf_id_board, mf.poster_time AS mf_poster_time,
mf.id_member AS mf_id_member, mf.id_msg_modified AS mf_id_msg_modified, mf.subject AS mf_subject, mf.poster_name AS mf_poster_name,
mf.poster_email AS mf_poster_email, mf.poster_ip AS mf_poster_ip, mf.smileys_enabled AS smileys_enabled, mf.modified_time AS mf_modified_time,
mf.modified_name AS mf_modified_name, mf.body AS mf_body, mf.icon AS mf_icon, mf.approved AS mf_approved,

ml.id_msg AS ml_id_msg, ml.id_topic AS ml_id_topic, ml.id_board AS ml_id_board, ml.poster_time AS ml_poster_time,
ml.id_member AS ml_id_member, ml.id_msg_modified AS ml_id_msg_modified, ml.subject AS ml_subject, ml.poster_name AS ml_poster_name,
ml.poster_email AS ml_poster_email, ml.poster_ip AS ml_poster_ip, ml.smileys_enabled AS smileys_enabled, ml.modified_time AS ml_modified_time,
ml.modified_name AS ml_modified_name, ml.body AS ml_body, ml.icon AS ml_icon, ml.approved AS ml_approved
FROM
[PREFIX]topics AS t
INNER JOIN [PREFIX]messages AS mf ON (mf.id_msg = t.id_first_msg)
INNER JOIN [PREFIX]messages AS ml ON (ml.id_msg = t.id_last_msg)
ORDER BY t.id_last_msg DESC
LIMIT 20


Yes I know! It's not good to do this. But the client absolutly required that particular conditions are satisfied in spite of my suggestions and alerts... ::)
Ugly! :o :P
I'm pretty sure the next requirement will be attachments, so be ready for it. :P
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: margarett - marraskuu 04, 2013, 07:36:06 AP
I would suggest you pick one of the existing mods and "study" it. Being a package or not, custom coding also fits as a mod ;)
So, if you're coding yourself, you will also be making a MODification ;)

As for your code, you just need ID, first message ID+subject and poster name in order to build a link ;)
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: marco.panichi - marraskuu 05, 2013, 02:39:45 AP
First of all, thank you vey much for your support. I really appreciate your work and I'm starting to appreciate the SFM too.

Regarding the security I've studied some modification (in particular the http://custom.simplemachines.org/mods/index.php?mod=1414 (http://custom.simplemachines.org/mods/index.php?mod=1414) modification  that I used to make the query above) and now I'm less "scared". You are right, cit. A "mod" is not a magic thing

I've also used the package manager and understood that I prefer not to use it, because copying and customizing the code by myself is more comfortable as you said.

LainaaUgly! :o :P
I made ​​a bet with myself about your comment on my query and I have to say that you were very nice compared to my predictions  :D But you know, I solved the client's problem and established with him that there will be no further changes (attachment problem: FIXED!  ;) )

LainaaAs for your code, you just need ID, first message ID+subject and poster name in order to build a link
I have these fields in my query: mf = message first / ml = message last.

Thank you again...!
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: Colin - marraskuu 05, 2013, 02:48:32 AP
Lainaa
I've also used the package manager and understood that I prefer not to use it, because copying and customizing the code by myself is more comfortable as you said.

I am glad that you got everything working, but I would really encourage you to use mods. The benefit of using mods is all of the code changes are accounted for and can be easily removed and readded if need be. The package manager is rather efficient. In terms of mod quality the customization team vets each modification on initial submission for compliance with the coding guidelines so it isn't a totally loose process. Rather than stray away from it because of some preconceptions, have a look around, ask, give it a try, and form your own opinion. I think it might be quite different from what it is now.
Otsikko: Re: How to show last X topics on home page?
Kirjoitti: marco.panichi - marraskuu 06, 2013, 04:09:40 AP
Hi Colin,

I have no preconceptions, really. I've used the packet manager successfully to install three mods. I also want to consider the manual installation because I feel I have more consciousness on the entire project.