<!doctype html>
<html>
<?php include 'head.php'; ?>
<body>
<?php
/*Template Name: Custom Contact*/
get_header();
?>
<div class="ny_ban"><img src="/wp-content/uploads/2024/03/2019072513474886.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'] ?? 38;
            // 输出目录
            echo get_slider_submenus('contact',37,$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="/contact">联系我们</a> > <span><?php echo get_cat_name($cat_id) ?></span></div>
			<span><?php echo get_cat_name($cat_id) ?></span>
		</div>
        <div class="con">
        <?php
            if($cat_id != 45){
                // 获取该分类下的第一篇文章
                $args = array(
                    'cat' => $cat_id, // 分类ID
                    'posts_per_page' => 1, // 每页显示的文章数量
                    'orderby' => 'date', // 按日期排序
                    'order' => 'ASC', // 升序
                );

                $cur_post = get_posts($args);

                if ($cur_post) {
                    $content = $cur_post[0]->post_content; // 文章内容
                    echo $content;
                } else {
                    echo '文章不存在';
                }

                // 释放查询结果
                wp_reset_postdata();
            }
        ?>
        <?php 
            if($cat_id == 38){
                include 'map.php';
            }
        ?>
        <?php
            // 加盟申请
            if($cat_id == 45){
                include 'commentForm.php';
            }
            ?>
        </div>
    </div>
</div>
<style>
    .swiper-wrapper{height:auto;}
</style>
<?php get_footer(); ?>

<script>
    jQuery(document).ready(function($) {
        $('#contact-form').submit(function(e) {
            e.preventDefault();
            if($("#rename").val()==''){
                alert('请输入姓名!');
                return
            }
            if($("#phone").val()==''){
                alert('请输入电话!');
                return
            }
            
            $.ajax({
                url: $(this).attr('action'),
                type: 'post',
                data: {
                    action: 'submit_custom_comment',
                    comment_data: $(this).serialize()
                },
                success: function(response) {
                    alert('提交成功!');
                    $('#contact-form')[0].reset();
                },
                error: function() {
                    alert('提交失败，请重试.');
                }
            });
        });
    });
</script>
</body>
</html>