Skip to content

Instantly share code, notes, and snippets.

@clivewalker
clivewalker / add_page_numbers.php
Last active July 20, 2021 13:38
WordPress page numbers with Yoast SEO plugin. Add to functions.php. This will add " - Page x" to titles and meta descriptions in paginated archives (categories, blog post archives).Based on http://www.htpcbeginner.com/resources/codes/page-number-meta-description.txt
<?php
//Add page number to Yoast meta description and page titles to avoid duplication (when using customised titles/descriptions)
if ( ! function_exists( 'cvw_add_page_number' ) )
{
function cvw_add_page_number( $s )
{
global $page;
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
! empty ( $page ) && 1 < $page && $paged = $page;
// 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 / next_previous_links.php
Last active January 29, 2020 11:57
How to add Next and Previous links to a blog post with Perch
@clivewalker
clivewalker / image_orientation_detection.php
Last active June 19, 2019 09:32
A Perch CMS template filter to detect whether an image is portrait or landscape orientation. Written by Jay George.
/* 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 / config.js
Last active December 7, 2018 06:33
A config file to load additional plugins for Perch CMS default Redactor editor
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 / If-different-block-type.html
Last active November 1, 2018 12:06
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?"
<perch:if different="_block_type">
This is a different block type
</perch:if>
@clivewalker
clivewalker / perch-blog-template.php
Created June 28, 2018 08:13
Using layouts in Perch
<?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();
}
?>
@clivewalker
clivewalker / sidebarcode.php
Last active December 6, 2017 08:18
Showing a blog post excerpt that isn't the current post in a sidebar using Perch CMS. Use this on your post page.
<?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'
));
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 July 24, 2017 20:00
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
Perch.UserConfig.redactor = function(){
var get = function(profile, config, field) {
return { buttons: ['bold', 'italic'] }
};
var load = function(cb) {
cb();
};