Advertisement
Guest User

Untitled

a guest
Jan 20th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.48 KB | None | 0 0
  1. <?php
  2. /**
  3. * The Template for displaying index page.
  4. */
  5. get_header(); ?>
  6.  
  7.  
  8. <!-- #contents -->
  9. <div id="contents">
  10. <div class="flexslider">
  11.  
  12. <ul class="slides">
  13. <?php $args = array(
  14. 'numberposts' => 5, //表示(取得)する記事の数
  15. 'post_type' => 'key_img' //投稿タイプの指定
  16. );
  17. $customPosts = get_posts($args);
  18. if($customPosts) : foreach($customPosts as $post) : setup_postdata( $post ); ?>
  19. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key1', true),'full'); ?></li>
  20. <?php if(get_field("key2")): ?>
  21. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key2', true),'full'); ?></li>
  22. <?php else : ?>
  23. <?php endif; ?>
  24. <?php if(get_field("key3")): ?>
  25. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key3', true),'full'); ?></li>
  26. <?php else : ?>
  27. <?php endif; ?>
  28. <?php if(get_field("key4")): ?>
  29. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key4', true),'full'); ?></li>
  30. <?php else : ?>
  31. <?php endif; ?>
  32. <?php if(get_field("key5")): ?>
  33. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key5', true),'full'); ?></li>
  34. <?php else : ?>
  35. <?php endif; ?>
  36. <?php if(get_field("key6")): ?>
  37. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key6', true),'full'); ?></li>
  38. <?php else : ?>
  39. <?php endif; ?>
  40. <?php if(get_field("key7")): ?>
  41. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key7', true),'full'); ?></li>
  42. <?php else : ?>
  43. <?php endif; ?>
  44. <?php if(get_field("key8")): ?>
  45. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key8', true),'full'); ?></li>
  46. <?php else : ?>
  47. <?php endif; ?>
  48. <?php if(get_field("key9")): ?>
  49. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key9', true),'full'); ?></li>
  50. <?php else : ?>
  51. <?php endif; ?>
  52. <?php if(get_field("key10")): ?>
  53. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key10', true),'full'); ?></li>
  54. <?php else : ?>
  55. <?php endif; ?>
  56. <!--<li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key7', true),'full'); ?></li>
  57. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key8', true),'full'); ?></li>
  58. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key9', true),'full'); ?></li>
  59. <li><?php echo wp_get_attachment_image(get_post_meta($post->ID, 'key10', true),'full'); ?></li>-->
  60. <?php endforeach; ?>
  61. <?php else : //記事が無い場合 ?>
  62. <?php endif; ?>
  63. <?php wp_reset_postdata(); ?>
  64. </ul>
  65.  
  66. <div class="key_logo no_opacity" >
  67. <a href="<?php bloginfo('url'); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/top_pat03_10.png" alt="宅都" width="240" height="410" /></a>
  68. <div id="search_top">&nbsp;</div>
  69. </div>
  70. </div>
  71. <!-- #main -->
  72. <div id="main">
  73. <?php
  74. // クエリ
  75. $meta_query = array();
  76.  
  77. // 検索条件
  78. $search_conditions = array();
  79.  
  80.  
  81. /* 家賃 */
  82. if ( isset($_POST['yachin']) && is_array($_POST['yachin']) && count($_POST['yachin']) ) {
  83.  
  84. $queries = array();
  85. for ( $i = 0, $cnt = count($_POST['yachin']); $i < $cnt; $i++ ) {
  86.  
  87. $search_conditions[] = array(
  88. 'display_name' => $_POST['yachin'][$i],
  89. 'name' => 'yachin[]',
  90. 'value' => $_POST['yachin'][$i]
  91. );
  92.  
  93. $queries[] = array(
  94. 'key' => 's_yachin',
  95. 'value' => $_POST['yachin'][$i],
  96. 'compare' => 'LIKE',
  97. 'type' => 'CHAR'
  98. );
  99. }
  100.  
  101. if ( count($queries) ) $queries['relation'] = 'or';
  102.  
  103. $meta_query[] = $queries;
  104. }
  105.  
  106. /* 間取り */
  107. if ( isset($_POST['layout']) && is_array($_POST['layout']) && count($_POST['layout']) ) {
  108.  
  109. $queries = array();
  110. for ( $i = 0, $cnt = count($_POST['layout']); $i < $cnt; $i++ ) {
  111.  
  112. $search_conditions[] = array(
  113. 'display_name' => $_POST['layout'][$i],
  114. 'name' => 'layout[]',
  115. 'value' => $_POST['layout'][$i]
  116. );
  117.  
  118. $queries[] = array(
  119. 'key' => 's_madori',
  120. 'value' => $_POST['layout'][$i],
  121. 'compare' => '='
  122. );
  123. }
  124.  
  125. if ( count($queries) ) $queries['relation'] = 'or';
  126.  
  127. $meta_query[] = $queries;
  128. }
  129.  
  130. /* 専有面積 */
  131. if ( isset($_POST['menseki']) && is_array($_POST['menseki']) && count($_POST['menseki']) ) {
  132.  
  133. $queries = array();
  134. for ( $i = 0, $cnt = count($_POST['menseki']); $i < $cnt; $i++ ) {
  135.  
  136. $search_conditions[] = array(
  137. 'display_name' => $_POST['menseki'][$i],
  138. 'name' => 'menseki[]',
  139. 'value' => $_POST['menseki'][$i]
  140. );
  141.  
  142. $queries[] = array(
  143. 'key' => 's_menseki',
  144. 'value' => $_POST['menseki'][$i],
  145. 'compare' => 'LIKE',
  146. 'type' => 'CHAR'
  147. );
  148. }
  149.  
  150. if ( count($queries) ) $queries['relation'] = 'or';
  151.  
  152. $meta_query[] = $queries;
  153. }
  154.  
  155. /* 築年数 */
  156. if ( isset($_POST['tikunen']) && is_array($_POST['tikunen']) && count($_POST['tikunen']) ) {
  157.  
  158. $queries = array();
  159. for ( $i = 0, $cnt = count($_POST['tikunen']); $i < $cnt; $i++ ) {
  160.  
  161. $search_conditions[] = array(
  162. 'display_name' => $_POST['tikunen'][$i],
  163. 'name' => 'tikunen[]',
  164. 'value' => $_POST['tikunen'][$i]
  165. );
  166.  
  167. $queries[] = array(
  168. 'key' => 's_tikunen',
  169. 'value' => $_POST['tikunen'][$i],
  170. 'compare' => 'LIKE',
  171. 'type' => 'CHAR'
  172. );
  173. }
  174.  
  175. if ( count($queries) ) $queries['relation'] = 'or';
  176.  
  177. $meta_query[] = $queries;
  178. }
  179.  
  180. /* こだわり条件 */
  181. if ( isset($_POST['kodawari']) && is_array($_POST['kodawari']) && count($_POST['kodawari']) ) {
  182.  
  183. $queries = array();
  184. for ( $i = 0, $cnt = count($_POST['kodawari']); $i < $cnt; $i++ ) {
  185.  
  186. $search_conditions[] = array(
  187. 'display_name' => $_POST['kodawari'][$i],
  188. 'name' => 'kodawari[]',
  189. 'value' => $_POST['kodawari'][$i]
  190. );
  191.  
  192. $queries[] = array(
  193. 'key' => 's_kodawari',
  194. 'value' => $_POST['kodawari'][$i],
  195. 'compare' => 'LIKE',
  196. 'type' => 'CHAR'
  197. );
  198. }
  199.  
  200. if ( count($queries) ) $queries['relation'] = 'or';
  201.  
  202. $meta_query[] = $queries;
  203. }
  204.  
  205.  
  206. if ( count($meta_query) ) $meta_query['relation'] = 'or';
  207.  
  208. $args = array(
  209. 'post_type' => array('bukken'),
  210. 'paged' => (isset($_POST['page']) && is_numeric($_POST['page']))? $_POST['page'] : $paged,
  211. 'meta_query' => $meta_query
  212. );
  213.  
  214. /* タクソノミー */
  215. if ( isset($_POST['term_id']) && strlen($_POST['term_id']) ) {
  216. $term = get_term($_POST['term_id'], 'place_area');
  217. array_unshift($search_conditions, array(
  218. 'display_name' => $term->name,
  219. 'name' => 'place-area'
  220. ));
  221. $args['place_area'] = $term->slug;
  222. }
  223.  
  224. query_posts($args);
  225. ?>
  226.  
  227.  
  228. <!-- #articles -->
  229. <div id="articles">
  230. <div class="Article_list clear_fix">
  231. <!-- #search-conditions -->
  232. <div id="search-conditions" class="clearfix">
  233. <!-- #search-conditions -->
  234. <?php if ( count($search_conditions) ) foreach ( $search_conditions as $val ) : ?>
  235. <img src="<?php bloginfo('template_directory'); ?>/images/search_tag1.png" class="search_back1"/>
  236. <a href="javascript:void(0);" id="search_tag" data-action="clear" data-target="<?php echo $val['name']; ?>" data-value="<?php echo $val['value'] ?>">
  237. <?php echo $val['display_name']; ?></a>
  238. <?php endforeach; ?>
  239. </div>
  240. <!-- /#search-conditions -->
  241.  
  242.  
  243.  
  244. <?php if(have_posts()): ?>
  245. <?php $post_counter = 1; ?>
  246. <?php while(have_posts()): the_post();?>
  247.  
  248. <?php if($post_counter == 1): ?>
  249.  
  250. <div class="Article">
  251. [--記事の書き出し箇所 中略--]
  252. </div>
  253.  
  254.  
  255. <?php elseif($post_counter ==2): ?>
  256.  
  257. <div class="Article2">
  258. [--記事の書き出し箇所 中略--]
  259. </div>
  260.  
  261. <?php else: ?>
  262.  
  263. <div class="Article3">
  264. [--記事の書き出し箇所 中略--]
  265. </div>
  266.  
  267.  
  268.  
  269. <?php endif; ?>
  270. <?php $post_counter++; ?>
  271. <?php endwhile; ?>
  272. <?php else: ?>
  273. <p class="not-article">物件がありません。<br>条件を変えて再度検索してください。</p>
  274. <?php endif; ?>
  275. <div class="clear"></div>
  276. <!-- #pager-->
  277. <div id="pager"></div>
  278. <!-- /#pager -->
  279.  
  280.  
  281.  
  282. </div>
  283. </div>
  284. <!-- /#articles -->
  285. </div>
  286. <!-- /#main -->
  287.  
  288. <?php get_sidebar(); ?>
  289.  
  290. </div>
  291. <!-- /#contents -->
  292.  
  293.  
  294. <input type="hidden" id="m-page" name="m-page" value="<?php echo $wp_query->max_num_pages; ?>">
  295. <input type="hidden" id="place-area" name="place-area" value="<?php echo $_POST['term_id'] ?>">
  296.  
  297. <?php if ( !isset($_POST['search']) || $_POST['search'] === false ) : ?>
  298. <script>
  299. $(function() {
  300.  
  301. var $page = 1;
  302.  
  303. search();
  304.  
  305. $(document).on('change', '[data-action="search"]', function() {
  306.  
  307. $('html, body').animate({scrollTop:$('#articles').offset().top}, 500, 'swing');
  308.  
  309. search();
  310. });
  311. $(document).on('click', 'a[data-action="search"]', function() {
  312.  
  313. $('#place-area').val($(this).data('id'));
  314.  
  315. $('html, body').animate({scrollTop:$('#articles').offset().top}, 500, 'swing');
  316.  
  317. search();
  318. });
  319.  
  320. $(document).on('click', '[data-action="paging"]', function() {
  321.  
  322. $('html, body').animate({scrollTop:$('#articles').offset().top}, 500, 'swing');
  323.  
  324. search($(this).data('page'));
  325. });
  326.  
  327. $(document).on('click', '[data-action="clear"]', function () {
  328.  
  329. var $split = $(this).data('target').split(',');
  330. var $value = $(this).data('value');
  331.  
  332. $.each($split, function($i, $val) {
  333. $tag_name = $('[name="' + $val + '"]')[0].tagName;
  334.  
  335. if ( $tag_name == 'SELECT' ) {
  336. $('[name="' + $val + '"] option').prop('selected', false);
  337. }
  338. else if ( $tag_name == 'INPUT' ) {
  339. if ( $('[name="' + $val + '"]').attr('type') == 'checkbox' || $('[name="' + $val + '"]').attr('type') == 'radio' ) {
  340. $('[name="' + $val + '"][value="' + $value + '"]').prop('checked', false);
  341. }
  342. else {
  343. $('[name="' + $val + '"]').val('');
  344. }
  345. }
  346. });
  347.  
  348. search();
  349. });
  350.  
  351. function search($current_page) {
  352. $('#articles').children().remove();
  353. $('#articles').append('<p id="loading" style="text-align: center; margin-top: 30p;">Loading ...</p>');
  354. if ( $current_page == null ) {
  355. $page = 1;
  356. }
  357. else {
  358. $page = $current_page;
  359. }
  360.  
  361. var $data = {'search': true, 'page': $page, 'term_id': $('#place-area').val(), 'kodawari':[], 'tikunen':[], 'layout':[], 'menseki':[], 'yachin':[]};
  362. $('input[name="kodawari[]"]:checked').each(function() {
  363. $data['kodawari'].push($(this).val());
  364. });
  365. $('input[name="tikunen[]"]:checked').each(function() {
  366. $data['tikunen'].push($(this).val());
  367. });
  368. $('input[name="layout[]"]:checked').each(function() {
  369. $data['layout'].push($(this).val());
  370. });
  371. $('input[name="menseki[]"]:checked').each(function() {
  372. $data['menseki'].push($(this).val());
  373. });
  374. $('input[name="yachin[]"]:checked').each(function() {
  375. $data['yachin'].push($(this).val());
  376. });
  377.  
  378. $.ajax({
  379. type : 'POST',
  380. dataType : 'html',
  381. data : $data,
  382. success : function($html) {
  383. $html = $html.replace(/\r?\n/g, "");
  384. $html = $html.replace(/\t/g, "");
  385. var $articles = $html.match(/<div id="articles">.+?<!-- \/#articles -->/i);
  386. var $search_number = $html.match(/id="search-number"[^>]*?>([0-9,]+)/i);
  387. var $m_page = $html.match(/id="m-page"[^>]*?value="([0-9]+?)">/i);
  388. $('#m-page').val($m_page[1]);
  389. $('#search-number').text($search_number[1]);
  390. $('#articles').append($articles[0]);
  391. create_pager($page);
  392.  
  393. $('.flexslider').flexslider({
  394. animation: "slide",
  395. slideshow:false,
  396. directionNav:false,
  397. });
  398. },
  399. error : function($XMLHttpRequest, $textStatus, $errorThrown) {
  400. console.log($textStatus);
  401. },
  402. complete : function () {
  403. $('#loading').remove();
  404. }
  405. });
  406. }
  407.  
  408. function create_pager($current_page) {
  409. if ( $current_page == null ) {
  410. $page = 1;
  411. }
  412. else {
  413. $page = $current_page;
  414. }
  415. if ( !parseInt($('#m-page').val()) ) return;
  416. var $dom = '';
  417.  
  418. if ( $page > 1 ) {
  419. $dom += '<a href="javascript:void(0);" class="prev" data-action="paging" data-page="1">前へ</a>';
  420. }
  421. else {
  422. $dom += '<span class="prev not">前へ</span>';
  423. }
  424. var $next_page = parseInt($page) + 1;
  425. if ( $page < $('#m-page').val() ) {
  426. $dom += '<a href="javascript:void(0);" class="next" data-action="paging" data-page="' + $next_page + '">次へ</a>';
  427. }
  428. else {
  429. $dom += '<span class="next not">次へ</span>';
  430. }
  431. $('#pager').append($dom);
  432. }
  433. });
  434. </script>
  435. <?php endif; ?>
  436.  
  437. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement