Add pretty url for blog post
This commit is contained in:
parent
01c5e08fad
commit
aea0773df8
6 changed files with 19 additions and 4 deletions
|
@ -17,7 +17,7 @@
|
||||||
RewriteRule ^wishlist/([0-9a-f]{40})$ /?page=wishlist&hash=$1 [QSA,L]
|
RewriteRule ^wishlist/([0-9a-f]{40})$ /?page=wishlist&hash=$1 [QSA,L]
|
||||||
|
|
||||||
# Blog Post
|
# Blog Post
|
||||||
RewriteRule ^blog/([a-z\-0-9]+)$ /?page=blog&slug=$1 [QSA,L]
|
RewriteRule ^blog/([a-z\-0-9]+)$ /?page=post&slug=$1 [QSA,L]
|
||||||
</IfModule>
|
</IfModule>
|
||||||
|
|
||||||
##-- When caching of gzipped JS and CSS files is used, enable this setting
|
##-- When caching of gzipped JS and CSS files is used, enable this setting
|
||||||
|
|
|
@ -33,6 +33,19 @@ class Blog
|
||||||
return $post;
|
return $post;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getPostBySlug(string $slug): \stdClass
|
||||||
|
{
|
||||||
|
$posts = self::get(self::ENDPOINT_POSTS);
|
||||||
|
|
||||||
|
foreach ($posts as $post) {
|
||||||
|
if ($slug === $post->slug) {
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \Exception('No post found with the slug "' . $slug . '".');
|
||||||
|
}
|
||||||
|
|
||||||
public static function getPosts(): array
|
public static function getPosts(): array
|
||||||
{
|
{
|
||||||
$posts = self::get(self::ENDPOINT_POSTS);
|
$posts = self::get(self::ENDPOINT_POSTS);
|
||||||
|
|
|
@ -122,6 +122,7 @@ class Page
|
||||||
$ignorePower = array(
|
$ignorePower = array(
|
||||||
'home',
|
'home',
|
||||||
'blog',
|
'blog',
|
||||||
|
'post',
|
||||||
'install',
|
'install',
|
||||||
'login',
|
'login',
|
||||||
'maintenance',
|
'maintenance',
|
||||||
|
|
|
@ -32,7 +32,7 @@ $posts = Blog::getPosts();
|
||||||
);
|
);
|
||||||
$mediaHTML = isset($post->featured_media) ? Blog::getMediaHTML($post->featured_media) : '';
|
$mediaHTML = isset($post->featured_media) ? Blog::getMediaHTML($post->featured_media) : '';
|
||||||
$categoriesHTML = Blog::getCategoriesHTML($post->categories);
|
$categoriesHTML = Blog::getCategoriesHTML($post->categories);
|
||||||
$postLink = '/?page=post&id=' . $post->id;
|
$postLink = '/?page=post&slug=' . $post->slug;
|
||||||
?>
|
?>
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<div class="ui fluid card stretch">
|
<div class="ui fluid card stretch">
|
||||||
|
|
|
@ -45,6 +45,7 @@ $page->navigation();
|
||||||
<ul>
|
<ul>
|
||||||
<li><?= __('Localisation (many new translations added)') ?></li>
|
<li><?= __('Localisation (many new translations added)') ?></li>
|
||||||
<li><?= __('Saved wish information is not updated if the url can not be found') ?></li>
|
<li><?= __('Saved wish information is not updated if the url can not be found') ?></li>
|
||||||
|
<li><?= __('URL handling') ?></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h3 class="ui header"><?= __('Changed') ?></h3>
|
<h3 class="ui header"><?= __('Changed') ?></h3>
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
namespace wishthis;
|
namespace wishthis;
|
||||||
|
|
||||||
$postID = $_SESSION['_GET']['id'];
|
$postSlug = $_SESSION['_GET']['slug'];
|
||||||
$post = Blog::getPost($postID);
|
$post = Blog::getPostBySlug($postSlug);
|
||||||
$postMediaHTML = isset($post->featured_media) ? Blog::getMediaHTML($post->featured_media) : '';
|
$postMediaHTML = isset($post->featured_media) ? Blog::getMediaHTML($post->featured_media) : '';
|
||||||
|
|
||||||
$page = new Page(__FILE__, 'Post');
|
$page = new Page(__FILE__, 'Post');
|
||||||
|
|
Loading…
Reference in a new issue