Created
July 16, 2014 18:47
-
-
Save ianshea/f8182b5dca895f64d416 to your computer and use it in GitHub Desktop.
First Entry from First Sub Category from Top Category Slug in Craft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# Get the category from the slug. This will return one CategoryModel #} | |
{% set topCat = craft.categories.slug('someSlug').first() %} | |
{# Get the first subcategory under the top level category using the getChildren() method on the category model. #} | |
{% set firstSubCat = topCat.getChildren().first() %} | |
{# Grab the first entry under that category using the relatedTo function and appending the .first() method to return only one item. #} | |
{% set firstEntry = craft.entries.relatedTo( firstSubCat ).first() %} | |
{# Set your image from your asset field #} | |
{% set image = firstEntry.assetField.first() %} | |
{# Party #} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment