Gossamer Forum
Home : Products : Gossamer Forum : Development, Plugins and Globals :

Newest Thread on home page

Quote Reply
Newest Thread on home page
Hi

Is there a way to place the the newest X posts on the home page? NOT the Forum home page but the real home page?
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Newest Thread on home page In reply to
There are different ways to do this.

What I use is a very simple script that is called through SSI. You can find it in the attachement. This script will display any number of recent posts, but it will not check if the user is logged in and if the user has the permissions to access the posts/forums in question. This works fine for me, because all posts are visible for everyone. The script uses a template display_recent_posts.html, which is also in the attachement.

Use the script as recent.cgi?number=x, where x is the number of posts you want to display.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Newest Thread on home page In reply to
Hi Yogi,

Is it possible to "not show" posts from private forums using this script?
Quote Reply
Re: [Teambldr] Newest Thread on home page In reply to
The quickest way would be to hard-code the forums where you don't want the posts to be displayed. This would mean that no user would be seeing the private forums.

The most elegant way would be to compare the user's permission with the post/forum. All users would be seeing exactly what they allowed to see.

Depends on your situation, which way you go.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Newest Thread on home page In reply to
It seems to me that the second scenerio would be most appropriate for my application.
Quote Reply
Re: [Teambldr] Newest Thread on home page In reply to
Hi,

You could do this by creating an SSI:

<!--#include virtual="/cgi-bin/gforum.cgi?do=search_results&search_time=24h&t=homepage"-->

The tricky part is the last bit t=homepage. You should create a new template directory with two files:

search_results.html
.tplinfo

with the .tplinfo looks like:

{
inheritance => '../default'
}

This means when you go to t=homepage, it is going to use the search_results.html in that directory, but for any other template it will fall back to the default set.

Then just customize search_results.html so it fits in with how your SSI should look.

Since it goes through gforum.cgi, it ensures that all forum permissions are obeyed and people see only what they are meant to see (and if they are logged in, they would see private forums as well).

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Newest Thread on home page In reply to
Alex,

I have implemented this, but it gives you every post within the last 24 hours. How do we narrow that down to just the most recent post?

I have created a global variable <%newest_post%> to identify the post_id for the newest post

I am using the sub routine for the newest_user variable here as my guide and I have modified it for newest_post:


sub { my $table = $DB->table('Post'); $table->select_options("ORDER BY post_id DESC", "LIMIT 1"); return $table->select( 'post_id' )->fetchrow; }



This returns the post_id for the newest post.


The follow up to this would be - what do the <% if %> statements need to look like to restrict the displayed NEWEST_POST from being in a restricted area like "The Administrator Corner."

Last edited by:

shiner: Jun 4, 2002, 1:26 PM
Quote Reply
Re: [shiner] Newest Thread on home page In reply to
Quote:
I have implemented this, but it gives you every post within the last 24 hours. How do we narrow that down to just the most recent post?

You could just add mh=1 to the above query string. =) That would give you the newest post.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Newest Thread on home page In reply to
For a more generic fix - that would work better for most home page SSI includes - this appears to be the answer.

I created 5 new global variables:



newest_post

sub { my $table = $DB->table('Post'); $table->select_options("ORDER BY post_id DESC", "LIMIT 1"); return $table->select( 'post_id' )->fetchrow; }





newest_post_author

sub { my $table = $DB->table('Post'); $table->select_options("ORDER BY post_id DESC", "LIMIT 1"); return $table->select( 'post_username' )->fetchrow; }





newest_post_message

sub { my $table = $DB->table('Post'); $table->select_options("ORDER BY post_id DESC", "LIMIT 1"); return $table->select( 'post_message' )->fetchrow; }



newest_post_subject

sub { my $table = $DB->table('Post'); $table->select_options("ORDER BY post_id DESC", "LIMIT 1"); return $table->select( 'post_subject' )->fetchrow; }




chop_message

sub { my $post_message = shift; return substr($post_message,0,50); }






search_results.html (FULL POST VERSION)

<html>
<head>
<%include include_css.html%>
</head>
<%body_tag%>

<%body_table%>
<table cellspacing="0" border="0" width="100%">
<tr><td colspan="2">Recently in the <a href="/cgi-bin/forum/gforum.cgi?">discussion forum</a></td></tr>
<tr><td>- <a href="/cgi-bin/forum/gforum.cgi?post=<%newest_post%>;#<%newest_post%>;"><%newest_post_subject%></a> by <%newest_post_author%></td>
<tr><td><%newest_post_message%></td></tr>
<%/body_table%>
</center>
</body>
</html>



search_results.html (CONDENCED POST VERSION)



<html>
<head>
<%include include_css.html%>
</head>
<%body_tag%>

<%body_table%>
<table cellspacing="0" border="0" width="100%">
<tr><td colspan="2">Recently in the <a href="/cgi-bin/forum/gforum.cgi?">discussion forum</a></td></tr>
<tr><td>- <a href="/cgi-bin/forum/gforum.cgi?post=<%newest_post%>;#<%newest_post%>;"><%newest_post_subject%></a> by <%newest_post_author%></td>
<tr><td><%chop_message($newest_post_message)%>...</td></tr>
<tr><td><B>Welcome our newest member: <%newest_user%></B></td></tr>
<%/body_table%>
</center>
</body>
</html>




I like this version because it is easy to deploy, and will fit seamlessly into a pre-existing webpage.

I just have the "if - then" statements to work out. If I get it, I will post it. Tonight was a fun learning experience - one that makes me appreciate even more the robustness of the gossamer product. thanks guys! This is truly a wonderful program.
Quote Reply
Re: [Alex] Newest Thread on home page In reply to
Alex,

I am currently working on a solution for not displaying posts from restricted areas of your site on the homepage. I am not sure I am on the right track, but this is what I have so far.

1) created a field in the FORUM table called visable_on_homepage
-> visable forums got a 1 and hidden forums got a 0

2) created an action called display_newest_post with newest_post.html as the template
-> SSI: <!--#include virtual="/cgi-bin/forum/gforum.cgi?do=display_newest_post"-->

3) in newest_post.html was trying to construct the if/then statements to compensate for hidden forums, but after a few goes at it, I think this needs to be done via a sub routine in a global variable newest_visable_post.

I think the logic is close to this:

1) essentially use what was covered above in this thread to locate <%newest_post%>
2) obtain the forum_id_fk from <%newest_post%>
3) given that forum_id_fk number, cross reference {my $table = $DB->forum('visable_on_homepage')}
4) if the forum is visable_on_homepage then the value for newest_visable_post = newest_post
5) if the forum is not supposed to be visable, you need to subtract 1 from newest_post (aka the post_id of the most recent post)
6) this should continue in a loop until you find a post_id that is from a forum that is visable_on_homepage
7) once a post_id is determined, you need to be able to call upon the fields of that post.

Last edited by:

shiner: Jun 4, 2002, 1:46 PM
Quote Reply
Re: [yogi] Newest Thread on home page In reply to
Hi

I have tried your script and on the page I am using the SSI on (<!--#exec cgi="/cgi-bin/forum/recent.cgi?number=5"--> )

I am getting an error message:

[an error occurred while processing this directive]

Any suggestions
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Newest Thread on home page In reply to
Look at the error logs, what does it say?
Are the permissions of the file set correctly (i.e. is it executable)?
Have you entered the correct paths to your GForum installation?

Just some hints...

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Newest Thread on home page In reply to
Im also interested in having new forum messages on my main page. Dont have SSI though :(

My main page is the user_home of community. So its cgi generated html.

Any way of doing it?

Cat
Quote Reply
Re: [catlovette] Newest Thread on home page In reply to
I am using Yogi script to show the newest treads on the home page, know what I would like to show is threads from only one particular forum(forum_id = 1). How do I implement this; here's part of the cgi script.

# get the details of the recents posts from the database
my $db = new GT::SQL $path . '/defs';
my $post_db = $db->table ('Post');
$post_db->select_options('ORDER BY post_time DESC', "LIMIT $num");
my $sth = $post_db->select;
my @output;
my $date = date_get();
while (my $post = $sth->fetchrow_hashref) {
$$post{'time_ago'} = time_ago($$post{'post_time'});
$$post{'post_time'} = date_get($$post{'post_time'});
push @output, $post;
}
Quote Reply
Re: [goman] Newest Thread on home page In reply to
Change:

$post_db->select;

to:

$post_db->select( { forum_id_fk => 1 });

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Newest Thread on home page In reply to
That did it, thanks Alex.
Quote Reply
Re: [Alex] Newest Thread on home page In reply to
How about selecting from a particular category and it's sub's; if not posible how do I select multiple forums?

$post_db->select( { forum_id_fk => 1 });

Thanks in advance
Quote Reply
Re: [yogi] Newest Thread on home page In reply to
when I display the URL of recent posts: .... /cgi-bin/forum/recent.cgi?number=5 i have it blank... any suggestion?

Thanks
Antoine
Quote Reply
Re: [antoined] Newest Thread on home page In reply to
 YOGI SCRIPT

For people less expert like me, change (if you have named the first file as display_recent_posts.html) :

$tpl->parse_print($path . '/templates/' . $templateset . '/external_display_recent_posts.html', {post_loop => \@output, number => $num, localtime=> $date});

to

$tpl->parse_print($path . '/templates/' . $templateset . '/display_recent_posts.html', {post_loop => \@output, number => $num, localtime=> $date});

Antoine

Last edited by:

antoined: May 8, 2004, 7:51 AM
Quote Reply
Re: [katabd] Newest Thread on home page In reply to
In Reply To:
Hi

I have tried your script and on the page I am using the SSI on (<!--#exec cgi="/cgi-bin/forum/recent.cgi?number=5"--> )

I am getting an error message:

[an error occurred while processing this directive]

Any suggestions

Yogi,

I'm having that problem as well. I get the error when I use exec cgi. If I use include virtual I get a blank page.
Any thoughts

ccunet
my Christian web
Quote Reply
Re: [ccunet] Newest Thread on home page In reply to
What is your page's name?
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Newest Thread on home page In reply to
KaTaBd

The display tempplate file is display_recent_posts.html

I've made the change in the recent,cgi file as mentioned above. But I'm still getting error. recent.cgi is in my forum directory I don't know if that makes a difference. Should it be somewhere else? Permissions are set correctly.

The page I'm calling it from is just a test page named Untiled.shtml

Do you have it working?


CCUnet
my Christian web

Last edited by:

ccunet: May 9, 2004, 4:55 AM
Quote Reply
Re: [ccunet] Newest Thread on home page In reply to
Hi

What I ended up using is different as this script keeps giving me headache.. (must likley me using it and not the script it self.)
Regards
KaTaBd

Users plug In - Multi Search And Remote Search plug in - WebRing plug in - Muslims Directory
Quote Reply
Re: [katabd] Newest Thread on home page In reply to
Actually got it working

http://www.mychristianweb.com/connections

Thanks for the help
CCUnet
my Christian web