Keyword

Creating a simple list of items in a category

  • Fjorten Syvogtredive (1437dk)
  • Fjorten Syvogtredive (1437dk)'s Avatar Topic Author
  • Offline
  • New Member
More
10 years 3 months ago - 10 years 3 months ago #129715 by Fjorten Syvogtredive (1437dk)
Creating a simple list of items in a category was created by Fjorten Syvogtredive (1437dk)
Hi, i'm rather new to K2, and i am desperately trying to make a list of my items in a specific category. Like this:

Attachment not found



…but i can't seem to find a detailed documentation list. I have created a copy of the default template, and started working on "category.php"-file, but i can't seem to get it to do exactly as i want.

Here is the code so far:
		
Attachments:

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 3 months ago #129716 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Creating a simple list of items in a category
K2 Uses sets of items.
Leading, Primary, Secondary and links.
I will not function properly without these loops (sets).

You need to adapt your template to the category.php template and ideally copy the looped item (tr) and paste it in category_item.php. This way the structure will resemble the default one, which means it will be managed easier.

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

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

  • Fjorten Syvogtredive (1437dk)
  • Fjorten Syvogtredive (1437dk)'s Avatar Topic Author
  • Offline
  • New Member
More
10 years 3 months ago #129717 by Fjorten Syvogtredive (1437dk)
Replied by Fjorten Syvogtredive (1437dk) on topic Re: Creating a simple list of items in a category
Hi Krikor.
Thanks for the reply. Sadly the reply is a bit over my technical-skills. I'm looking for the codes to:

1. pull the subcategory name
2. make the item a link
3. making the background of the list change every other row.

Here is what the code above currently generates:

Attachment not found



Do you by any chance know anywhere i can post this and pay someone to make this?
Attachments:

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 3 months ago #129718 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Creating a simple list of items in a category
The subcategories are present in K2's default template.
You can use that code.
		<?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 -->
					<div class="subCategoryDesc"><?php echo $subCategory->description; ?></div>
					<?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; ?>

For a quick solution I would look at Bootstrap's stripped tables. getbootstrap.com/css/#tables

Finally for the link use:
<a href="<?php echo $this->item->link; ?>">
  	  		<?php echo $this->item->title; ?>
  	  	</a>
Please note that in your case it might be $item->link etc..

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

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

  • Fjorten Syvogtredive (1437dk)
  • Fjorten Syvogtredive (1437dk)'s Avatar Topic Author
  • Offline
  • New Member
More
10 years 3 months ago #129719 by Fjorten Syvogtredive (1437dk)
Replied by Fjorten Syvogtredive (1437dk) on topic Re: Creating a simple list of items in a category
First off all thank you so much for helping me.

I might be doing something wrong, or pasting it the wrong place, but when i use the attached code the page just goes blank?

I'm not that familiar with PHP, so i can't seem to figure out where it all goes wrong. Where and in what file do i put the above code.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 3 months ago #129720 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Creating a simple list of items in a category
This code should be pasted in the category.php file. Above the $this->items = array_merge...

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

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

  • Fjorten Syvogtredive (1437dk)
  • Fjorten Syvogtredive (1437dk)'s Avatar Topic Author
  • Offline
  • New Member
More
10 years 2 months ago #129721 by Fjorten Syvogtredive (1437dk)
Replied by Fjorten Syvogtredive (1437dk) on topic Re: Creating a simple list of items in a category
Sorry for the late reply. And thanks for all the help.

I can't seem to find where to put the code? The word "array" is nowhere in my category.php-file?

I have made my own version - but the page loads very slow compared to the rest of the site. And the list does not honor when i set the titles not to link in the backend.

What am i doing wrong?
Log in  or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 2 months ago #129722 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Creating a simple list of items in a category
You can paste the subcategory code on top of your code.
I would advise you to use K2's leading/ primary... structure and not merging them.

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

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

  • Fjorten Syvogtredive (1437dk)
  • Fjorten Syvogtredive (1437dk)'s Avatar Topic Author
  • Offline
  • New Member
More
10 years 2 months ago - 10 years 2 months ago #129723 by Fjorten Syvogtredive (1437dk)
Replied by Fjorten Syvogtredive (1437dk) on topic Re: Creating a simple list of items in a category

Krikor Boghossian wrote: You can paste the subcategory code on top of your code.
I would advise you to use K2's leading/ primary... structure and not merging them.


I can't seem to get it to work and i'm not technical enough to understand what "K2's leading/ primary... structure" is.

What would it cost me to get you or someone else to make the code in the correct way, so it does not take 10-15 seconds to load the page?


Attachment not found

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
10 years 2 months ago #129724 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: Creating a simple list of items in a category
You might want to post this as a job.

You will understand the items structure if you open the default category.php.
Use that structure instead of merging all items.

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

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