View previous topic :: View next topic |
Author |
Message |
sidcarter
Joined: 18 Sep 2002 Posts: 8
|
Posted: Thu Oct 17, 2002 2:32 pm Post subject: And updated version of the hack ( Scalable ;) ) |
|
|
Of course, this hack does not show date and time. This hack makes it easier in case you want search friendly urls.
Code: |
<?
include ("blog.header.php");
dbconnect();
$query = "SELECT ID, post_title FROM b2posts ORDER BY post_date DESC LIMIT 10";
$result = mysql_query($query);
while ($data = mysql_fetch_row($result)) {
echo "<a href=\"$siteurl/".$blogfilename.$querystring_start.'p'.$querystring_equal."$data[0]\">$data[1]</a><br />\n";
}
?>
|
|
|
Back to top |
|
 |
Cyberian75
Joined: 26 Sep 2002 Posts: 1052 Location: Oregon
|
Posted: Thu Oct 17, 2002 11:07 pm Post subject: |
|
|
I rewrote it into a function, which you can include in b2template_functions.php . . .
Code: |
function posttitles($lim) {
global $tableposts,$querycount;
$result = mysql_query("select ID, post_title FROM $tableposts ORDER BY post_date DESC LIMIT $lim");
$querycount++;
while ($data = mysql_fetch_row($result)) {
echo "<a href=\"index.php?p=$data[0]\">$data[1]</a><br>\n";
}
}
|
With this function, you can define the number of post titles to display just by passing a numerical parameter; i.e., posttitles(10). However, I believe you have to call this function outside the b2 loop.
Michael P _________________ Michael P. |
|
Back to top |
|
 |
hellhound
Joined: 24 Oct 2002 Posts: 38
|
Posted: Sat Oct 26, 2002 10:16 pm Post subject: |
|
|
hmm in above all codes i got this error
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in ** on line 6 or 9 (i try dif 2 codes) |
|
Back to top |
|
 |
Jeevan
Joined: 11 May 2002 Posts: 16
|
Posted: Sun Apr 06, 2003 4:01 pm Post subject: |
|
|
Try this, not sure if I did anything wrong, but it's working fine on my site:
[php:1:4234b3b6fa]<?
dbconnect();
$query = "SELECT ID, post_title FROM b2posts ORDER BY post_date DESC LIMIT 10";
$headline = mysql_query($query);
while ($data = mysql_fetch_row($headline)) {
echo "<a href=\"?p=$data[0]\">$data[1]</a><br>\n";
}
?>[/php:1:4234b3b6fa]
Then include the file where you want it to be. _________________ Jeevan |
|
Back to top |
|
 |
benmarsh
Joined: 04 May 2003 Posts: 4
|
Posted: Tue May 06, 2003 7:05 am Post subject: |
|
|
i just put this together;
might be useful if you're having problems with the $query interfering with the b2loop's $query try this;
Code: | <?php
$headline = mysql_query("SELECT ID, post_title FROM b2posts ORDER BY post_date DESC LIMIT 10");
while ($data = mysql_fetch_row($headline)) {
echo "<a href=\"?p=$data[0]\">$data[1]</a><br>\n";
}
?> |
just make sure it is out of the loop but you can put it anywhere in the page as it does not affect $query. to make changes to $headline - modify the 'mysql_query' term string.
ben  |
|
Back to top |
|
 |
kappaluppa
Joined: 24 Oct 2003 Posts: 2
|
Posted: Fri Oct 24, 2003 6:55 am Post subject: |
|
|
This worked, but how do i get stripslashes working so my ' dont end up \' ?
thanks
k |
|
Back to top |
|
 |
Aredubya
Joined: 19 Nov 2003 Posts: 5
|
Posted: Wed Nov 19, 2003 1:55 pm Post subject: |
|
|
Hi folks,
I'm trying to get a function like this working under b2, although the listing query would be a bit different. Rather than list and order by the date/time of the specific posts, I'd like to list and order based on the time of the most recent comments. You can see an example of the sort of function I'd want from my friend's site (who doesn't run b2 ) at http://spite.com, under the "Talk Amongst Yourselves" section. Thanks for any assistance.
Aredubya, http://blog.netho.net/ |
|
Back to top |
|
 |
XianghuaALPHA
Joined: 05 Aug 2003 Posts: 79 Location: Tulsa, OK
|
Posted: Tue Jan 27, 2004 3:48 am Post subject: yea, THIS hack had to pull me in today didn't it.... |
|
|
Okay, talking to me like I'm a lil 5 yr old - because after a good 40 minutes trying to get this to work on another page- and then seeing that it wouldn't - but it would on my b2 page - makes me feel REALLY stupid.
A - is this a solution I can use on another php page - outside the dir - just by making the call /blog/b2headlines.php blah lbah balh... I tried - and it wouldn't work
If A is possible....
then...
B - how do I do that?
If A is not possible...
then...
C - is there a way?
and then...
D - the hack with the small tiem code is cool - I see like 5 MORE VERSIONS OF THIS HACK [yes I tried them all too on my other page and yea] and like yea - which is the best for including the time and yea? Once again - like a FIVE YEAR OLD PLEASE
Yea - I appreciate the help here, I am just very frustrated with it also for not working on my other page - I APPRECIATE the help ahead of tiem
X A _________________ [ [ - - There can be only 2 or 3 - - ]]
You know what. On a quite board - you end up talking to yourself alot....
Friends don't let friends play Tekken |
|
Back to top |
|
 |
XianghuaALPHA
Joined: 05 Aug 2003 Posts: 79 Location: Tulsa, OK
|
Posted: Tue Jan 27, 2004 4:25 am Post subject: |
|
|
Oh yea - and Iv'e got it working on my actual blog - but for the LIFE OF ME I CANNOT GET IT TO DISPLAY THE DAMN am vs pm THIGN!@ a ='s FRI or SUN or yea - the three letter date for somereasin!?!~@
I've tried....
Code: | $result = mysql_query("select ID, DATE_FORMAT(post_date, '%m.%d.%y - %h:%i.%a'), post_title FROM posts ORDER BY post_date DESC LIMIT 5");
|
and
Code: | $result = mysql_query("select ID, DATE_FORMAT(post_date, '%m%.%d%.%y %- %h%:%i%.%a'), post_title FROM posts ORDER BY post_date DESC LIMIT 5");
|
and even this now
Code: | $result = mysql_query("select ID, DATE_FORMAT(post_date, '%m%.%d%.%y %- %h%:%i%.%A'), post_title FROM posts ORDER BY post_date DESC LIMIT 5");
|
NO LOVe. So yea - anyone. Help. Please.
X A _________________ [ [ - - There can be only 2 or 3 - - ]]
You know what. On a quite board - you end up talking to yourself alot....
Friends don't let friends play Tekken |
|
Back to top |
|
 |
XianghuaALPHA
Joined: 05 Aug 2003 Posts: 79 Location: Tulsa, OK
|
Posted: Thu Jan 29, 2004 4:40 pm Post subject: |
|
|
Okay - while I've YET to figure out why it hates on my damn AM vs PM thing - I solved it with 'ish' at the end of them all - I do have some answers for myself at least....
A - no - it calls the header to include, and thus if your page is outside b2's dir - making since since it'd probably be a FRONT PAGE OF YOUR SITE deal, then no, the include couldn't call and have all it's includes work blah blah balh.
Thus - B = a no go.
C ='s yes though and is discribed here -
http://cafelog.com/board/viewtopic.php?p=22611#22611
D ='s all the coder's different styles of work - plus the ammount of quieries? Something like that - basically the original is written to call several times more than is actually needed or somethign, and thus is harder on the server? And the pretty shineyer versions - not so much.
Good times - if anyone want's yet ANOTHER version of this, I think I can put it up, and if your looking for solutions as I was - check out that link above.
X A _________________ [ [ - - There can be only 2 or 3 - - ]]
You know what. On a quite board - you end up talking to yourself alot....
Friends don't let friends play Tekken |
|
Back to top |
|
 |
fro
Joined: 21 Jul 2004 Posts: 2
|
Posted: Wed Jul 21, 2004 3:45 pm Post subject: |
|
|
Sorry for bring back such an old topic, but is there anyway to make this category specific? Lets say I want to get 5 headlines from sports on one page, and 5 headlines from news on another... is this possible? |
|
Back to top |
|
 |
|