[Portfolio] fetching latest item + related items from same category
Hi there,
First of all, thanks for the great tutorial for creating a portfolio. Very useful ressource.
I have two questions:
1. Fetching latest item from portfolio
I'd like to display the latest added item from the portfolio on my homepage. I know it's possible to do so using the blog app through sort-order; is there any way to achieve the same thing through categories? For now, I have to re-order the items in the back-office in order to get it to work.
Here is how the index.php looks like:
<?php
perch_content_custom('Portfolio', array(
'count' => 1,
'template' => 'portfolio_listing.html',
'page'=>'/portfolio.php',
'category' => perch_get('cat'),
));
?>
2. Related items
On the detail page of a particular portfolio item, I'd like to display the related items belonging to the same category. Is this achievable? Do you have any leads?
Thanks, Robin
perch_content_custom()
call to get items in those categories. Filter it so that the item's_id
isn't in the set.Thanks for the prompt reply.
I am now able to get the latest portfolio item; noted for the related items, I'll try to implement this.
Hi,
I'm able to get related items by hard-coding a value for the category:
One thing I'm not able to do is to get the categories of the current item. Any hints?
Cheers, Robin
Why are you not able to do that?
I'm actually not too sure how to do it, I believe I am missing something somewhere :) I don't know how to access the path of the categories of a given item.
The following code fetches all the entries regardless of categories rather than filtering the ones from the category of current item.
Use
skip-template
to get the current categoriesThen
$result[0]
will be your item, and presumably something like$result[0]['category']
will be your categories.Thanks for the reply, this is helpful. I get the array with all the information from the region using $result[0]. Nevertheless, when I specify the following:
It seems that I'm only getting the id of the category, there's no mention of the name of the categories.
Am I missing something?
No, that's something we'll need to look at.
For the time being, is there a way to map the id of the categories to the category name?
I don't believe so.
Ok, is this something you might fix eventually? I find that it would be really useful to be able to access the categories assigned to a particular item.
Cheers,
Yes, absolutely.
Hi Drew,
Just wondering if you made any progress on this? The use case is to append the categories assigned to an item to both description and title meta tags.
Cheers,
No, it's not something I've had time to look at.
Thanks for the fix!
Hi,
I have an problem getting the translated values in case of multi-lingual categories.
Here is how I set it up: I have a set of category (themes) which contains categories (perseverance, parenthood, etc.). Each of these categories has two fields for each translations.
I do get the category name but the array doesn't give me the translated text of a given category.
When I print the array, I get the name of the categories but not the translated texts.
How could I go one level deeper and get the translated texts?
Cheers,
Those are the category paths - you should be able to use them to look up any information about the category.
Could you give me a hint on how to do that?
I know how to filter content based on a given categories but somehow I don't understand how to access the information (in my case the two translations) from a specific category.
Thanks,
Yes, you can use the
perch_category()
function - pass it the category path:Ok thanks. I do get the two translated value by doing this:
I would like now access either one of the two translations depending on the language set by the user. Usually, I can
skip-template
and get the array and play around with what I need. Here, it does not seem to do the trick. I believe I'm doing something which makes no sense here, as the page becomes white.The doc states that perch_category accept an array of options. Is there an equivalent of skip-template for the perch_category? What to do to be able to print one of the two translations?
Thanks for your help!