WordPress Core Contributor, WordPress Kaunas Meetup co-organizer, WordCamp (Lithuania 2015, Riga 2016, 2017, Stockholm 2016, 2017) speaker and one of the editors of the Lithuanian WordPress translation team.
Free & premium WordPress plugin developer:
Founder of Arunas.co and EcoSim / Vini.lt;
Lecturer at Kaunas College.
Puikus įskiepis, sukurtas
John Blackbourn
Privalomas bet kuriam WordPress developeriui
/*
Theme Name: Hello World!
Theme URI: https://arunas.co/
Description: A hello world theme
Author: Arūnas Liuiza
Version: 0.1
*/
<?php echo get_stylesheet_directory_uri(); ?>/
<?php wp_title(); ?>
Pasikartojantiems blokams:
Jei yra keli variantai:
Universali funkcija - get_template_part()
Pradžia
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
Turinio bloko HTML
Pabaiga
<?php endwhile; endif; ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article>
<h1><?php the_title(); ?></h1>
<p><?php the_author(); ?> / <?php the_date(); ?></p>
<div><?php the_content(); ?></div>
</article>
<?php endwhile; endif; ?>
page-apie.php // slug=apie
page-15.php // ID=15
page.php // visiems puslapiams
index.php // bendras
category-sportas.php
category-15.php
category.php
archive.php
index.php
post-thumbnails (featured image)
post-formats (image/quote/video/aside/kt...)
automatic-feed-links (RSS)
title-tag (vietoj <title>)
// functions.php
// add_image_size( $name, $width, $height, $crop );
add_image_size( 'temos-didelis', 800, 600, true );
// loop.php
the_post_thumbnail( 'temos-didelis' );
// style.css - theme headeryje
Text Domain: temos-katalogas
// visur kitur
__( 'Translatable text', 'temos-katalogas' );
_e( 'Translatable text', 'temos-katalogas' );
// style.css - theme headeryje
add_action( 'wp_enqueue_scripts', 'arunas_scripts' );
function arunas_scripts() {
wp_register_style(
'theme-style',
get_template_directory_uri(). '/style.css'
);
wp_enqueue_style( 'theme-style' );
wp_register_script(
'theme-script',
get_template_directory_uri(). '/script.js',
array( 'jquery' ),
'0.1.0',
true
);
wp_enqueue_script( 'theme-script' );
}
// functions.php
add_shortcode( 'vardas', 'vardas_shortcode' );
function vardas_shortcode( $args, $content ) {
return 'Petras';
}
// įrašo/puslapio tekste
[vardas]
// functions.php
add_shortcode( 'kitas', 'kitas_shortcode' );
function kitas_shortcode( $args, $content ) {
$defaults = array(
'title' => __( 'Some Title', 'temos-katalogas' ),
'description' => '',
);
$args = wp_parse_args( $args, $defaults );
$result = "<strong>{$args['title']}</strong>";
if ( $args['description'] ) {
$result .= "- <em>{$args['description']}</em>";
}
if ( $content ) {
$result .= '<br />' . do_shortcode( $content );
}
return $result;
}
// įrašo/puslapio tekste
[kitas title="Vardas" description="kardas"]tekstas[/kitas]
// functions.php
register_nav_menu( 'header-menu', 'Header Menu' );
// header.php
$args = array(
'theme_location' => 'header-menu',
'container' => 'nav',
'container_class' => 'my-menu-class',
);
wp_nav_menu( $args );
// Custom walker
// https://gist.github.com/kosinix/5544535
// functions.php
$args = array(
'name' => 'Main Sidebar',
'id' => 'sidebar-1',
'description' => 'Main widget area',
'before_widget' => '<li id="%1$s" class="widget %2$s">',
'after_widget' => '</li>',
'before_title' => '<h2 class="widgettitle">',
'after_title' => '</h2>',
);
register_sidebar( $args );
// sidebar.php
<ul id="sidebar">
<?php if ( ! dynamic_sidebar() ) : ?>
<li>{static sidebar item 1}</li>
<li>{static sidebar item 2}</li>
<?php endif; ?>
</ul>
// functions.php
function arunas_load_widget() {
register_widget( 'Arunas_Widget' );
}
add_action( 'widgets_init', 'arunas_load_widget' );
include_once( 'includes/arunas-widget.php' );
// https://gist.github.com/ideag/9a75ad25c16cbaf413f5110012260bbb
// loop-main.php
echo get_post_meta( get_the_id(), 'field_name, true );
// header.php
<body <?php body_class(); ?>
<?php
// The Query
$query1 = new WP_Query( $args );
// The Loop
while ( $query1->have_posts() ) {
$query1->the_post();
echo '<li>' . get_the_title() . '</li>';
}
wp_reset_postdata();
add_action( 'customize_register', 'arunas_customize_register' );
function arunas_customize_register( $wp_customize ) {
// registruoti customizer objektus
}
$wp_customize->add_setting(
'setting_id',
array(
'type' => 'theme_mod', // or 'option'
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
'default' => '',
'transport' => 'refresh', // or postMessage
'sanitize_callback' => '',
'sanitize_js_callback' => '', // Basically to_json.
)
);
$wp_customize->add_control(
'setting_id',
array(
'type' => 'date',
'priority' => 10, // Within the section.
'section' => 'colors', // Required, core or custom.
'label' => __( 'Date' ),
'description' => __( 'This is a date control with a red border.' ),
'input_attrs' => array(
'class' => 'my-custom-class-for-js',
'style' => 'border: 1px solid #900',
'placeholder' => __( 'mm/dd/yyyy' ),
),
'active_callback' => 'is_front_page',
)
);
WP_Customize_Color_Control
WP_Customize_Media_Control
WP_Customize_Upload_Control
WP_Customize_Cropped_Image_Control
$wp_customize->add_control(
new WP_Customize_Color_Control(
$wp_customize,
'color_control',
array(
'label' => __( 'Accent Color', 'theme_textdomain' ),
'section' => 'media',
)
)
);
$wp_customize->add_section(
'custom_css',
array(
'title' => __( 'Custom CSS' ),
'description' => __( 'Add custom CSS here' ),
'panel' => '', // Not typically needed.
'priority' => 160,
'capability' => 'edit_theme_options',
'theme_supports' => '', // Rarely needed.
)
);
Title | ID | Priority |
---|---|---|
Site Title & Tagline | title_tagline | 20 |
Colors | colors | 40 |
Header image | header_image | 60 |
Background image | background_image | 80 |
Menus (Panel) | nav_menus | 100 |
Widgets (Panel) | widgets | 110 |
Static Front Page | static_front_page | 120 |
default | 160 | |
Additional CSS | custom_css | 200 |
$wp_customize->selective_refresh->add_partial(
'setting_id', array(
'selector' => '.site-description',
'container_inclusive' => false,
'render_callback' => 'callback_function',
)
);