boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

List categories along with posts

 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
daynah



Joined: 25 Jan 2002
Posts: 8

PostPosted: Mon Sep 09, 2002 6:20 pm    Post subject: List categories along with posts Reply with quote

I wrote this hack a few days ago. It's useful if you have a site using b2 that is more concerned with the Category type rather than the day of the post. For example, in the tutorials site, it is more important to view the archives by Category type rather than the date when it was posted. Another idea to use this script is for art galleries, photo gallery, etc. I'm not sure if anyone implemented it yet... but I wanted to share anyhow.

On with the hack...

In file b2-include/b2template.functions.php, after line 487 (or after the function list_cats()) ADD this function:

Code:

// out of the b2 loop -- added by Daynah
function list_cats_posts($optionall = 1, $all = 'All', $sort_column = 'ID', $sort_order = 'asc', $file = 'blah') {
        global $tablecategories,$querycount,$tableposts;
        global $pagenow;
        $file = ($file == 'blah') ? $pagenow : $file;
        $sort_column = 'cat_'.$sort_column;
        $query="SELECT * FROM $tablecategories WHERE cat_ID > 0 ORDER BY $sort_column $sort_order";
        $result=mysql_query($query);
        $querycount++;
        if (intval($optionall) == 1) {
                echo "\t<a href=\"$file?cat=all\">$all</a><br />\n";
        }
        while($row = mysql_fetch_object($result)) {
                echo "\t<a href=\"$file?cat=".$row->cat_ID."\">";
                echo stripslashes($row->cat_name)."</a><br />\n";

                // another while loop to print post titles
                $query2="SELECT * FROM $tableposts WHERE post_category ='$row->cat_ID' ORDER BY ID DESC";

                $result2=mysql_query($query2);

                $titlecount = 1;
                while($row2 = mysql_fetch_object($result2))
                {
                        echo "<span class=\"list_cats_post\">" . $titlecount . ") " .
                        "<a href=\"$file?p=" . $row2->ID . "more=1\">" .
                        stripslashes($row2->post_title) . "</a></span><br />\n";
                        $titlecount++;
                }

                echo '<br />';
        }
}


Wherever you want the list to show, just put:

Code:
<? list_cats_posts(0, 'All', 'id'); ?>


(This is if you put it on the main index.php page. If you would like it on a different page, it should look like this:

listing.php
Code:

<?php $blog=1; include ("blog.header.php"); ?>
<? list_cats_posts(0, 'All', 'id'); ?>


Demo: http://tutorials.php-princess.net/index.php?x=tutorials
Note: Most of the function is like Michel's list_cats() function, with some modification. Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
Eggatron



Joined: 25 Jan 2002
Posts: 55
Location: Aberdeen, Scotland

PostPosted: Mon Sep 09, 2002 9:58 pm    Post subject: Reply with quote

YAY! I tried to make something similar a few months ago, but I failed. Thank you.
_________________
eggatron.net
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
1705



Joined: 12 Sep 2002
Posts: 3

PostPosted: Thu Sep 12, 2002 6:31 am    Post subject: Error message Reply with quote

i receive this error message - thoughts?

Warning: Cannot add header information - headers already sent by (output started at /home/xxxx/public_html/xx/b2-include/b2template.functions.php:760) in /home/xxxx/public_html/xx/b2edit.php on line 156
Back to top
View user's profile Send private message
daynah



Joined: 25 Jan 2002
Posts: 8

PostPosted: Thu Sep 12, 2002 5:55 pm    Post subject: Reply with quote

Hmm, are you using the latest version of b2? If so, could you test it again by replacing it with this b2template.functions.php file?

* Please make backups before testing.
_________________
PHP Princess.net | Daynah.net
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
1705



Joined: 12 Sep 2002
Posts: 3

PostPosted: Thu Sep 12, 2002 6:05 pm    Post subject: More info Reply with quote

Sorry, it was late last night. I received this error after editing a story. The editing was successful, I was just stuck in this loop.

Tried this file, no change.
Back to top
View user's profile Send private message
kulai



Joined: 27 Apr 2002
Posts: 6
Location: Dipolog City, Philippnes

PostPosted: Fri Sep 13, 2002 3:24 pm    Post subject: How to show posts in specific category only? Reply with quote

i have tried the hack and i like it. however, i need to show whenever i click on a category to show the posts on that category only not all categories and their posts. please help. tnx
Back to top
View user's profile Send private message Visit poster's website
Edlef



Joined: 16 Mar 2002
Posts: 71

PostPosted: Sat Sep 14, 2002 6:57 am    Post subject: error Reply with quote

Hi Kulai,

please look at this topic:
http://tidakada.com/board/viewtopic.php?t=1003&highlight=
Back to top
View user's profile Send private message Visit poster's website
kulai



Joined: 27 Apr 2002
Posts: 6
Location: Dipolog City, Philippnes

PostPosted: Sat Sep 14, 2002 1:45 pm    Post subject: Reply with quote

thank you very much. i'll test and integrate this fix. :) :wink:
Back to top
View user's profile Send private message Visit poster's website
kulai



Joined: 27 Apr 2002
Posts: 6
Location: Dipolog City, Philippnes

PostPosted: Wed Oct 02, 2002 2:52 pm    Post subject: Reply with quote

ok i have read the link but it didn't answer my question.

let me rephrase it. How do i show the post in a specific category only using the hack?. i understand that putting the $cat= string on top of the page will always show the specific category first time the index page is accessed. but for me to show the list of posts using the hack when i access say "interest" category/link. the hack will only show the post in the category "interest". currently the hack will show all posts in all categories no matter what link/category you are in. i hope i made it clear.

thanks
Back to top
View user's profile Send private message Visit poster's website
sakurazuka_utena



Joined: 07 Aug 2003
Posts: 2

PostPosted: Tue Sep 30, 2003 10:03 pm    Post subject: Reply with quote

Nice hack Daynah, thx so much.

I have something to ask : how can I sort the posts in alphabetical order (by title) in each categories, using this hack ?

Categories are in alphabetical order, but I can't do the same with posts, which are sorted by date I think.
Back to top
View user's profile Send private message Visit poster's website
eak



Joined: 09 Sep 2003
Posts: 5
Location: Cheney, Washington

PostPosted: Sat Oct 18, 2003 8:00 pm    Post subject: Reply with quote

daynah wrote:
Hmm, are you using the latest version of b2? If so, could you test it again by replacing it with this b2template.functions.php file?

* Please make backups before testing.


I just tried this with this file, instead of editing the templates directly. (Tried that first, and messed it up. I'm not very knowledgeable about php, so I don't generally mess with it unless I can follow instructions like yours exactly.) It displays properly on my index.php page, but I'm getting all kinds of error messages on the login/logout page.

I'm getting this:

Warning: Cannot modify header information - headers already sent by (output started at /home/kissling/public_html/cmst414/b2-include/b2template.functions.php:760) in /home/kissling/public_html/cmst414/b2login.php on line 52

for six different line numbers!

Not sure what to do now - I can't even log out of my b2 page. Any advice?
_________________
Elizabeth A. Kissling
[email protected]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
eak



Joined: 09 Sep 2003
Posts: 5
Location: Cheney, Washington

PostPosted: Sat Oct 18, 2003 10:50 pm    Post subject: Reply with quote

Disregard my previous query. And have a laugh at the newbie. Smile

Persistence pays off. I continued to dig around in the forum for information about archiving by category instead of by date, and discovered that what I needed was a simple, one-line replacement in the template: <?php list_cats() ?> instead of <?php include("b2archives.php") ?>

This instruction was in the "readme" file, which I have read several times. It just took me a while to understand enough about how this works to realize that was what I was looking for!

Daynah, my apologies for emailing you with this. I do appreciate folks like your self offering advice and hints in forums like this.

-EAK
_________________
Elizabeth A. Kissling
[email protected]
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group