¡Esta es una revisión vieja del documento!
Core code files implement main Wordpress functions. /wp-includes/option.php, for example, contains functions for updating the site configuration, /wp-includes/pluggable.php and /wp-includes/ user.php contain function for updating users… Also exist /wp-includes/post.php, comments…
There is also the possibility to add more information to these elements (posts, users, comments…); to do that exists the concept of meta elements, which exists for other main elements in Wordpress.
wp-content\themes contains several folders, each one is an installed theme. You can develop your theme there.
WordPress themes only require two files: index.php and style.css. They usually are made up of many files and can become quickly disorganized. Still Wordpress does not need any folder you also can add a js and a css folders, in its root you'll place the template main files. There's also another especial folder, page-templates, where you will put the custom page template files.
So, to develop a theme you will create a folder with the name of the theme. There you will add an index.php file and a style.css.
WordPress uses the query string (a sequence of codes in a Uniform Resource Identifier (URI) that a web page uses to determine what dynamic data to display) to decide which template or set of templates should be used to display the page.
With the exception of the basic index.php template file, you can choose whether you want to implement a particular template file or not. If WordPress cannot find a template file with a matching name, it will skip to the next file in the hierarchy. If WordPress cannot find any matching template file, the theme’s index.php file will be used.
To add some logic to the template. The difference between functions.php and plugin.
A WordPress plugin:
A functions file:
In functions.php you can:
functions.php is loaded during theme setup, after any plugin files have loaded.
General uses for functions.php:
You will need to register and enqueue the plugins and styles. To do it, you must add a callback function to the head or the wp_enqueue_scripts event. To add it:
add_action( 'wp_enqueue_scripts', 'register_styles' );
Then, to register and enqueue:
function register_styles() { wp_register_style( 'my-plugin', get_template_directory_uri() . '/css/my_style.css' ); wp_enqueue_style( 'my-plugin' ); }
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.
Special wordpress templates. They are only to change the look and feel of a page (not a post); they can be applied to a single page, a page section or a class of pages. page-about.php is a page template, more specific than page.php or index.php.
When a user requests a specific page, the core WordPress code decides which template to use for rendering that page. Template Hierarchy:
index.php — Or else WordPress uses the theme’s index file.
Name your template file so you can easily identify its template name, e.g., filename my-custom-page.php for the template name “My Custom Page.” Important! Do not use page- as a prefix, as WordPress will interpret the file as a specialized template, meant to apply to only one page on your site.
For example: Your About page has a slug of ‘about’ and an ID of 6. If your active theme’s folder has a file named page-about.php or page-6.php, then WordPress will automatically find and use that file to render the About page.
It's used to display posts according to your instructions given by template tags. The basic loop is (while there are posts, display the posts):
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?>
The most simple index.php would be:
<?php get_header(); if (have_posts()) : while (have_posts()) : the_post(); the_content(); endwhile; endif; get_sidebar(); get_footer(); ?>
Other example:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_post_thumbnail(); ?> <?php the_excerpt(); ?> <?php endwhile; else: ?> <?php _e('Sorry, no posts matched your criteria.'); ?> <?php endif; ?>
WP_Query is a class given by WordPress to be used in the loop. For example $wp_query→have_posts() is called to see if there are any posts to show. To obtain a post $wp_query→the_post() is called. Also can be used to filter posts:
<?php $my_query = new WP_Query( $args ); ?> <?php while ($my_query->have_posts()) ? $my_query->the_post(); ?> // Do something <?php endwhile; ?>
They are used o control which templates are loaded on a certain page. Also which parts:
wp_head(), put it before </head> and wordpress will add required code for plugins.get_footer() includes the footer.php template file. get_header() includes the header.php template file. get_sidebar() includes the sidebar.php. Customized versions of these files can be called as well by naming the file sidebar-{your_custom_template}.php… You can then call the get_* functions with the custom template name as the only parameter, like this: get_header( 'your_custom_template' );.get_template_directory_uri(); & get_stylesheet_directory_uri();is_user_logged_in(), is_home(), is_front_page(), is_admin()…bloginfo('name'); to obtain information about the blog. Possible parameters: name, description, charset.the_title(); <head>
<meta charset="<?php bloginfo( 'charset' ); ?>">
<title><?php wp_title( '|', true, 'right' ); ?></title>
<link rel="stylesheet" href="<?php echo esc_url( get_stylesheet_uri() ); ?>" type="text/css" />
<?php wp_head(); ?>
</head>
You must indicate on the admin panel that the front page won't show the first post but content from a created page. Then…
<?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 -->