Skip to content

Instantly share code, notes, and snippets.

@texnixe
texnixe / language_toggle.php
Created October 4, 2013 12:15
This is a snippet for a multilingual Kirby CMS installation that provides a language toogle with language names instead of language codes. Requires PHP 5.3 and up.
<nav class=lang_toggle>
<?php
$langs=c::get('lang.available');
$current=c::get('lang.current');
foreach($langs as $lang):
?>
<span>
<a href="<?php echo $page->url($lang)?>">
// show language names in the language of the respective languages;
// change second $lang to $current if you want all language names to show in the current language
@texnixe
texnixe / longpost.php
Last active February 24, 2017 19:07
Template for [Kirby CMS](http://getkirby.com) that splits long post into several pages where the content file has a <!--pagebreak--> tag. Adds pagination ( prev numbers next). Put <!--pagebreak--> tag into your content file where you want to split the post.
<?php
// store the content of the kirbytext text variable in $text
$text = kirbytext($page->text());
// split the content of $text whenever a <!--pagebreak--> code is encountered and store in the array $pages
$pages = explode('<!--pagebreak-->', $text);
// count the number of pages in the array
$pageCount = count ($pages);
@texnixe
texnixe / videoname.videoextension.txt
Last active June 24, 2018 10:10
This template is based on the xmlsitemap.php as described in the Kirby blog article 'Sitemap for search engines' at http://getkirby.com/blog/xmlsitemap. It allows you to include images in your sitemap to inform search engine robots about the images and/or videos belonging to each page indexed in your sitemap. Changes made to the template: - Adde…
Title: Title of Video
----
Description: Description of video
----
Duration: length in minutes
----
Thumb: url/to/thumb/filename
@texnixe
texnixe / lang-switch.php
Created October 21, 2014 16:39
Kirby 2 Language Switch
<nav class="languages" role="navigation'">
<?php foreach($site->languages() as $language): ?>
<?php $inventory = $page->inventory();
if (array_key_exists($language->code(),$inventory['content'])) :?>
<?php if(($site->language() !== $language)): ?>
<span>
<a href="<?php echo $page->url($language->code()) ?>"><?php echo $language->code(); ?></a>
</span>
<?php endif ?>
<?php endif ?>
<?php
/**
* Move this file to /site/snippets/ and rename it video.php
*/
// stop without videos
if(empty($videos)) return;
// set some defaults
@texnixe
texnixe / gist:390996ca722fbf49c63d
Last active August 29, 2015 14:08
tag-results.php
<?php
snippet('header');
$tag = urldecode(param('tag'));
if(param('tag'))
$articles=$pages->visible()->filterBy('tags',$tag,',')->sortBy('date')->flip();
?>
<main class="main">
<section>
<h1><?php echo $page->title() . ' ' . $tag ?></h1>

Keybase proof

I hereby claim:

  • I am texnixe on github.
  • I am sonjabroda (https://keybase.io/sonjabroda) on keybase.
  • I have a public key whose fingerprint is C827 C112 15AF AC65 CC19 2D8A 5078 A576 776F E582

To claim this, I am signing this object:

@texnixe
texnixe / filterbystructure.php
Last active June 15, 2017 12:25
Kirby custom pages method to filter by values in structure field
<?php
/* Usage example:
* $filteredPages = $page('projects')->children()->visible()->filterByStructure('structureField', array(
* 'field1' => $value,
* 'field2' => $value
* ));
*/
pages::$methods['filterByStructure'] = function($pages, $field, $options) {
$filteredPages = $pages->filter(function($p)use($field, $options) {
$structureField = $p->$field()->yaml();
@texnixe
texnixe / methods.php
Last active August 14, 2023 06:04
Collection of custom Kirby page, pages, field etc. methods
<?php
// page methods
// check if page has Parents
page::$methods['hasParents'] = function($page) {
return $page->parents()->count();
};
// get max nesting level of page
@texnixe
texnixe / indexer.php
Created March 13, 2018 17:47 — forked from sebsel/indexer.php
Indexer for Kirby
<?php
class Indexer {
static $fields;
static $methods;
static $site;
static function get($where = null, $num = 20, $hideDeleted = true) {
if (!static::$site) static::$site = site();