Skip to content

Instantly share code, notes, and snippets.

clivewalker

Block or report user

Report or block clivewalker

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@clivewalker
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
/* GROUP IMAGE ORIENTATION DETECTION
=================================================== */
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
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
</perch:if>
View perch-blog-template.php
<?php
if (perch_layout_has('blog-post')) {
perch_blog_post_meta(perch_get('s'));
perch_page_attributes();
}else{
echo '<title>' . perch_pages_title(true) . '</title>';
perch_page_attributes();
}
?>
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
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
<?php
perch_blog_custom(array(
'filter' => 'postSlug',
'match' => 'neq',
'value' => perch_get('s'),
'sort'=>'postDateTime',
'sort-order'=>'DESC',
'count'=>1,
'template'=>'blog/post_in_list_sidebar.html'
));
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
clivewalker / config.js
Created Jul 24, 2017
Simple configuration file for default Redactor editor in Perch CMS. Minimal editor buttons. From http://forum.grabaperch.com/forum/06-28-2017-help-with-customising-redactor-toolbar-with-minimal-buttons
View config.js
Perch.UserConfig.redactor = function(){
var get = function(profile, config, field) {
return { buttons: ['bold', 'italic'] }
};
var load = function(cb) {
cb();
};
@clivewalker
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
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="http://example.com/subscribe">Subscribe to our newsletter</a>!</p>';
}
return $content;
}
add_filter ('the_content', 'after_post_content');
@clivewalker
clivewalker / formselectoptions.html
Last active Dec 6, 2016
Perch snippet allowing CMS editors to change a select element in a form
View formselectoptions.html
<perch:label for="subject">Subject</perch:label>
<perch:input type="select" id="subject" options="<perch:content id="subject" type="text" label="Subject" help="Add subjects separated by commas" />" id="subjectoptions" />
You can’t perform that action at this time.