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 12:23] alfred [Attaching CSS and JS] |
wiki2:wordpress [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 107: | Línea 107: | ||
| All of this code goes into the functions.php. | All of this code goes into the functions.php. | ||
| + | You also can use ''plugins_url()''(for Plugins) and ''get_template_directory_uri()'' (for Themes) to get a proper URL. | ||
| + | In the same way you will use ''wp_register_script'' and ''wp_enqueue_style''. | ||
| ==== Page templates ==== | ==== Page templates ==== | ||
| Línea 181: | Línea 183: | ||
| * Conditional functions: ''is_user_logged_in()'', ''is_home()'', ''is_front_page()'', ''is_admin()''... | * Conditional functions: ''is_user_logged_in()'', ''is_home()'', ''is_front_page()'', ''is_admin()''... | ||
| * [[https://developer.wordpress.org/themes/basics/conditional-tags/|Other functions to ask the template]] | * [[https://developer.wordpress.org/themes/basics/conditional-tags/|Other functions to ask the template]] | ||
| - | * ''bloginfo('name');'' to obtain information about the blog (name, title...) | + | * ''bloginfo('name');'' to obtain information about the blog. Possible parameters: name, description, charset. |
| * ''the_title();'' | * ''the_title();'' | ||
| Línea 193: | Línea 195: | ||
| <?php wp_head(); ?> | <?php wp_head(); ?> | ||
| </head> | </head> | ||
| + | </code> | ||
| + | |||
| + | === Create a front pate === | ||
| + | You must indicate on the admin panel that the front page won't show the first post but content from a created page. Then... | ||
| + | <code php> | ||
| + | <?php | ||
| + | /* | ||
| + | * Template Name: My Template | ||
| + | */ | ||
| + | get_header(); ?> | ||
| + | |||
| + | <div id="container"> | ||
| + | <div id="content" class="pageContent"> | ||
| + | |||
| + | <h1 class="entry-title"><?php the_title(); ?></h1> <!-- Page Title --> | ||
| + | <?php | ||
| + | // TO SHOW THE PAGE CONTENTS | ||
| + | while ( have_posts() ) : the_post(); ?> <!--Because the_content() works only inside a WP Loop --> | ||
| + | <div class="entry-content-page"> | ||
| + | <?php the_content(); ?> <!-- Page Content --> | ||
| + | </div><!-- .entry-content-page --> | ||
| + | |||
| + | <?php | ||
| + | endwhile; //resetting the page loop | ||
| + | wp_reset_query(); //resetting the page query | ||
| + | ?> | ||
| + | |||
| + | <?php | ||
| + | // TO SHOW THE POST CONTENTS | ||
| + | ?> | ||
| + | <?php | ||
| + | $my_query = new WP_Query( 'cat=1' ); // I used a category id 1 as an example | ||
| + | ?> | ||
| + | <?php if ( $my_query->have_posts() ) : ?> | ||
| + | <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> | ||
| + | <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> | ||
| + | |||
| + | <h1 class="entry-title"><?php the_title(); ?></h1> <!-- Queried Post Title --> | ||
| + | <div class="entry-content"> | ||
| + | <?php the_excerpt(); ?> <!-- Queried Post Excerpts --> | ||
| + | </div><!-- .entry-content --> | ||
| + | |||
| + | <?php endwhile; //resetting the post loop ?> | ||
| + | |||
| + | </div><!-- #post-<?php the_ID(); ?> --> | ||
| + | |||
| + | <?php | ||
| + | wp_reset_postdata(); //resetting the post query | ||
| + | endif; | ||
| + | ?> | ||
| + | |||
| + | </div><!-- #content --> | ||
| + | </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 ==== | ||