Advertisement
Guest User

YanAlexandrov

a guest
Dec 29th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. Есть произвольный тип записи в function.php выглядит так:
  2. /* Регистрируем Лучшее и таксономию для них
  3. -----------------------------------------------*/
  4. add_action('init', 'thebest');
  5. function thebest()
  6. {
  7. $labels = array(
  8. 'name' => 'Лучшее',
  9. 'singular_name' => 'Лучшее',
  10. 'add_new' => 'Добавить лучшее',
  11. 'add_new_item' => 'Добавить новую позиию',
  12. 'edit_item' => 'Редактировать лучшее',
  13. 'new_item' => 'Новая позиция',
  14. 'view_item' => 'Посмотреть лучшее',
  15. 'search_items' => 'Найти лучшее',
  16. 'not_found' => 'Лучшее не найдено',
  17. 'not_found_in_trash' => 'В корзине лучшее не найдено',
  18. 'parent_item_colon' => '',
  19. 'menu_name' => 'Лучшее'
  20. );
  21.  
  22. $args = array(
  23. 'labels' => $labels,
  24. 'public' => true,
  25. 'publicly_queryable' => true,
  26. 'show_ui' => true,
  27. 'show_in_menu' => true,
  28. 'query_var' => true,
  29. 'rewrite' => true,
  30. 'capability_type' => 'post',
  31. 'has_archive' => true,
  32. 'hierarchical' => false,
  33. 'menu_position' => 5,
  34. 'menu_icon' => 'dashicons-heart',
  35. 'supports' => array('title','editor','thumbnail','comments','custom-fields', 'author'),
  36. 'taxonomies' => array('thebests')
  37. );
  38. register_post_type('thebest',$args);
  39. }
  40. register_taxonomy( 'rubrika-thebest', 'thebest', array( 'hierarchical' => true, 'label' => 'Рубрики', 'query_var' => true, 'rewrite' => true ) );
  41.  
  42. На странице page-best.php создаю форму:
  43. <form action="" method="get">
  44. <p><label>Поисковый запрос</label><br />
  45. <input type="text" name="word" value=""></p>
  46. <p><label>Диапазон цены</label><br />
  47. от <input type="text" name="min-price" size="3" value="">
  48. до <input type="text" name="max-price" size="3" value=""></p>
  49. <input type="submit" name="meta_key" value="price-products">
  50. </form>
  51.  
  52. На этой же странице вывожу в цикле
  53.  
  54. <?php
  55. $args = array(
  56. 'post_type' => 'thebest',
  57. 's' => $_GET['word'],
  58. 'meta_key' => $_GET['meta_key'],
  59. 'posts_per_page' => $_GET['num'],
  60. 'paged' => get_query_var( 'paged' ),
  61. 'order' => $_GET['order'],
  62. 'orderby' => $_GET['orderby'],
  63. 'tax_query' => array(
  64. array(
  65. 'taxonomy' => 'rubrika-thebest',
  66. 'field' => 'id',
  67. 'terms' => array($_GET['rubrika-thebest'])
  68. )
  69. ),
  70. 'meta_query' => array(
  71. array(
  72. 'key' => 'product-price',
  73. 'value' => array( (int)$_GET['min-price'], (int)$_GET['max-price'] ),
  74. 'type' => 'numeric',
  75. 'compare' => 'BETWEEN'
  76. )
  77. )
  78. );
  79. query_posts( $args ); ?>
  80.  
  81. Сам цикл
  82. <?php $thebest = new WP_Query( array( 'post_type' => 'thebest', 'posts_per_page' => 30 ) ); ?>
  83. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  84. <?php endwhile; else: ?><p>Извините, но у нас пока нет информации о товарах и услугах с выгодными ценами.</p>
  85. <?php endif; ?>
  86.  
  87. <div id="looop" class="liist">
  88. <?php while ( $thebest->have_posts() ) : $thebest->the_post(); ?>
  89.  
  90. <div <?php post_class('post clear'); ?> id="post_<?php the_ID(); ?>">
  91. <?php if ( has_post_thumbnail() ) :?>
  92. <a href="<?php the_permalink() ?>" class="thumb"><?php the_post_thumbnail('thumbnail', array(
  93. 'alt' => trim(strip_tags( $post->post_title )),
  94. 'title' => trim(strip_tags( $post->post_title )),
  95. )); ?>
  96. <?php elseif ( ot_get_option('placeholder') != 'off' ): ?>
  97. <img src="<?php echo get_template_directory_uri(); ?>/img/thumb-small.png" alt="<?php the_title(); ?>" /></a>
  98. <?php endif; ?>
  99.  
  100. <h2><a href="#" onclick="openbox('box-<?php the_ID(); ?>'); return false" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
  101.  
  102.  
  103. <div class="post-content"><?php if (function_exists('smart_excerpt')) smart_excerpt(get_the_excerpt(), 55); ?></div>
  104.  
  105. <div id="best-info">
  106. <div id="buy"><a href="<?php $my_meta = get_post_custom_values( 'author-website', $ID ); if ( $my_meta) { foreach ( $my_meta as $val_key => $val_val ) echo $val_val; } ?>" title="<?php the_title(); ?>" target="_blank">Где купить</a></div>
  107. <div id="price">&#8226; <?php $my_meta = get_post_custom_values( 'product-price', $ID ); if ( $my_meta) { foreach ( $my_meta as $val_key => $val_val ) echo $val_val; } ?> руб</div>
  108. </div>
  109.  
  110. <?php if (ot_get_option('excerpt-length') != '0'): ?>
  111. <div class="entry excerpt" id="box-<?php the_ID(); ?>" style="display: none;">
  112. <?php the_excerpt(); ?>
  113. <?php the_content(); ?>
  114. </div><!--/.entry-->
  115. <?php endif; ?>
  116. </div>
  117. <?php endwhile; ?>
  118. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement