Cheatsheet

Tại đây bạn sẽ tìm thấy các function phổ biến giúp bạn phát triển giao diện WordPress. Đừng quên bookmark trang này lại nhé.

Đăng ký giao diện

File: style.css

/*
Theme Name: 
Theme URI: http://wordpress.org/
Description: 
Author: 
Author URI: 
Version: 1.0
Tags: 
License:
License URI:
*/

Cấu trúc file index

File: index.php

<?php
get_header();
?>

	<section id="primary" class="content-area">
		<main id="main" class="site-main">

		<?php
		if ( have_posts() ) {
			// Load posts loop.
			while ( have_posts() ) {
				the_post();
			}
			// Previous/next page navigation.
		} else {
			// If no content, include the "No posts found" template.
			
		}
		?>

		</main>
	</section>

<?php
get_footer();

Add Theme Support (functions.php)

File: functions.php

<?php
function mytheme_setup() {
  add_theme_support( 'title-tag' );
  add_theme_support(
    'html5',
    array(
      'search-form',
      'comment-form',
      'comment-list',
      'gallery',
      'caption'
    )
  );
  add_theme_support( 'responsive-embeds' );
}
add_action( 'after_setup_theme', 'mytheme_setup');

Đăng ký sidebar

File: functions.php

function mytheme_widgets_init() {
	register_sidebar(
		array(
			'name'          => __( 'Footer', 'mytheme' ),
			'id'            => 'footer-sidebar',
			'description'   => __( 'Add widgets here to appear in your footer.', 'mytheme' ),
			'before_widget' => '<section id="%1$s" class="widget %2$s">',
			'after_widget'  => '</section>',
			'before_title'  => '<h2 class="widget-title">',
			'after_title'   => '</h2>',
		)
	);
        // Register a second sidebar
        // register_sidebar();
}
add_action( 'widgets_init', 'mytheme_widgets_init' );

Load CSS và JS trong giao diện

function mytheme_assets() {
  // Load style
  wp_enqueue_style( 'mytheme-style', get_template_directory_uri() . '/assets/css/main.min.css', array(), wp_get_theme()->get( 'Version' ), 'all' );
  // Load javascript
  wp_enqueue_script( 'mytheme-script', get_theme_file_uri( '/assets/js/main.min.js' ), array(), '1.0', true );
  // Load comment style
  if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
    wp_enqueue_script( 'comment-reply' );
  }
}
add_action('wp_enqueue_scripts', 'mytheme_assets');

avatar
1 Comment threads
0 Thread replies
1 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Khôi Nguyễn Recent comment authors
  Subscribe  
newest oldest most voted
Notify of