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''.
==== Page templates ====
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:
* Page Template — If the page has a custom template assigned, WordPress looks for that file and, if found, uses it.
* page-{slug}.php — Or else WordPress looks for and, if found, uses a specialized template named with the page’s slug.
* page-{id}.php — Or else WordPress looks for and, if found, uses a specialized template named with the page’s ID.
* page.php — Or else WordPress looks for and, if found, uses the theme’s default page template.
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.
==== The post loop ====
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):
The most simple index.php would be:
Other example:
=== Functions that cna be used ===
* [[https://developer.wordpress.org/themes/basics/the-loop/#what-the-loop-can-display]]
=== WP_Query ===
* [[https://developer.wordpress.org/reference/classes/wp_query/]]
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:
have_posts()) ? $my_query->the_post(); ?>
// Do something
==== Conditional tags ====
They are used o control which templates are loaded on a certain page. Also which parts:
* [[https://developer.wordpress.org/themes/basics/conditional-tags/]]
==== Useful functions to use on templates ====
* ''wp_head()'', put it before '''' 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();''
* 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]]
* ''bloginfo('name');'' to obtain information about the blog. Possible parameters: name, description, charset.
* ''the_title();''
==== How to... ====
=== Simple header ===
=== 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...
have_posts() ) : ?>
>
have_posts()) : $my_query->the_post(); ?>
=== Get all posts ===
Using the argument post_status=any and post_per_page=1:
$args = array(
'post_type' => 'post',
'orderby' => 'title',
'order' => 'ASC',
'post_status' => 'any',
'posts_per_page' => -1,
);
$my_query = new WP_Query($args);
=== Get a concrete page content ===
have_posts() ) : $the_query->the_post(); ?>
=== 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').
get_option('page_on_front'),
'post_type' => 'page',
'post_status' => 'publish',
'title_li' => '',
); ?>
==== Other functionalities ====
* [[http://codex.wordpress.org/Post_Thumbnails|Post thumbnails]]
* [[http://codex.wordpress.org/Custom_Headers|Custom headers]]
===== Plugins =====