Skip to content

Commit

Permalink
feat: Group posts by post type, improve settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
merlijnvanlent committed Oct 29, 2024
1 parent 9e40ba0 commit 3b9d3da
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 57 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All changes to this project will be documented in this file.

## 1.0.7 - 2024-10-29

- Group posts by post types on sitemap pages
- Allow pages to be selected in the settings which are not published

## 1.0.1 - 2024-08-26

- Added Dutch translations
Expand Down
Binary file modified languages/vo-html-sitemap-nl_NL.mo
Binary file not shown.
26 changes: 17 additions & 9 deletions languages/vo-html-sitemap-nl_NL.po
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/vo-html-sitemap\n"
"POT-Creation-Date: 2024-10-03T09:42:01+00:00\n"
"PO-Revision-Date: 2024-10-03 11:42+0200\n"
"POT-Creation-Date: 2024-10-29T09:49:29+00:00\n"
"PO-Revision-Date: 2024-10-29 10:58+0100\n"
"Last-Translator: Danique Wijnalda <[email protected]>\n"
"Language-Team: \n"
"Language: nl_NL\n"
Expand Down Expand Up @@ -47,9 +47,17 @@ msgstr "Sitemap pagina"
msgid "Select a page"
msgstr "Selecteer een pagina"

#: resources/views/sitemap-range.php:31
msgid "No posts found"
msgstr "Geen berichten gevonden"
#: resources/views/admin/settings.php:51
msgid "After changing this setting you need to re-save your permalink settings."
msgstr "Na het aanpassen van deze instelling moet je de permalink instellingen opnieuw opslaan."

#: resources/views/admin/settings.php:54
msgid "Permalink Settings"
msgstr "Permalink instellingen"

#: resources/views/sitemap-range.php:25
msgid "Nothing found"
msgstr "Niks gevonden"

#: src/Core/SettingsPage.php:40
msgid "VO HTML Sitemap Settings"
Expand All @@ -59,19 +67,19 @@ msgstr "VO HTML Sitemap Instellingen"
msgid "HTML Sitemap"
msgstr "HTML Sitemap"

#: src/Pages/LastWeek.php:45
#: src/Pages/LastWeek.php:46
msgid "Last week"
msgstr "Vorige week"

#: src/Pages/ThisWeek.php:45
#: src/Pages/ThisWeek.php:46
msgid "This week"
msgstr "Deze week"

#: src/Pages/Today.php:48
#: src/Pages/Today.php:49
msgid "Today"
msgstr "Vandaag"

#: src/Pages/Yesterday.php:48
#: src/Pages/Yesterday.php:49
msgid "Yesterday"
msgstr "Gisteren"

Expand Down
22 changes: 15 additions & 7 deletions languages/vo-html-sitemap.pot
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-10-03T09:42:01+00:00\n"
"POT-Creation-Date: 2024-10-29T09:49:29+00:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.5.0\n"
"X-Domain: vo-html-sitemap\n"
Expand Down Expand Up @@ -47,8 +47,16 @@ msgstr ""
msgid "Select a page"
msgstr ""

#: resources/views/sitemap-range.php:31
msgid "No posts found"
#: resources/views/admin/settings.php:51
msgid "After changing this setting you need to re-save your permalink settings."
msgstr ""

#: resources/views/admin/settings.php:54
msgid "Permalink Settings"
msgstr ""

#: resources/views/sitemap-range.php:25
msgid "Nothing found"
msgstr ""

#: src/Core/SettingsPage.php:40
Expand All @@ -59,18 +67,18 @@ msgstr ""
msgid "HTML Sitemap"
msgstr ""

#: src/Pages/LastWeek.php:45
#: src/Pages/LastWeek.php:46
msgid "Last week"
msgstr ""

#: src/Pages/ThisWeek.php:45
#: src/Pages/ThisWeek.php:46
msgid "This week"
msgstr ""

#: src/Pages/Today.php:48
#: src/Pages/Today.php:49
msgid "Today"
msgstr ""

#: src/Pages/Yesterday.php:48
#: src/Pages/Yesterday.php:49
msgid "Yesterday"
msgstr ""
9 changes: 8 additions & 1 deletion resources/views/admin/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,19 @@
<td>
<select id="vohtmlsitemap-page" name="vohtmlsitemap-page">
<option value="0"><?php esc_html_e('Select a page', 'vo-html-sitemap') ?></option>
<?php foreach (get_posts(['post_type' => 'page', 'posts_per_page' => -1]) as $page): ?>
<?php foreach (get_posts(['post_type' => 'page', 'posts_per_page' => -1, 'post_status' => 'any']) as $page): ?>
<option value="<?php echo esc_attr($page->ID) ?>" <?php echo selected(get_option('vohtmlsitemap-page'), $page->ID) ?>>
<?php echo esc_html($page->post_title) ?>
</option>
<?php endforeach; ?>
</select>
<p>
<?php esc_html_e('After changing this setting you need to re-save your permalink settings.', 'vo-html-sitemap') ?>
<br>
<a href="<?php echo esc_url(admin_url('options-permalink.php')) ?>">
<?php esc_html_e('Permalink Settings', 'vo-html-sitemap') ?>
</a>
</p>
</td>
</tr>
</table>
Expand Down
22 changes: 11 additions & 11 deletions resources/views/sitemap-day.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @var $year Year
* @var $month Month
* @var $day Day
* @var $posts WP_Post[]
* @var $postTypes array
*/

?>
Expand All @@ -27,15 +27,15 @@

<hr>

<h3>
<?php echo esc_html(__('Posts')) ?>
</h3>
<?php foreach ($postTypes as $postType => $posts): ?>
<h3><?php echo esc_html(get_post_type_object($postType)->label) ?></h3>

<ul class="vo-html-sitemap__list">
<?php foreach ($posts as $post): ?>
<li class="vo-html-sitemap__list-item">
<a href="<?php echo esc_attr(get_permalink($post)) ?>"><?php echo esc_html($post->post_title) ?></a>
</li>
<?php endforeach; ?>
</ul>
<ul class="vo-html-sitemap__list">
<?php foreach ($posts as $post): ?>
<li class="vo-html-sitemap__list-item">
<a href="<?php echo esc_attr(get_permalink($post)) ?>"><?php echo esc_html($post->post_title) ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
</div>
32 changes: 15 additions & 17 deletions resources/views/sitemap-range.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* @var $page Page
* @var $posts WP_Post[]
* @var $postTypes array
*/

?>
Expand All @@ -21,21 +21,19 @@

<hr>

<h3>
<?php echo esc_html(__('Posts')) ?>
</h3>
<?php if (empty($postTypes)): ?>
<p><?php esc_html_e('Nothing found', 'vo-html-sitemap') ?></p>
<?php else: ?>
<?php foreach ($postTypes as $postType => $posts): ?>
<h3><?php echo esc_html(get_post_type_object($postType)->label) ?></h3>

<ul class="vo-html-sitemap__list">
<?php if (empty($posts)): ?>
<li class="vo-html-sitemap__list-item">
<?php esc_html_e('No posts found', 'vo-html-sitemap') ?>
</li>
<?php else: ?>
<?php foreach ($posts as $post): ?>
<li class="vo-html-sitemap__list-item">
<a href="<?php echo esc_attr(get_permalink($post)) ?>"><?php echo esc_html($post->post_title) ?></a>
</li>
<?php endforeach; ?>
<?php endif; ?>
</ul>
<ul class="vo-html-sitemap__list">
<?php foreach ($posts as $post): ?>
<li class="vo-html-sitemap__list-item">
<a href="<?php echo esc_attr(get_permalink($post)) ?>"><?php echo esc_html($post->post_title) ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
<?php endif; ?>
</div>
5 changes: 3 additions & 2 deletions src/Pages/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function content(): string
'year' => $this->year,
'month' => $this->month,
'day' => $this,
'posts' => $this->getItems(),
'postTypes' => $this->getItems(),
]);
}

Expand All @@ -41,10 +41,11 @@ public function getItems(array $parameters = []): array
'month' => $this->month->number,
'day' => $this->number,
],
'orderby' => ['type', 'date'],
'posts_per_page' => -1,
]);

return $this->items = $query->posts;
return $this->items = $this->splitByPostType($query->posts);
}

public function getLabel(): string
Expand Down
5 changes: 3 additions & 2 deletions src/Pages/LastWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function content(): string
{
return Template::get('sitemap-range', [
'page' => $this,
'posts' => $this->getItems(),
'postTypes' => $this->getItems(),
]);
}

Expand All @@ -35,9 +35,10 @@ public function getItems(array $parameters = []): array
'before' => gmdate('Y-m-d', strtotime("sunday last week +1 day")),
],
'posts_per_page' => -1,
'orderby' => ['type', 'date'],
]);

return $this->items = $query->posts;
return $this->items = $this->splitByPostType( $query->posts );
}

public function getLabel(): string
Expand Down
9 changes: 9 additions & 0 deletions src/Pages/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ public function getSlug(): string
{
return sanitize_title($this->getLabel());
}

protected function splitByPostType(array $posts = []): array
{
return array_reduce($posts, function ($carry, $post) {
$carry[$post->post_type][] = $post;

return $carry;
}, []);
}
}
5 changes: 3 additions & 2 deletions src/Pages/ThisWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function content(): string
{
return Template::get('sitemap-range', [
'page' => $this,
'posts' => $this->getItems(),
'postTypes' => $this->getItems(),
]);
}

Expand All @@ -35,9 +35,10 @@ public function getItems(array $parameters = []): array
'before' => gmdate('Y-m-d', strtotime("sunday this week +1 day")),
],
'posts_per_page' => -1,
'orderby' => ['type', 'date'],
]);

return $this->items = $query->posts;
return $this->items = $this->splitByPostType( $query->posts );
}

public function getLabel(): string
Expand Down
5 changes: 3 additions & 2 deletions src/Pages/Today.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function content(): string
{
return Template::get('sitemap-range', [
'page' => $this,
'posts' => $this->getItems(),
'postTypes' => $this->getItems(),
]);
}

Expand All @@ -38,9 +38,10 @@ public function getItems(array $parameters = []): array
'day' => $today->format('d'),
],
'posts_per_page' => -1,
'orderby' => ['type', 'date'],
]);

return $this->items = $query->posts;
return $this->items = $this->splitByPostType( $query->posts );
}

public function getLabel(): string
Expand Down
5 changes: 3 additions & 2 deletions src/Pages/Yesterday.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function content(): string
{
return Template::get('sitemap-range', [
'page' => $this,
'posts' => $this->getItems(),
'postTypes' => $this->getItems(),
]);
}

Expand All @@ -38,9 +38,10 @@ public function getItems(array $parameters = []): array
'day' => $yesterday->format('d'),
],
'posts_per_page' => -1,
'orderby' => ['type', 'date'],
]);

return $this->items = $query->posts;
return $this->items = $this->splitByPostType( $query->posts );
}

public function getLabel(): string
Expand Down
4 changes: 2 additions & 2 deletions vo-html-sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Description: Van Ons plugin to add an HTML sitemap to your site.
* Author: Van Ons
* Author URI: https://van-ons.nl/
* Version: 1.0.6
* Version: 1.0.7
* Text Domain: vo-html-sitemap
* Domain Path: /languages
* Requires at least: 6.4
Expand All @@ -23,7 +23,7 @@
}

// Define plugin constants.
define('VOHTMLSITEMAP_VERSION', '1.0.6');
define('VOHTMLSITEMAP_VERSION', '1.0.7');

define('VOHTMLSITEMAP_ROOT', __DIR__ . '/');
define('VOHTMLSITEMAP_ROOT_FILE', __FILE__);
Expand Down

0 comments on commit 3b9d3da

Please sign in to comment.