- Posts: 2
COMMUNITY FORUM
Category View Sub-Theme
- Alex
-
Topic Author
- Offline
- New Member
Less
More
10 years 3 months ago #140503
by Alex
Category View Sub-Theme was created by Alex
Hi,
I've been trying to create a category view using K2 which will display a table with a header row, followed by the extra field details of each of the items within a category.
I've managed to get this list to work and display items as intended but what I can't work out is how I can get this list to then link to the items in question so that if a user clicks on a part of each line it will open up that item (article). - I hope that makes sense.
The code I have so far is below and I want to add the link for each item to the Result field.
While I've been using Joomla for a number of years this is my first time with K2 so I'd appreciate any help you can provide.
I've been trying to create a category view using K2 which will display a table with a header row, followed by the extra field details of each of the items within a category.
I've managed to get this list to work and display items as intended but what I can't work out is how I can get this list to then link to the items in question so that if a user clicks on a part of each line it will open up that item (article). - I hope that makes sense.
The code I have so far is below and I want to add the link for each item to the Result field.
<?php
/**
* @version 2.6.x
* @package K2
* @author JoomlaWorks https://www.joomlaworks.net
* @copyright Copyright (c) 2006 - 2014 JoomlaWorks Ltd. All rights reserved.
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
*/
// no direct access
defined('_JEXEC') or die;
?>
<?php
$this->items = array_merge($this->leading, $this->primary, $this->secondary, $this->links);
?>
<!-- Start K2 Category Layout -->
<div id="k2Container" class="itemListView<?php if($this->params->get('pageclass_sfx')) echo ' '.$this->params->get('pageclass_sfx'); ?>">
<table width="100%">
<tr>
<th>Date</th>
<th>Opponent</th>
<th>H/A</th>
<th>Competition</th>
<th>Result</th>
<th>Value</th>
</tr>
<?php foreach($this->items as $item): ?>
<tr>
<td><?php echo $item->extraFields->Date->value ;?></td>
<td><?php echo $item->extraFields->Opponent->value ;?></td>
<td><?php echo $item->extraFields->HomeorAway>value ;?></td>
<td><?php echo $item->extraFields->Competition->value ;?></td>
<td><?php echo $item->extraFields->Result->value ;?></td>
<td><?php echo $item->extraFields->Scorers->value ;?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<!-- End K2 Category Layout -->
While I've been using Joomla for a number of years this is my first time with K2 so I'd appreciate any help you can provide.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 3 months ago #140546
by Krikor Boghossian
Replied by Krikor Boghossian on topic Category View Sub-Theme
Hello, you need add an <a> tag to these fields eg:
<a href="<?php echo $this->item->link; ?>"><?php echo $item->extraFields->Date->value ;?></a>
Please Log in or Create an account to join the conversation.
- Alex
-
Topic Author
- Offline
- New Member
Less
More
- Posts: 2
10 years 3 months ago #140562
by Alex
Replied by Alex on topic Category View Sub-Theme
Hi, thank you for your help. This didn't quite work but got me a lot closer.
When I added your code it did create a link but was instead linking direct to the root of the website.
After trying a few different modifications I discovered if I amended the <a> tag to the code below the link then worked:
Due to the way my original code is structured to redefine $this as $item.
When I added your code it did create a link but was instead linking direct to the root of the website.
After trying a few different modifications I discovered if I amended the <a> tag to the code below the link then worked:
<?php echo $item->link; ?>
Due to the way my original code is structured to redefine $this as $item.
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
Less
More
- Posts: 15920
10 years 3 months ago #140566
by Krikor Boghossian
Replied by Krikor Boghossian on topic Category View Sub-Theme
Nice to hear that you solved the issue :)
Please Log in or Create an account to join the conversation.