Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:wordpress [2015/01/03 19:39] alfred [How to...] |
wiki2:wordpress [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 248: | Línea 248: | ||
| </div><!-- #content --> | </div><!-- #content --> | ||
| </div><!-- #container --> | </div><!-- #container --> | ||
| + | </code> | ||
| + | |||
| + | === Get all posts === | ||
| + | Using the argument post_status=any and post_per_page=1: | ||
| + | <code php> | ||
| + | $args = array( | ||
| + | 'post_type' => 'post', | ||
| + | 'orderby' => 'title', | ||
| + | 'order' => 'ASC', | ||
| + | 'post_status' => 'any', | ||
| + | 'posts_per_page' => -1, | ||
| + | ); | ||
| + | $my_query = new WP_Query($args); | ||
| + | </code> | ||
| + | |||
| + | === Get a concrete page content === | ||
| + | <code php> | ||
| + | <?php $the_query = new WP_Query( 'pagename=contact' ); ?> | ||
| + | <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> | ||
| + | <h2><?php the_title(); ?></h2> | ||
| + | <?php the_content(); ?> | ||
| + | <?php endwhile; ?> | ||
| + | <?php wp_reset_postdata(); ?> | ||
| + | </code> | ||
| + | |||
| + | === Get child pages from front page === | ||
| + | First you must obtain the ID of the front page, it's stored in the wp_options WP table, as option_name=page_on_front and option_value=ID of the page. So if you want to retrieve this value, just use get_option('page_on_front'). | ||
| + | |||
| + | <code php> | ||
| + | <?php $args = array( | ||
| + | 'child_of' => get_option('page_on_front'), | ||
| + | 'post_type' => 'page', | ||
| + | 'post_status' => 'publish', | ||
| + | 'title_li' => '', | ||
| + | ); ?> | ||
| + | <?php $children = wp_list_pages( $args ); ?> | ||
| + | <?php if ($children) : ?> | ||
| + | <ul> | ||
| + | <?php echo $children; ?> | ||
| + | </ul> | ||
| + | <?php endif; ?> | ||
| </code> | </code> | ||
| ==== Other functionalities ==== | ==== Other functionalities ==== | ||