Skip to content

Instantly share code, notes, and snippets.

{# Paginate the News entries in groups of 4 #}
{% paginate craft.entries.section('news').relatedTo(category).limit(4) as newsEntries %}
{# Loop through this page's News entries #}
{% for newsEntry in newsEntries %}
{% set entryCategory = newsEntry.categories.first() %}
{# Figure out where this entry should link to #}
{# Paginate the News entries in groups of 4 #}
{% paginate craft.entries.section('news').relatedTo(category).limit(4) as newsEntries %}
{# Loop through this page's News entries #}
{% for newsEntry in newsEntries %}
{% set entryCategory = newsEntry.categories.first() %}
{# Figure out where this entry should link to #}
<div class="menu-links">
<a href="{{ url('about') }}" {% if craft.request.firstSegment == 'about' %}class="active"{% endif %}>About</a>
<a href="{{ url('services') }}" {% if craft.request.firstSegment == 'services' %}class="active"{% endif %}>Services</a>
<a href="{{ url('work') }}" {% if craft.request.firstSegment == 'work' %}class="active"{% endif %}>Work</a>
<a href="{{ url('news') }}" {% if craft.request.firstSegment == 'news' %}class="active"{% endif %}>News</a></a>
<a href="{{ url('resources') }}" {% if craft.request.firstSegment == 'resources' %}class="active"{% endif %}>Resources</a>
<a href="{{ url('contact') }}" {% if craft.request.firstSegment == 'contact' %}class="active"{% endif %}>Contact</a>
</div>
@richardsongo
richardsongo / gist:6ee1de84033f54c9ba3d
Last active August 29, 2015 14:21
Conditional statement if an entries relation field is empty?
{% if entry.fieldHandle |length %}
{{ entry.fieldHandle}}
{% else %}
{{ global.fieldHandle}}
{% endif %}
How can I conditionally display content if its a specific section?
{% if entry.section.handle == 'lettings' %}
@richardsongo
richardsongo / gist:6e603b9c7587d0dcbd44
Created May 20, 2015 22:43
Make a Craft entry Sticky
How would I make a post(s) sticky so that it appears first in the results and does not repeat later in the results?
You could add a custom lightswitch field or similar and order your entries by that field.
{% set entries = craft.entries.section('news').order('myLightswitch desc') %}
http://craftcms.stackexchange.com/questions/2149/is-there-a-sticky-post-function-built-into-craft?lq=1
http://craftcms.stackexchange.com/questions/2146/from-a-template-how-can-you-order-entries-by-one-field-and-if-that-field-is-em
<section class="news-items">
{% for entry in craft.entries.section('news').limit(10) %}
{% set image = entry.featuredImage.first() %}
{% set entryCategory = entry.categories.first() %}
<article class="media news-item">
<div class="media-left news-thumbnail">
<a class="" href="{{ entry.url }}">
<figure class="image_mask placeholder">
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
{% block head %}
<title>{% if title is defined %}{{ title }} - {% endif %}{{ siteName }}</title>
@richardsongo
richardsongo / full-social-media-tag-template-article
Last active August 29, 2015 14:22
Full Social Media Tag Template: Article
<!--
Full Social Media Tag Template: Article
Source: https://moz.com/blog/meta-data-templates-123
-->
<!-- Update your html tag to include the itemscope and itemtype attributes. -->
<html itemscope itemtype="http://schema.org/Article">
<!-- Place this data between the <head> tags of your website -->
<title>Page Title. Maximum length 60-70 characters</title>
<meta name="description" content="Page description. No longer than 155 characters." />
{% for block in siteInfo.globalSiteInfo.type('description, slogan') %}
{% if block.type == "description" %} <meta property="og:description" content="{{ block.siteDescription }}" /> {% endif %}
{% if block.type == "slogan" %} <meta property="og:title" content="{{ block.siteMoto }}" /> {% endif %}
{% endfor %}
<ul class="story-share shareTop hidden-print clearfix">
<li class="top-facebook-share top-article-share-button">
<a href="https://www.facebook.com/sharer/sharer.php?u=#{{ entry.url|url_encode }}"><i class="fa fa-facebook"></i></a>
</li>
<li class="top-twitter-share top-article-share-button">
<a href="http://twitter.com/share?text={{ entry.title|url_encode }}&amp;via=ReplaceWithChannelName&url={{ entry.url|url_encode }}">
<i class="fa fa-twitter"></i></a>
</li>
<li class="top-google-share top-article-share-button">
<a href="https://plus.google.com/share?url={{ entry.url }}" onclick="javascript:window.open(this.href,