Skip to content

Instantly share code, notes, and snippets.

clivewalker / next_previous_links.php
Last active Jan 29, 2020
How to add Next and Previous links to a blog post with Perch
View next_previous_links.php
clivewalker / image_orientation_detection.php
Last active Jun 19, 2019
A Perch CMS template filter to detect whether an image is portrait or landscape orientation. Written by Jay George.
View image_orientation_detection.php
=================================================== */
class PerchTemplateFilter_image_orientation_detection extends PerchTemplateFilter
/* Notes...
You may want to do something different if the image is landscape e.g. span 2 columns in a CSS grid rather than 1
- Assumes your template image has an ID of `image`
- e.g. `<div class="c-photo-grid__item c-photo-grid__item--<perch:content id="image" filter="image-orientation-detection" />">`
This would either output `c-photo-grid__item--landscape` or `c-photo-grid__item--portrait`
clivewalker / If-different-block-type.html
Last active Nov 1, 2018
With Perch CMS, you can use conditional tags with the different attribute to compare _block_type. Credit: Hussein Al Hammad. Original question by Jay George: "Any idea if it's possible to change the output of a block depending on which block procedes it? e.g. if a 'heading' block is followed by another 'heading' block, the output is changed?"
View If-different-block-type.html
<perch:if different="_block_type">
This is a different block type
View perch-blog-template.php
if (perch_layout_has('blog-post')) {
echo '<title>' . perch_pages_title(true) . '</title>';
View excluding-categories.php
// We're grabbing each category and filtering the 'Properties' region using that category - if the property count is 0, we don't pass that category to the output.
// This method does produce a database query for each category, so I would run it with debug switched on to see if makes an impact for your setup or not.
<?php perch_categories(['set'=>'area','sort'=>'catTitle','sort-order'=>'ASC','each'=>function($item) {
if (PerchUtil::count(perch_content_custom('Properties',
['skip-template'=>true, 'category'=>$item['catPath']])) > 0) return $item; }]
); ?>
// You do have to make a slight change to the category template with this though - an example using the default category.html template:
clivewalker / sidebarcode.php
Last active Dec 6, 2017
Showing a blog post excerpt that isn't the current post in a sidebar using Perch CMS. Use this on your post page.
View sidebarcode.php
'filter' => 'postSlug',
'match' => 'neq',
'value' => perch_get('s'),
View heading-arrows.css
h1 {
background: #000000;
color: #FFFFFF;
font-size: 20px;
font-weight: bold;
padding: 5px;
position: relative;
h1:after {
border-color: #000000 transparent transparent;
clivewalker / config.js
Created Jul 24, 2017
Simple configuration file for default Redactor editor in Perch CMS. Minimal editor buttons. From
View config.js
Perch.UserConfig.redactor = function(){
var get = function(profile, config, field) {
return { buttons: ['bold', 'italic'] }
var load = function(cb) {
clivewalker / config.js
Last active Dec 7, 2018
A config file to load additional plugins for Perch CMS default Redactor editor
View config.js
Perch.UserConfig.redactor = function(){
var get = function(profile, config, field) {
if (config.plugins.indexOf('source') === -1) config.plugins.push('source');
if (config.plugins.indexOf('fontcolor') === -1) config.plugins.push('fontcolor');
if (config.plugins.indexOf('alignment') === -1) config.plugins.push('alignment');
return config;
clivewalker / after-content-hook.php
Last active Feb 8, 2017
Adding after post content with WP filter hook so that it's in RSS feed
View after-content-hook.php
function after_post_content($content) {
if(!is_feed() && !is_home()) {
$content.= '<h4>Like this post?</h4>';
$content.= '<p><a href="">Subscribe to our newsletter</a>!</p>';
return $content;
add_filter ('the_content', 'after_post_content');