Skip to content

Instantly share code, notes, and snippets.

@richardsongo
richardsongo / Craft-Previous-Next-entries
Created September 17, 2015 21:20
How to link to previous/next entries in a section?
{# Set parameters for prev/next elements list #}
{% set params = craft.entries.section('blog').order('title asc') %}
{# Get the prev/next elements #}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}
{# And make sure to only output the links if the element exists #}
<nav class="col">
{% if prevEntry %}<div class="nav-prev"><a href="{{ prevEntry.url }}"><i class="icomoon-chevron-left"></i> <span class="sub-title">Previous article</span> {{ prev.title }}</a></div>{% endif %}
@richardsongo
richardsongo / Craft-Previous-Next-entries
Created September 17, 2015 21:20
How to link to previous/next entries in a section?
{# Set parameters for prev/next elements list #}
{% set params = craft.entries.section('blog').order('title asc') %}
{# Get the prev/next elements #}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}
{# And make sure to only output the links if the element exists #}
<nav class="col">
{% if prevEntry %}<div class="nav-prev"><a href="{{ prevEntry.url }}"><i class="icomoon-chevron-left"></i> <span class="sub-title">Previous article</span> {{ prev.title }}</a></div>{% endif %}
<?xml version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ siteName }}</title>
<link>{{ siteUrl }}</link>
<atom:link href="{{ craft.request.url }}" rel="self" type="application/rss+xml" />
<description><![CDATA[ {{ siteInfo.siteDescription }} ]]> </description>
<language>fr</language>
<pubDate>{{ now.rss }}</pubDate>
<lastBuildDate>{{ now.rss }}</lastBuildDate>
{% block head %}
{{ parent() }}
<meta name="description" content="{{ entry.body | trimit(400) }}" />
<link rel="canonical" href="{{ entry.url }}">
<meta name="author" content="{{ siteName }}">
<!-- Schema.org markup for Google+ -->
<meta itemprop="name" content="{{ entry.title }}">
<meta itemprop="description" content="{{ entry.body | trimit(400) }}">
<meta itemprop="image" content="{% if image %}{{ image.getUrl('large') }}{% endif %}">
<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,
{% 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 %}
@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." />
<!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>
<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">
@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