Keyword

[SOLVED] Display extra fields in a table

  • eyeweiss
  • eyeweiss's Avatar Topic Author
  • Offline
  • New Member
More
9 years 11 months ago - 9 years 11 months ago #129364 by eyeweiss
Hola,
I have only little knowledge on html and CSS and getting quite desperate on an seemingly easy php-task:

I want to display articles with extra fields in a table. There should be 4 columns each showing one of the defined extra fields.

Like this:
<table>
<tr>
  <th>Typ</th>
  <th>Ort</th>
  <th>Datum</th>
  <th>Details</th>
</tr>
<tr>
  <td><?php echo $this->item->extraFields->Typ->value ;?></td>
  <td><?php echo $this->item->extraFields->Ort->value ;?></td>
  <td><?php echo $this->item->extraFields->Datum->value ;?></td>
  <td><?php echo $this->item->extraFields->Details->value ;?></td>
</tr>
</table>

I have added it to category_item.php but it then displays another table for each article. So, I guess I have to work on category.php but I can't figure out, where to insert my table.

I was searching on several other pages but still couldn't realize it.
Link 1
Link 2
Link 3
Link 4

Thanks for any help.
eyeweiss

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #129365 by Lefteris
Replied by Lefteris on topic Re: Display extra fields in a table
Hi. Each item has it's own extra fields so since you are inside a loop each item will have it's own extra fields table. What's the result you are trying to achieve?

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • eyeweiss
  • eyeweiss's Avatar Topic Author
  • Offline
  • New Member
More
9 years 11 months ago - 9 years 11 months ago #129366 by eyeweiss
Replied by eyeweiss on topic Re: Display extra fields in a table
A table should be generated which displays the extra fields of each article per row.

I'll try to visualize it here:
TypeDatePlaceDetails
Basic02.02.2014WienLink1
Advanced03.03.2014LondonLink2
............

I almost get there by using these instructions , but then I have an unordered list which is not as nice to handle as a table (eg. not sortable).

Thanks a lot.
eyeweiss

Please Log in or Create an account to join the conversation.

More
9 years 11 months ago #129367 by Lefteris
Replied by Lefteris on topic Re: Display extra fields in a table
I suggest to first read getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates . Then create an override for category.php and use the following code:
<table>
<tr>
  <th>Typ</th>
  <th>Ort</th>
  <th>Datum</th>
  <th>Details</th>
</tr>
<?php foreach($this->items as $item): ?>
<tr>
  <td><?php echo $item->extraFields->Typ->value ;?></td>
  <td><?php echo $item->extraFields->Ort->value ;?></td>
  <td><?php echo $item->extraFields->Datum->value ;?></td>
  <td><?php echo $item->extraFields->Details->value ;?></td>
</tr>
<?php endforeach; ?>
</table>

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • eyeweiss
  • eyeweiss's Avatar Topic Author
  • Offline
  • New Member
More
9 years 11 months ago - 9 years 11 months ago #129368 by eyeweiss
Replied by eyeweiss on topic Re: Display extra fields in a table
Thanks, Lefteris. Your code makes sense to me :). Still, it does not display any item - but it displays the headings.

It seems like it does not has acces to the "items". I deleted anything in category.php and replaced it by your suggested code. Could that be the error? Do I have to keep some parts of the original category.php? Do I have to insert the new code at some particular line?

PS: It defintitely "uses" the new category.php e.g. the table width changes, if I edit it in the new file.


Original code:
<?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;

?>

<!-- Start K2 Category Layout -->
<div id="k2Container" class="itemListView<?php if($this->params->get('pageclass_sfx')) echo ' '.$this->params->get('pageclass_sfx'); ?>">

	<?php if($this->params->get('show_page_title')): ?>
	<!-- Page title -->
	<div class="componentheading<?php echo $this->params->get('pageclass_sfx')?>">
		<?php echo $this->escape($this->params->get('page_title')); ?>
	</div>
	<?php endif; ?>

	<?php if($this->params->get('catFeedIcon')): ?>
	<!-- RSS feed icon -->
	<div class="k2FeedIcon">
		<a href="<?php echo $this->feed; ?>" title="<?php echo JText::_('K2_SUBSCRIBE_TO_THIS_RSS_FEED'); ?>">
			<span><?php echo JText::_('K2_SUBSCRIBE_TO_THIS_RSS_FEED'); ?></span>
		</a>
		<div class="clr"></div>
	</div>
	<?php endif; ?>

	<?php if(isset($this->category) || ( $this->params->get('subCategories') && isset($this->subCategories) && count($this->subCategories) )): ?>
	<!-- Blocks for current category and subcategories -->
	<div class="itemListCategoriesBlock">

		<?php if(isset($this->category) && ( $this->params->get('catImage') || $this->params->get('catTitle') || $this->params->get('catDescription') || $this->category->event->K2CategoryDisplay )): ?>
		<!-- Category block -->
		<div class="itemListCategory">

			<?php if(isset($this->addLink)): ?>
			<!-- Item add link -->
			<span class="catItemAddLink">
				<a class="modal" rel="{handler:'iframe',size:{x:990,y:650}}" href="<?php echo $this->addLink; ?>">
					<?php echo JText::_('K2_ADD_A_NEW_ITEM_IN_THIS_CATEGORY'); ?>
				</a>
			</span>
			<?php endif; ?>

			<?php if($this->params->get('catImage') && $this->category->image): ?>
			<!-- Category image -->
			<img alt="<?php echo K2HelperUtilities::cleanHtml($this->category->name); ?>" src="<?php echo $this->category->image; ?>" style="width:<?php echo $this->params->get('catImageWidth'); ?>px; height:auto;" />
			<?php endif; ?>

			<?php if($this->params->get('catTitle')): ?>
			<!-- Category title -->
			<h2><?php echo $this->category->name; ?><?php if($this->params->get('catTitleItemCounter')) echo ' ('.$this->pagination->total.')'; ?></h2>
			<?php endif; ?>

			<?php if($this->params->get('catDescription')): ?>
			<!-- Category description -->
			<p><?php echo $this->category->description; ?></p>
			<?php endif; ?>

			<!-- K2 Plugins: K2CategoryDisplay -->
			<?php echo $this->category->event->K2CategoryDisplay; ?>

			<div class="clr"></div>
		</div>
		<?php endif; ?>

		<?php if($this->params->get('subCategories') && isset($this->subCategories) && count($this->subCategories)): ?>
		<!-- Subcategories -->
		<div class="itemListSubCategories">
			<h3><?php echo JText::_('K2_CHILDREN_CATEGORIES'); ?></h3>

			<?php foreach($this->subCategories as $key=>$subCategory): ?>

			<?php
			// Define a CSS class for the last container on each row
			if( (($key+1)%($this->params->get('subCatColumns'))==0))
				$lastContainer= ' subCategoryContainerLast';
			else
				$lastContainer='';
			?>

			<div class="subCategoryContainer<?php echo $lastContainer; ?>"<?php echo (count($this->subCategories)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('subCatColumns'), 1).'%;"'; ?>>
				<div class="subCategory">
					<?php if($this->params->get('subCatImage') && $subCategory->image): ?>
					<!-- Subcategory image -->
					<a class="subCategoryImage" href="<?php echo $subCategory->link; ?>">
						<img alt="<?php echo K2HelperUtilities::cleanHtml($subCategory->name); ?>" src="<?php echo $subCategory->image; ?>" />
					</a>
					<?php endif; ?>

					<?php if($this->params->get('subCatTitle')): ?>
					<!-- Subcategory title -->
					<h2>
						<a href="<?php echo $subCategory->link; ?>">
							<?php echo $subCategory->name; ?><?php if($this->params->get('subCatTitleItemCounter')) echo ' ('.$subCategory->numOfItems.')'; ?>
						</a>
					</h2>
					<?php endif; ?>

					<?php if($this->params->get('subCatDescription')): ?>
					<!-- Subcategory description -->
					<p><?php echo $subCategory->description; ?></p>
					<?php endif; ?>

					<!-- Subcategory more... -->
					<a class="subCategoryMore" href="<?php echo $subCategory->link; ?>">
						<?php echo JText::_('K2_VIEW_ITEMS'); ?>
					</a>

					<div class="clr"></div>
				</div>
			</div>
			<?php if(($key+1)%($this->params->get('subCatColumns'))==0): ?>
			<div class="clr"></div>
			<?php endif; ?>
			<?php endforeach; ?>

			<div class="clr"></div>
		</div>
		<?php endif; ?>

	</div>
	<?php endif; ?>



	<?php if((isset($this->leading) || isset($this->primary) || isset($this->secondary) || isset($this->links)) && (count($this->leading) || count($this->primary) || count($this->secondary) || count($this->links))): ?>
	<!-- Item list -->
	<div class="itemList">

		<?php if(isset($this->leading) && count($this->leading)): ?>
		<!-- Leading items -->
		<div id="itemListLeading">
			<?php foreach($this->leading as $key=>$item): ?>

			<?php
			// Define a CSS class for the last container on each row
			if( (($key+1)%($this->params->get('num_leading_columns'))==0) || count($this->leading)<$this->params->get('num_leading_columns') )
				$lastContainer= ' itemContainerLast';
			else
				$lastContainer='';
			?>
			
			<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->leading)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_leading_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_leading_columns'))==0): ?>
			<div class="clr"></div>
			<?php endif; ?>
			<?php endforeach; ?>
			<div class="clr"></div>
		</div>
		<?php endif; ?>

		<?php if(isset($this->primary) && count($this->primary)): ?>
		<!-- Primary items -->
		<div id="itemListPrimary">
			<?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; ?>
			<div class="clr"></div>
		</div>
		<?php endif; ?>

		<?php if(isset($this->secondary) && count($this->secondary)): ?>
		<!-- Secondary items -->
		<div id="itemListSecondary">
			<?php foreach($this->secondary as $key=>$item): ?>
			
			<?php
			// Define a CSS class for the last container on each row
			if( (($key+1)%($this->params->get('num_secondary_columns'))==0) || count($this->secondary)<$this->params->get('num_secondary_columns') )
				$lastContainer= ' itemContainerLast';
			else
				$lastContainer='';
			?>
			
			<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->secondary)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_secondary_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_secondary_columns'))==0): ?>
			<div class="clr"></div>
			<?php endif; ?>
			<?php endforeach; ?>
			<div class="clr"></div>
		</div>
		<?php endif; ?>

		<?php if(isset($this->links) && count($this->links)): ?>
		<!-- Link items -->
		<div id="itemListLinks">
			<h4><?php echo JText::_('K2_MORE'); ?></h4>
			<?php foreach($this->links as $key=>$item): ?>

			<?php
			// Define a CSS class for the last container on each row
			if( (($key+1)%($this->params->get('num_links_columns'))==0) || count($this->links)<$this->params->get('num_links_columns') )
				$lastContainer= ' itemContainerLast';
			else
				$lastContainer='';
			?>

			<div class="itemContainer<?php echo $lastContainer; ?>"<?php echo (count($this->links)==1) ? '' : ' style="width:'.number_format(100/$this->params->get('num_links_columns'), 1).'%;"'; ?>>
				<?php
					// Load category_item_links.php by default
					$this->item=$item;
					echo $this->loadTemplate('item_links');
				?>
			</div>
			<?php if(($key+1)%($this->params->get('num_links_columns'))==0): ?>
			<div class="clr"></div>
			<?php endif; ?>
			<?php endforeach; ?>
			<div class="clr"></div>
		</div>
		<?php endif; ?>

	</div>

	<!-- Pagination -->
	<?php if($this->pagination->getPagesLinks()): ?>
	<div class="k2Pagination">
		<?php if($this->params->get('catPagination')) echo $this->pagination->getPagesLinks(); ?>
		<div class="clr"></div>
		<?php if($this->params->get('catPaginationResults')) echo $this->pagination->getPagesCounter(); ?>
	</div>
	<?php endif; ?>

	<?php endif; ?>
</div>
<!-- End K2 Category Layout -->

New code:
<?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;
?>
<!-- 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>Typ</th>
  <th>Ort</th>
  <th>Datum</th>
  <th>Details</th>
</tr>
<?php foreach($this->items as $item): ?>
<tr>
  <td><?php echo $item->extraFields->Typ->value ;?></td>
  <td><?php echo $item->extraFields->Ort->value ;?></td>
  <td><?php echo $item->extraFields->Datum->value ;?></td>
  <td><?php echo $item->extraFields->Details->value ;?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<!-- End K2 Category Layout -->

Please Log in or Create an account to join the conversation.

More
9 years 10 months ago #129369 by Lefteris
Replied by Lefteris on topic Re: Display extra fields in a table
In category view the items are split to groups ( leading, primary etc. ). We need to merge them before the loop. Try to add this code in the begining of the file:
<?php
$this->items = array_merge($this->leading, $this->primary, $this->secondary, $this->links); 
?>

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

  • eyeweiss
  • eyeweiss's Avatar Topic Author
  • Offline
  • New Member
More
9 years 10 months ago #129370 by eyeweiss
Replied by eyeweiss on topic Re: Display extra fields in a table
He, that made my day. Thanks a lot, Lefteris! Works perfectly.

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum