-
-
Save Pavel-Shulepov/73c091f44df25868e13a4d569e62d4c4 to your computer and use it in GitHub Desktop.
WordPress | Выборка постов и страниц по произвольным полям
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!--Выборка постов и страниц по произвольным полям--> | |
| <?php $args = array( 'post_type' => array('post', 'page'), | |
| 'meta_key' => 'order', | |
| 'orderby' => 'meta_value_num', | |
| 'order' => 'ASC', | |
| 'posts_per_page' => 3 ); ?> | |
| <?php $page_index = new WP_Query($args); ?> | |
| <?php if ( $page_index->have_posts() ) : while ( $page_index->have_posts() ) : $page_index->the_post(); ?> | |
| <div> | |
| <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('full'); ?></a> | |
| <h1><a href="<?php the_permalink(); ?>"><?php echo get_post_meta( get_the_ID(), 'title', true ) ?></a></h1> | |
| <?php the_excerpt(); ?> | |
| <p><a href="<?php the_permalink(); ?>" class="read-more">read more</a></p> | |
| </div> | |
| <?php endwhile; ?> | |
| <!-- post navigation --> | |
| <?php else: ?> | |
| <div> | |
| <p>Добавьте к страницам/записям произвольное поле "title" с неободимым заголовком для вывода на главную страницу</p> | |
| <p>Второе произвольное поле - "order" - будет использовано для сортировки</p> | |
| </div> | |
| <?php endif; ?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment