Enthusiast: Categorising "All Categories" in show_joined.php
This was requested from a user at the The Fanlistings Network Message Board », and once again decided to post it over here! Note: I've tried this with version 3.1.4 and 3.1.5.
1st Step
Open show_joined.php in the editor of your choice—whether that be a HTML or text editor—and go to line 233 and find the following line of code:
$ids = array();
Below that line you will find the following block of code:
if( $_GET['cat'] == 'all' )
$ids = get_joined();
else if( $_GET['cat'] == 'pending' )
$ids = get_joined( 'pending' );
else
$ids = get_joined_by_category( clean( $_GET['cat'] ) );
echo get_setting( 'joined_template_header' );
foreach( $ids as $id )
echo parse_joined_template( $id );
echo get_setting( 'joined_template_footer' );
Which I want you to change to:
if( $_GET['cat'] == 'all' ) {
}
else {
if( $_GET['cat'] == 'pending' )
$ids = get_joined( 'pending' );
else
$ids = get_joined_by_category( clean( $_GET['cat'] ) );
echo get_setting( 'joined_template_header' );
foreach( $ids as $id )
echo parse_joined_template( $id );
echo get_setting( 'joined_template_footer' );
}
Bit by Bit
I'm going to add each line of code with an explanation to describe what each line is doing; if you'd like to skip to the whole block of code, you » can do so! ;)
First off, we're going to add this line right after if( $_GET['cat'] == 'all' ) {:
$all_joined_cats = get_categories();
What this is doing is gathering all of the categories (by ID) into an array (that's what the get_categories() function is for), under a variables. The next line is to obviously break up the categories by way of foreach():
$all_joined_cats = get_categories();
foreach($all_joined_cats as $ajc) {
Now we can apply a bit of coding to each category! Underneath that, we're going to add the following line:
$all_joined_cats = get_categories();
foreach($all_joined_cats as $ajc) {
$ajcid = $ajc['catid'];
What I'm doing isn't strictly necessary (the method can be accomplished by $ajc['catid'], but I'm puting this variables underneath another variable, so when go to select the joined listings from this category, we have a regular variable. Coming up? Pulling up the joined listings from the joined table!
$all_joined_cats = get_categories();
foreach($all_joined_cats as $ajc) {
$ajcid = $ajc['catid'];
$select = @mysql_query("SELECT * FROM `$db_joined` WHERE `catid` LIKE '%|$ajcid|%'");
Normally I split the query and the mysql_query() function into two variables, but I decided to save space. As I stated before, this is pulling the joined listings from the category (this is any category—the foreach() function loops through all categories). The next line of code is making sure there is joined listings under the category, so we're going to issue the mysql_num_rows() function:
$all_joined_cats = get_categories();
foreach($all_joined_cats as $ajc) {
$ajcid = $ajc['catid'];
$select = @mysql_query("SELECT * FROM `$db_joined` WHERE `catid` LIKE '%|$ajcid|%'");
if(mysql_num_rows($select) > 0) {
Assuming we do have joined listings under this category, let's continue! The next line is the header of the category. This is starting the <div> and the title of the category:
$all_joined_cats = get_categories();
foreach($all_joined_cats as $ajc) {
$ajcid = $ajc['catid'];
$select = @mysql_query("SELECT * FROM `$db_joined` WHERE `catid` LIKE '%|$ajcid|%'");
if(mysql_num_rows($select) > 0) {
echo "<div id=\"category$ajcid\"><strong>" . $ajc['catname'] . "</strong><br />\n";
This line can be changed to however you wish for it to look (perhaps adding <h2>, etc.), this is just for example's sake. The next line would be another array-in-function line, which is grabbing the actual joined listings!
$all_joined_cats = get_categories();
foreach($all_joined_cats as $ajc) {
$ajcid = $ajc['catid'];
$select = @mysql_query("SELECT * FROM `$db_joined` WHERE `catid` LIKE '%|$ajcid|%'");
if(mysql_num_rows($select) > 0) {
echo "<div id=\"category$ajcid\"><strong>" . $ajc['catname'] . "</strong><br />\n";
$alljc = get_joined_by_category($ajcid);
As stated above, this grabs the joined listings from the category currently being looped through. The next line is echoing the header template for your joined listings. This is only partially a necessity, mainly centred on valid coding:
$all_joined_cats = get_categories();
foreach($all_joined_cats as $ajc) {
$ajcid = $ajc['catid'];
$select = @mysql_query("SELECT * FROM `$db_joined` WHERE `catid` LIKE '%|$ajcid|%'");
if(mysql_num_rows($select) > 0) {
echo "<div id=\"category$ajcid\"><strong>" . $ajc['catname'] . "</strong><br />\n";
$alljc = get_joined_by_category($ajcid);
echo get_setting( 'joined_template_header' );
The next is another foreach() loop, which will loops through all joined listings—this is so we can apply the joined template to each joined listing:
$all_joined_cats = get_categories();
foreach($all_joined_cats as $ajc) {
$ajcid = $ajc['catid'];
$select = @mysql_query("SELECT * FROM `$db_joined` WHERE `catid` LIKE '%|$ajcid|%'");
if(mysql_num_rows($select) > 0) {
echo "<div id=\"category$ajcid\"><strong>" . $ajc['catname'] . "</strong><br />\n";
$alljc = get_joined_by_category($ajcid);
echo get_setting( 'joined_template_header' );
foreach($alljc as $a) {
As stated above, we are now going to add the joined template (for each joined listing)—this is necessary, as this is how we're displaying the joined listing:
$all_joined_cats = get_categories();
foreach($all_joined_cats as $ajc) {
$ajcid = $ajc['catid'];
$select = @mysql_query("SELECT * FROM `$db_joined` WHERE `catid` LIKE '%|$ajcid|%'");
if(mysql_num_rows($select) > 0) {
echo "<div id=\"category$ajcid\"><strong>" . $ajc['catname'] . "</strong><br />\n";
$alljc = get_joined_by_category($ajcid);
echo get_setting( 'joined_template_header' );
foreach($alljc as $a) {
echo parse_joined_template($a);
The next bit of coding will be the ending bracket for the foreach() loop, the footer template, the ending DIV (not required), the closing bracket from the first foreach() loop and the closing bracket from the if() statement:
$all_joined_cats = get_categories();
foreach($all_joined_cats as $ajc) {
$ajcid = $ajc['catid'];
$select = @mysql_query("SELECT * FROM `$db_joined` WHERE `catid` LIKE '%|$ajcid|%'");
if(mysql_num_rows($select) > 0) {
echo "<div id=\"category$ajcid\"><strong>" . $ajc['catname'] . "</strong><br />\n";
$alljc = get_joined_by_category($ajcid);
echo get_setting( 'joined_template_header' );
foreach($alljc as $a) {
echo parse_joined_template($a);
}
echo get_setting( 'joined_template_footer' );
echo "</div>";
}
}
Besides the echo "<div>"; line, the last bit of coding is required. Finally, we are done! Once you hit "All listings", you will now view all your joined listings sorted by category! :D If you are uncomfortable messing with the coding, the file is available for download on » the download page!
Preview
Click the image below to be taken to an example of a working version of this mod—please note this is an old version of my joined listings, so a good number of links will be defunct.
Comments
Currently no comments!
