- Posts: 11
COMMUNITY FORUM
Creating a simple list of items in a category
- Fjorten Syvogtredive (1437dk)
-
Topic Author
- Offline
- New Member
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:
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
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.
Please Log in or Create an account to join the conversation.
- Fjorten Syvogtredive (1437dk)
-
Topic Author
- Offline
- New Member
- Posts: 11
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?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
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 Log in or Create an account to join the conversation.
- Fjorten Syvogtredive (1437dk)
-
Topic Author
- Offline
- New Member
- Posts: 11
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
-
- Offline
- Platinum Member
- Posts: 15920
Please Log in or Create an account to join the conversation.
- Fjorten Syvogtredive (1437dk)
-
Topic Author
- Offline
- New Member
- Posts: 11
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
-
- Offline
- Platinum Member
- Posts: 15920
I would advise you to use K2's leading/ primary... structure and not merging them.
Please Log in or Create an account to join the conversation.
- Fjorten Syvogtredive (1437dk)
-
Topic Author
- Offline
- New Member
- Posts: 11
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
-
- Offline
- Platinum Member
- Posts: 15920
You will understand the items structure if you open the default category.php.
Use that structure instead of merging all items.
Please Log in or Create an account to join the conversation.
- Fjorten Syvogtredive (1437dk)
-
Topic Author
- Offline
- New Member
- Posts: 11
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Yes and putting [JOB] in front will attract more people.
Please Log in or Create an account to join the conversation.
- Fjorten Syvogtredive (1437dk)
-
Topic Author
- Offline
- New Member
- Posts: 11
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Best of luck.
Please Log in or Create an account to join the conversation.