- Posts: 15
COMMUNITY FORUM
Extrafields names in category.php, for table headr
- Mark
- Topic Author
- Offline
- New Member
Less
More
10 years 9 months ago - 10 years 9 months ago #124774
by Mark
Extrafields names in category.php, for table headr was created by Mark
I'm looking to have my category listing page, show only extra field values. Everything else will be disabled, including the extra field name.
I need to know how to get the extra field names only for a particular category. Seeing as category groups are assigned to category level, this should be possible
The solution I'm looking for is almost exactly like this:
www.modernmagic.com/blog/joomla-technical-support/k2-table-like-list-in-category-view.html
Except, I'd like to make it a little more dynamic.
On category.php, I need the ability to get and echo extra_field->name
Then in category_item.php, I'll list only extra_field->value
The result I'm looking for would be a standard table grid, where row 1 headers are created in category.php and the table data is created in category_item.php
I hope this makes sense, please could someone assist me?
I need to know how to get the extra field names only for a particular category. Seeing as category groups are assigned to category level, this should be possible
The solution I'm looking for is almost exactly like this:
www.modernmagic.com/blog/joomla-technical-support/k2-table-like-list-in-category-view.html
Except, I'd like to make it a little more dynamic.
On category.php, I need the ability to get and echo extra_field->name
Then in category_item.php, I'll list only extra_field->value
The result I'm looking for would be a standard table grid, where row 1 headers are created in category.php and the table data is created in category_item.php
I hope this makes sense, please could someone assist me?
Please Log in or Create an account to join the conversation.
- Mark
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
10 years 9 months ago #124775
by Mark
Replied by Mark on topic Re: Extrafields names in category.php, for table headr
Another way that could work, is to only display the extra_field->name for the first item within category_item.php .. how could I do this?
Please Log in or Create an account to join the conversation.
- Yiota
- Visitor
10 years 9 months ago #124776
by Yiota
Replied by Yiota on topic Re: Extrafields names in category.php, for table headr
Since there is nothing else you will show in your category pages why don't you just use the category name to be the same with the extra field value and keep in all items of this category the extra field values?
Please Log in or Create an account to join the conversation.
- Mark
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
10 years 9 months ago #124777
by Mark
Replied by Mark on topic Re: Extrafields names in category.php, for table headr
I've got a few categories, they dont all share the same extra field groups
ie:
Category 1, will have extra fields: Col1, Col2, Col3
Category 2, will have extra fields: Col1, Col2, Col3, Col4
Category 3, will have extra fields: Col1, Col3, Col4
It would be much easier if i could generate the headers dynamically (ie; from whats in the database) rather than creating a seperate template for every category - cos that would then require a developer to be involved everytime client creates a new category
ie:
Category 1, will have extra fields: Col1, Col2, Col3
Category 2, will have extra fields: Col1, Col2, Col3, Col4
Category 3, will have extra fields: Col1, Col3, Col4
It would be much easier if i could generate the headers dynamically (ie; from whats in the database) rather than creating a seperate template for every category - cos that would then require a developer to be involved everytime client creates a new category
Please Log in or Create an account to join the conversation.
- Yiota
- Visitor
10 years 9 months ago #124778
by Yiota
Replied by Yiota on topic Re: Extrafields names in category.php, for table headr
Would you have a different extra field for the title which you want to show on top and then construct the rest of the extra fields values in a table?
Please Log in or Create an account to join the conversation.
- Mark
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
10 years 9 months ago #124779
by Mark
Replied by Mark on topic Re: Extrafields names in category.php, for table headr
This is the best way I can explain.. have a look at this image:
we-value-you.co.za/capture.PNG
This is achieved by manually editing
category.php like so:
<?php if(isset($this->primary) && count($this->primary)): ?>
<!-- Primary items -->
<div id="itemListPrimary">
<table width="100%" border=1>
<tr>
<th>Coil Size (mm)</th>
<th>Grade</th>
<th>Finish</th>
<th> </th>
</tr>
<?php foreach($this->primary as $key=>$item): ?>
<?php
// Define a CSS class for the last container on each row
if( (($key+1)%($this->params->get('num_primary_columns'))==0) || count($this->primary)<$this->params->get('num_primary_columns') )
$lastContainer= ' itemContainerLast';
else
$lastContainer='';
?>
<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->primary)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_primary_columns'), 1).'%;"'; ?>>
<?php
// Load category_item.php by default
$this->item=$item;
echo $this->loadTemplate('item');
?>
</div>
<?php if(($key+1)%($this->params->get('num_primary_columns'))==0): ?>
<div class="clr"></div>
<?php endif; ?>
<?php endforeach; ?>
</table>
<div class="clr"></div>
</div>
<?php endif; ?>
And in category_item.php (I've removed all other code) :
<!-- TR data -->
<tr>
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->value != ''): ?>
<td><span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span></td>
<?php endif; ?>
<?php endforeach; ?>
<td>
<!-- K2 Plugins: K2AfterDisplay -->
<?php echo $this->item->event->K2AfterDisplay; ?>
</td>
</tr>
The bit in category.php:
<tr>
<th>Coil Size (mm)</th>
<th>Grade</th>
<th>Finish</th>
<th> </th>
</tr>
I would like to automate this, by doing something like:
foreach ($this->????category????->extra_fields->name)
we-value-you.co.za/capture.PNG
This is achieved by manually editing
category.php like so:
<?php if(isset($this->primary) && count($this->primary)): ?>
<!-- Primary items -->
<div id="itemListPrimary">
<table width="100%" border=1>
<tr>
<th>Coil Size (mm)</th>
<th>Grade</th>
<th>Finish</th>
<th> </th>
</tr>
<?php foreach($this->primary as $key=>$item): ?>
<?php
// Define a CSS class for the last container on each row
if( (($key+1)%($this->params->get('num_primary_columns'))==0) || count($this->primary)<$this->params->get('num_primary_columns') )
$lastContainer= ' itemContainerLast';
else
$lastContainer='';
?>
<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->primary)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_primary_columns'), 1).'%;"'; ?>>
<?php
// Load category_item.php by default
$this->item=$item;
echo $this->loadTemplate('item');
?>
</div>
<?php if(($key+1)%($this->params->get('num_primary_columns'))==0): ?>
<div class="clr"></div>
<?php endif; ?>
<?php endforeach; ?>
</table>
<div class="clr"></div>
</div>
<?php endif; ?>
And in category_item.php (I've removed all other code) :
<!-- TR data -->
<tr>
<?php foreach ($this->item->extra_fields as $key=>$extraField): ?>
<?php if($extraField->value != ''): ?>
<td><span class="catItemExtraFieldsValue"><?php echo $extraField->value; ?></span></td>
<?php endif; ?>
<?php endforeach; ?>
<td>
<!-- K2 Plugins: K2AfterDisplay -->
<?php echo $this->item->event->K2AfterDisplay; ?>
</td>
</tr>
The bit in category.php:
<tr>
<th>Coil Size (mm)</th>
<th>Grade</th>
<th>Finish</th>
<th> </th>
</tr>
I would like to automate this, by doing something like:
foreach ($this->????category????->extra_fields->name)
Please Log in or Create an account to join the conversation.
- Yiota
- Visitor
10 years 9 months ago #124780
by Yiota
Replied by Yiota on topic Re: Extrafields names in category.php, for table headr
What if you add this code snippet in the category.php file right under the foreach of the items, wrapped in an if statement where it would show only the first item's label fields no matter if they would have values or not.
<?php if ($key==0) : ?>
<!-- TR data -->
<tr>
<?php foreach ($item->extra_fields as $key_2=>$extraField): ?>
<td><span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span></td>
<?php endforeach; ?>
<td>
</td>
</tr>
<?php endif; ?>
<?php if ($key==0) : ?>
<!-- TR data -->
<tr>
<?php foreach ($item->extra_fields as $key_2=>$extraField): ?>
<td><span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span></td>
<?php endforeach; ?>
<td>
</td>
</tr>
<?php endif; ?>
Please Log in or Create an account to join the conversation.
- Mark
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
10 years 9 months ago #124781
by Mark
Replied by Mark on topic Re: Extrafields names in category.php, for table headr
This solution would work perfectly!!!! Its exactly what I'm looking for HOWEVER, in your suggestion, $key resets to 0 on each new row :( Therefore, it always shows the extra_field->name
Any other way to do this?
Any other way to do this?
Please Log in or Create an account to join the conversation.
- Yiota
- Visitor
10 years 9 months ago #124782
by Yiota
Replied by Yiota on topic Re: Extrafields names in category.php, for table headr
Did you put in the foreach of the items, like
<?php foreach($this->leading as $key=>$item): ?>
<?php if ($key==0) : ?>
<!-- TR data -->
<tr>
<?php foreach ($item->extra_fields as $key_2=>$extraField): ?>
<td><span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span></td>
<?php endforeach; ?>
<td>
</td>
</tr>
<?php endif; ?>
......
continue with all other code
......
<?php endforeach; ?>
<?php foreach($this->leading as $key=>$item): ?>
<?php if ($key==0) : ?>
<!-- TR data -->
<tr>
<?php foreach ($item->extra_fields as $key_2=>$extraField): ?>
<td><span class="catItemExtraFieldsLabel"><?php echo $extraField->name; ?></span></td>
<?php endforeach; ?>
<td>
</td>
</tr>
<?php endif; ?>
......
continue with all other code
......
<?php endforeach; ?>
Please Log in or Create an account to join the conversation.
- Mark
- Topic Author
- Offline
- New Member
Less
More
- Posts: 15
10 years 9 months ago #124783
by Mark
Replied by Mark on topic Re: Extrafields names in category.php, for table headr
Yiota Ziaggou
You are a LEGEND!
THANK YOU!
You are a LEGEND!
THANK YOU!
Please Log in or Create an account to join the conversation.