Display Category Name not Category ID

9 posts by 4 authors in: Forums > CMS Builder
Last Post: March 15, 2011   (RSS)

Hello,

For some reason I am unable to display the category name of a listing on my listings.php page.

I am using the following code:

<?php foreach ($listingRecords as $listing): ?>

<li class="mark">
<strong><?php echo $listing['category'] ?></strong>
<h3><a href="<?php echo $listing['_link'] ?>"><?php echo $listing['product'] ?></a></h3>
<div class="text">
<?php foreach ($listing['uploads'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<a href="<?php echo $listing['_link'] ?>"><img class="image" src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" border="0" title="<?php echo $upload['info1'] ?>" alt="<?php echo $upload['info1'] ?>" /></a><br/>
<?php break ?>
<?php endif; ?>
<?php endforeach ?>


The following part of the code...

<?php echo $listing['category'] ?>

... displays the category ID number, not the name of the category.

Can you help me out please?

Thank you,
Greg

Re: [gversion] Display Category Name not Category ID

By Damon - September 19, 2010

Hi Greg,

If you are using version 2.04 or higher of CMS Builder you can use this code:

$listing['category:label']

Instead of displaying the category number, it will display the category label (name).

Give that a try. Hope that helps.
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] Display Category Name not Category ID

Hi,

Thanks for the message.

I am using v2.06 and inserted the code as you suggested but now receive the following error:

Notice: Undefined index: category:name in /home/sites/mydomain.co.uk/public_html/listings.php on line 81

I'd be very grateful if you could help me fix this.

Thank you,
Greg

Re: [gversion] Display Category Name not Category ID

Hi Damon,

Thanks again for your help. I tried updating the website again and this time it worked!

Thanks very much!!

Greg

Re: [gversion] Display Category Name not Category ID

By Damon - September 20, 2010

Thanks for the update!

Glad to hear it is now working.
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] Display Category Name not Category ID

Hi Damon,

I have now created a page called viewCats.php, which I would like to display all the listings in a specific category.

I have got the listings to appear correctly, so if I use the URL viewCats.php?category=6, only listings belonging to the category with id 6 are displayed.

However, on this page I would like the heading to be:

Browse: {{Parent Category}} - {{Category Name}}

I have inserted the following code so far but it's not working correctly:

===========================

<?php

require_once "init.php";

list($listingRecords, $listingDetails) = getRecords(array(
'tableName' => 'listings',
'joinTable' => 'homepages',

));

?>

<?php
require_once "cmsAdmin/lib/viewer_functions.php";
list($categoryRecords, $categoryMetaData) = getRecords(array(
'tableName' => 'category',
'where' => whereRecordNumberInUrl(1),
));
$categoryRecord = @$categoryRecords[0]; // get first record
?>

<?php include "include_header.php"; ?>


<h3>Browse: <?php echo $categoryRecords['parentNum'] ?> - <?php echo $categoryRecords['name'] ?></h3>


... code continues to display listings...

==========================

Can you give me some more help please?

Despite reading the support docs, I still haven't quite got my head around what's required in order to display field values on a page. Any explanation would be really appreciated.

Thank you very much.

Best wishes,
Greg

Re: [Chris] Display Category Name not Category ID

By Djulia - March 15, 2011

Hi Chris,

I have a problem with getCategories.

My URL has a numeric value and getCategories seems to use this first value (2 in example) :

list.php/card-2d?cat=11

Do You think that it is possible to circumvent this problem ?

Is It perhaps possible to use the example of Dave ?
http://www.interactivetools.com/iforum/gforum.cgi?post=80852;search_string=%20%24lastNumber%20%3D%20%24matches%5B1%5D;t=search_engine#80852

Thanks for your suggestion ! :)

Djulia

Re: [Chris] Display Category Name not Category ID

By Djulia - March 15, 2011 - edited: March 15, 2011

The problem is corrected with your post :
http://www.interactivetools.com/forum/gforum.cgi?post=82675#82675

Thanks ! :)

Djulia