From 275c0d74cd68677622a5431505c5c870c473063d Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 29 Mar 2026 21:40:15 +0000
Subject: [PATCH] =Seems to be working, huzzah! Added some changes for on-this-page nav
---
inc/registrar/Registrar.php | 47 ++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/inc/registrar/Registrar.php b/inc/registrar/Registrar.php
index 33a8687..a69a13f 100644
--- a/inc/registrar/Registrar.php
+++ b/inc/registrar/Registrar.php
@@ -186,8 +186,10 @@
private static array $instances = [];
+ protected string $based;
private function __construct(string $slug, string $singular, string $plural, string $type) {
$this->slug = $slug;
+ $this->based = jvbCheckBase($slug);
$this->type = $type;
$this->singular = $singular;
$this->plural = $plural;
@@ -383,6 +385,11 @@
return $this->slug;
}
+ public function getBased():string
+ {
+ return $this->based;
+ }
+
public function setTimeline(bool $set):self
{
$this->is_timeline = $set;
@@ -686,9 +693,43 @@
}
wp_reset_postdata();
}
-
add_filter('jvb_post_content_output', [$this, 'renderContent'], 20, 2);
+
+
+ //Add a date published and date modified fields, and auto-update them on term creation/modification
+ $this->fields()->addField('date_published', [
+ 'type' => 'datetime',
+ 'label' => 'Published',
+ 'hidden' => true,
+ ]);
+ $this->fields()->addField('date_modified', [
+ 'type' => 'datetime',
+ 'label' => 'Modified',
+ 'hidden' => true,
+ ]);
+ add_action('created_'.$this->based, [$this, 'addTermCreatedMeta']);
+ add_action('edited_'.$this->based, [$this, 'addTermUpdatedMeta']);
}
+ public function addTermCreatedMeta(int $termId):void
+ {
+ $meta = Meta::forTerm($termId);
+ $meta->set('date_published', date('Y-m-d H:i:s'));
+ }
+ public function handleContentTermMetaChange(int $meta_id, int $term_id, string $meta_key, $meta_value):void
+ {
+ $term = get_term($term_id);
+ $taxonomy = $term->taxonomy;
+ if ($taxonomy === $this->based && $meta_key !== BASE . 'date_modified') {
+ $meta = Meta::forTerm($term_id);
+ $meta->set('date_modified', date('Y-m-d H:i:s'));
+ }
+
+ }
+ public function addTermUpdatedMeta(int $termId):void
+ {
+ $meta = Meta::forTerm($termId);
+ $meta->set('date_modified', date('Y-m-d H:i:s'));
+ }
public function renderContent(string $content, array $block):string
{
if (!is_page($this->page)) {
@@ -716,7 +757,7 @@
$meta = Meta::forTerm($item);
$slug = sanitize_title($meta->get('name'));
$item = sprintf(
- '<li id="%s"><h3><a href="%s">%s</a></h3><p>%s</p><ul>',
+ '<li id="%s"><h2><a href="%s">%s</a></h2><p>%s</p><ul class="item-grid">',
$slug,
get_term_link($item, jvbCheckBase($this->slug))??'',
$meta->get('name'),
@@ -737,7 +778,7 @@
$img = $postMeta->get('post_thumbnail');
$img = !empty($img) ? jvbFormatImage((int)$img, 'tiny', 'medium') : '';
$item .= sprintf(
- '<li id="%s"><h4><a href="%s">%s</a></h4>%s</li>',
+ '<li id="%s" class="item"><h3><a href="%s">%s</a></h3>%s</li>',
$slug.'-'.sanitize_title(get_the_title($ID)),
get_the_permalink($ID),
$postMeta->get('post_title'),
--
Gitblit v1.10.0