133 lines
6.3 KiB
PHP
133 lines
6.3 KiB
PHP
<?php
|
|
if ( ! defined( 'ABSPATH' ) ) exit;
|
|
get_header();
|
|
global $post;
|
|
$settings = get_option('wmw_settings', array());
|
|
$article = $post;
|
|
$wiki = wmw_get_article_wiki($article->ID);
|
|
$side_pos = $settings['sidebar_position'] ?? 'left';
|
|
?>
|
|
<div class="wmw-page wmw-article-page">
|
|
<?php if ($settings['show_breadcrumbs'] ?? 1): ?>
|
|
<?php WMW_Frontend::render_breadcrumb($article); ?>
|
|
<?php endif; ?>
|
|
|
|
<div class="wmw-layout wmw-layout--<?php echo esc_attr($side_pos); ?>">
|
|
|
|
<?php if ($side_pos !== 'none' && $wiki) : ?>
|
|
<aside class="wmw-sidebar">
|
|
<?php if ($settings['show_search'] ?? 1): ?>
|
|
<?php WMW_Frontend::render_search_box($wiki->ID); ?>
|
|
<?php endif; ?>
|
|
<?php echo WMW_Frontend::get_wiki_sidebar($wiki); ?>
|
|
</aside>
|
|
<?php endif; ?>
|
|
|
|
<main class="wmw-main">
|
|
<article class="wmw-article">
|
|
<header class="wmw-article__header">
|
|
<?php if ($wiki): ?>
|
|
<a href="<?php echo get_permalink($wiki->ID); ?>" class="wmw-article__wiki-link">
|
|
<span><?php echo wmw_get_wiki_icon($wiki->ID); ?></span>
|
|
<?php echo esc_html($wiki->post_title); ?>
|
|
</a>
|
|
<?php endif; ?>
|
|
<h1 class="wmw-article__title"><?php echo esc_html($article->post_title); ?></h1>
|
|
<div class="wmw-article__meta">
|
|
<?php $cats = get_the_terms($article->ID, 'wmw_category');
|
|
if ($cats && !is_wp_error($cats)):
|
|
foreach($cats as $cat): ?>
|
|
<a href="<?php echo get_term_link($cat); ?>" class="wmw-tag wmw-tag--cat"><?php echo esc_html($cat->name); ?></a>
|
|
<?php endforeach;
|
|
endif; ?>
|
|
<?php $tags = get_the_terms($article->ID, 'wmw_tag');
|
|
if ($tags && !is_wp_error($tags)):
|
|
foreach($tags as $tag): ?>
|
|
<a href="<?php echo get_term_link($tag); ?>" class="wmw-tag"><?php echo esc_html($tag->name); ?></a>
|
|
<?php endforeach;
|
|
endif; ?>
|
|
<span class="wmw-article__updated">Aktualisiert: <?php echo get_the_modified_date('d.m.Y', $article); ?></span>
|
|
</div>
|
|
</header>
|
|
|
|
<div class="wmw-article__body">
|
|
<?php echo apply_filters('the_content', $article->post_content); ?>
|
|
</div>
|
|
|
|
<footer class="wmw-article__footer">
|
|
<?php
|
|
// Prev / Next in same wiki
|
|
if ($wiki) {
|
|
$articles = wmw_get_articles($wiki->ID, array('orderby' => 'meta_value_num', 'meta_key' => '_wmw_order', 'order' => 'ASC'));
|
|
$ids = wp_list_pluck($articles, 'ID');
|
|
$pos = array_search($article->ID, $ids);
|
|
$prev = $pos > 0 ? get_post($ids[$pos-1]) : null;
|
|
$next = $pos !== false && $pos < count($ids)-1 ? get_post($ids[$pos+1]) : null;
|
|
?>
|
|
<nav class="wmw-article-nav">
|
|
<div class="wmw-article-nav__prev">
|
|
<?php if ($prev): ?>
|
|
<a href="<?php echo get_permalink($prev->ID); ?>">
|
|
<span class="wmw-article-nav__label">← Vorheriger Artikel</span>
|
|
<span class="wmw-article-nav__title"><?php echo esc_html($prev->post_title); ?></span>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
<div class="wmw-article-nav__next">
|
|
<?php if ($next): ?>
|
|
<a href="<?php echo get_permalink($next->ID); ?>">
|
|
<span class="wmw-article-nav__label">Nächster Artikel →</span>
|
|
<span class="wmw-article-nav__title"><?php echo esc_html($next->post_title); ?></span>
|
|
</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</nav>
|
|
<?php } ?>
|
|
</footer>
|
|
</article>
|
|
|
|
<?php
|
|
// Related Articles
|
|
$related = array();
|
|
if ($settings['show_related'] ?? 1) {
|
|
$cats = get_the_terms($article->ID, 'wmw_category');
|
|
if ($cats && !is_wp_error($cats)) {
|
|
$cat_ids = wp_list_pluck($cats, 'term_id');
|
|
$related = get_posts(array(
|
|
'post_type' => 'wmw_article',
|
|
'post_status' => 'publish',
|
|
'posts_per_page' => 4,
|
|
'post__not_in' => array($article->ID),
|
|
'meta_query' => array(array('key'=>'_wmw_wiki_id','value'=>wmw_get_article_wiki_id($article->ID))),
|
|
'tax_query' => array(array('taxonomy'=>'wmw_category','field'=>'term_id','terms'=>$cat_ids)),
|
|
));
|
|
}
|
|
}
|
|
if (!empty($related)):
|
|
?>
|
|
<section class="wmw-related">
|
|
<h3 class="wmw-related__title">📎 Verwandte Artikel</h3>
|
|
<div class="wmw-related-grid">
|
|
<?php foreach($related as $rel): ?>
|
|
<a href="<?php echo get_permalink($rel->ID); ?>" class="wmw-related-item">
|
|
<span class="wmw-related-item__title"><?php echo esc_html($rel->post_title); ?></span>
|
|
<?php if ($rel->post_excerpt): ?>
|
|
<span class="wmw-related-item__exc"><?php echo esc_html(wp_trim_words($rel->post_excerpt,12)); ?></span>
|
|
<?php endif; ?>
|
|
</a>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
|
|
</main>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
// Track view
|
|
jQuery(function($){
|
|
$.post(wmwPublic.ajaxUrl, { action:'wmw_track_view', article_id: <?php echo $article->ID; ?> });
|
|
});
|
|
</script>
|
|
<?php get_footer(); ?>
|