<!doctype html>
<html>
<?php include 'head.php'; ?>
<body>
<?php
/*Template Name: Custom SchoolDetail*/
get_header();
?>
<div class="ny_ban"><img src="/wp-content/uploads/2024/03/2019072513571726.jpg"></div>

<div class="ny_main w1200">
	<div class="l">
		<div class="box">
    <div class="tit">创业大学</div>
    <div class="bor">
        <ul class="lm">
            <?php
            // 获取当前子分类
            $cat_id = $_REQUEST['fid'] ?? 30;
            
            // 输出目录
            echo get_slider_submenus('school',29,$cat_id)
            ?>
        </ul>
    </div>
</div>		
<?php include 'concat.php'; ?>
</div>
	<div class="r">
		<div class="tit">
			<div class="lj">您当前位置 ：<a href="/index">首页</a> > <a href="/school">创业大学</a> > <span><?php echo get_cat_name($cat_id) ?></span></div>
			<span><?php echo get_cat_name($cat_id) ?></span>
		</div>
        <div class="con ny_news_detail">
        <?php
            // 文章id
            $post_id = $_REQUEST['id'];
            if($post_id) {
                // 获取文章标题
                $title = get_post_field('post_title', $post_id);
                // 获取文章内容
                $content = get_post_field('post_content', $post_id);
                // 获取作者ID
                $author_id = get_post_field('post_author', $post_id);
                // 获取作者名字
                $author_name = get_the_author_meta('display_name', $author_id);
                // 获取发布时间
                $published_date = get_the_date('', $post_id);
            }
            // 检查文章是否存在
            $post = get_post($post_id);
            setup_postdata($post);
            if ($post) {
                 // 获取当前文章的浏览计数
                 $post_views = (int) get_post_meta($post->ID, 'views', true);
        ?>
            <h3><?php echo $title; ?></h3>
			<div class="infos">
				<span><img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/news_detail_03.jpg">发布时间：<?php echo $published_date ?></span>
				<span><img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/news_detail_04.jpg">发布者：<?php echo $author_name ?></span>
				<span><img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/news_detail_05.jpg">浏览次数：<?php echo $post_views ?>次</span>
				<!-- <span><img src="images/news_detail_06.jpg">分享到：<img src="images/news_detail_07.jpg"></span> -->
			</div>
			<div class="con">
                <?php echo $content; ?>
		    </div>

            <div class="prev_next">
            <?php
               
                // 更新浏览计数
                update_post_meta($post->ID, 'views', $post_views + 1);

                // 获取上一篇文章
                $previous_post = get_adjacent_post(true, '', false);
                // 获取下一篇文章
                $next_post = get_adjacent_post(true, '', true);

                // 输出前后文章的链接和标题
                if (!empty($previous_post)) {
                 echo '<div>上一篇：<a href="/schoolDetail/?id=' . $previous_post->ID .'&&fid='.$cat_id. '">' . get_the_title($previous_post) . '</a></div> ';
                }else{
                 echo '<div>上一篇：<span>没有啦</span></div>';
                }
                if (!empty($next_post)) {
                 echo '<div>下一篇：<a href="/schoolDetail/?id=' . $next_post->ID .'&&fid='.$cat_id. '">' . get_the_title($next_post) . '</a></div> ';
                }else{
                 echo '<div>下一篇：<span>没有啦</span></div>';
                }
            ?> 
            </div>
        <?php   
            } else {
                // 没有找到文章的提示
                echo '没有找到文章。';
            }
            
            wp_reset_postdata();
        ?>
        </div>
    </div>
</div>
<style>
    .swiper-wrapper{height:auto;}
</style>
<?php get_footer(); ?>

</body>
</html>