Влезте в папката на Вашата тема и отворете с редактор файла functions.php
Поставете следният код, който ще добави специфичният CSS код в login хедъра:
<?
/**
* @desc attach custom admin login CSS file
*/
function custom_login_css() {
echo '<link rel="stylesheet" href="'.get_bloginfo('template_directory').'/inc/login.css" />';
}
add_action('login_head', 'custom_login_css');
?>
Сега вече може да предефинирате всички стилове, които искате. За примера аз ще използвам моят login screen:
.locale-bg-bg {
background-color: #f7f7f7 !important;
background-image: none !important;
background-image: url('bg-5.jpg') !important;
background-repeat: no-repeat !important;
background-position: 50% 0 !important;
background-attachment: fixed !important;
}
#backtoblog{
display:none !important;
}
.login form {
margin-top: 20px !important;
padding: 16px 17px 18px !important;
background: #fff !important;
-webkit-box-shadow: 0 1px 3px rgba(0,0,0,.13) !important;
box-shadow: 0px 0px 0px 0px rgba(0,0,0,.13) !important;
}
.login #nav {
margin: 10px 0 0 !important;
}
.login #backtoblog, .login #nav {
padding: 0px !important;
}
#nav a {
-moz-box-shadow:inset 0px -3px 7px 0px #29bbff;
-webkit-box-shadow:inset 0px -3px 7px 0px #29bbff;
box-shadow:inset 0px -3px 7px 0px #29bbff;
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #2dabf9), color-stop(1, #0688fa));
background:-moz-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
background:-webkit-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
background:-o-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
background:-ms-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
background:linear-gradient(to bottom, #2dabf9 5%, #0688fa 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#2dabf9', endColorstr='#0688fa',GradientType=0);
background-color:#2dabf9;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
display:inline-block;
cursor:pointer;
color:#ffffff !important;
font-family:Arial;
padding:2px 10px;
text-decoration:none;
text-shadow:0px 1px 0px #263666;
}
#nav a:hover {
background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0688fa), color-stop(1, #2dabf9));
background:-moz-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
background:-webkit-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
background:-o-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
background:-ms-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
background:linear-gradient(to bottom, #0688fa 5%, #2dabf9 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#0688fa', endColorstr='#2dabf9',GradientType=0);
background-color:#0688fa;
}
#nav a:active {
position:relative;
top:1px;
}
.login label {
color: #000000 !important;
font-size: 12px !important;
}
.wp-core-ui .button-primary {
-moz-box-shadow:inset 0px 39px 0px -24px #e67a73 !important;
-webkit-box-shadow:inset 0px 39px 0px -24px #e67a73 !important;
box-shadow:inset 0px 39px 0px -24px #e67a73 !important;
background-color:#e4685d !important;
-moz-border-radius:4px;
-webkit-border-radius:4px;
border-radius:4px;
border:1px solid #ffffff !important;
display:inline-block;
cursor:pointer;
color:#ffffff;
font-family:Arial;
font-size:17px !important;
padding:6px 15px;
text-decoration:none;
text-shadow:0px 1px 0px #b23e35 !important;
}
.wp-core-ui .button-primary:hover {
background-color:#eb675e !important;
}
.wp-core-ui .button-primary:active {
position:relative;
top:1px;
}
#loginform p label #user_login, #loginform p label #user_pass {
font-weight: normal;
padding: 8px 9px;
font-style: normal;
border-right-color: #dadada;
border-bottom-color: #dadada;
color: #999 !important;
border-radius: 4px;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
outline: none;
text-shadow: 0px 1px 0px #fff;
background-color: #fff;
background: -webkit-gradient(linear, left top, left bottombottom, from(#f9f9f9), to(#ffffff)) !important;
background: -webkit-linear-gradient(top, #f9f9f9, #ffffff) !important;
background: -moz-linear-gradient(top, #f9f9f9, #ffffff) !important;
background: -ms-linear-gradient(top, #f9f9f9, #ffffff) !important;
background: -o-linear-gradient(top, #f9f9f9, #ffffff);
}
#loginform p label #user_login:focus, #loginform p label #user_pass:focus, #loginform p label #user_login:hover, #loginform p label #user_pass:hover {
color: #777 !important;
background: #fff !important;
}
#loginform p label #user_login:-webkit-autofill, #loginform p label #user_pass:-webkit-autofill {
background-color: #fff !important;
}
#login h1 { display: block; position: relative; height: 99px; margin-top: 10px; }
#login h1 a {
background: #fff url('logo.png') no-repeat top center;
display: block;
position: relative;
right: 55px;
top: -50px;
width: 419px;
height: 160px;
}
В примера по-долу извиквам Media Library на WordPress, чрез натискане на картинка.
<script>
function getmedia(ident){
// Instantiates the variable that holds the media library frame.
var meta_image_frame;
// Runs when the image button is clicked.
j(function(){
// Prevents the default action from occuring.
// e.preventDefault();
// If the frame already exists, re-open it.
if ( meta_image_frame ) {
meta_image_frame.open();
return;
}
// Sets up the media library frame
meta_image_frame = wp.media.frames.meta_image_frame = wp.media({
// title: meta_image.title,
// button: { text: meta_image.button },
library: { type: 'image' }
});
// Runs when an image is selected.
meta_image_frame.on('select', function(){
// return false;
// Grabs the attachment selection and creates a JSON representation of the model.
var media_attachment = meta_image_frame.state().get('selection').first().toJSON();
// Sends the attachment URL to our custom image input field.
document.getElementById("imgc_"+ident).src = media_attachment.sizes.thumbnail.url;
//media_attachment.id; имате и id-то на самият attachment (за повече опции, проверете в WordPress документацията)
});
// Opens the media library frame.
meta_image_frame.open();
});
}
</script>
Ето това са картинките, чрез които ще извикваме Media Library и ще заменяме src адреса.
<img src="smiley.gif" id="imgc_1" alt="Smiley face" height="42" width="42" onclick="getmedia('1');"></br>
<img src="smiley.gif" id="imgc_2" alt="Smiley face" height="42" width="42" onclick="getmedia('2');"></br>
<img src="smiley.gif" id="imgc_3" alt="Smiley face" height="42" width="42" onclick="getmedia('3');">
<?php
// Add term page
function pippin_taxonomy_add_new_meta_field() {
// this will add the custom meta field to the add new term page
?>
<div class="form-field">
<label for="term_meta[custom_term_meta]"><?php _e( 'Example meta field', 'pippin' ); ?></label>
<input type="text" name="term_meta[custom_term_meta]" id="term_meta[custom_term_meta]" value="">
<p class="description"><?php _e( 'Enter a value for this field','pippin' ); ?></p>
</div>
<?php
}
add_action( 'category_add_form_fields', 'pippin_taxonomy_add_new_meta_field', 10, 2 );
Забележете това: {$taxonomy_name}_add_form_fields !
След като сте поставили кода би трябвало да виждате следното нещо:
За да направите така, че добавеното от вас поле да има възможността да се редактира е нужно да поставите и кода:
<?php
// Edit term page
function pippin_taxonomy_edit_meta_field($term) {
// put the term ID into a variable
$t_id = $term->term_id;
// retrieve the existing value(s) for this meta field. This returns an array
$term_meta = get_option( "taxonomy_$t_id" ); ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[custom_term_meta]"><?php _e( 'Example meta field', 'pippin' ); ?></label></th>
<td>
<input type="text" name="term_meta[custom_term_meta]" id="term_meta[custom_term_meta]" value="<?php echo esc_attr( $term_meta['custom_term_meta'] ) ? esc_attr( $term_meta['custom_term_meta'] ) : ''; ?>">
<p class="description"><?php _e( 'Enter a value for this field','pippin' ); ?></p>
</td>
</tr>
<?php
}
add_action( 'category_edit_form_fields', 'pippin_taxonomy_edit_meta_field', 10, 2 );
Резултата трябва да изглежда така:
Последната стъпка е да направите функцията, която ще запази вашето ново поле в базата:
// Save extra taxonomy fields callback function.
function save_taxonomy_custom_meta( $term_id ) {
if ( isset( $_POST['term_meta'] ) ) {
$t_id = $term_id;
$term_meta = get_option( "taxonomy_$t_id" );
$cat_keys = array_keys( $_POST['term_meta'] );
foreach ( $cat_keys as $key ) {
if ( isset ( $_POST['term_meta'][$key] ) ) {
$term_meta[$key] = $_POST['term_meta'][$key];
}
}
// Save the option array.
update_option( "taxonomy_$t_id", $term_meta );
}
}
add_action( 'edited_category', 'save_taxonomy_custom_meta', 10, 2 );
add_action( 'create_category', 'save_taxonomy_custom_meta', 10, 2 );
$labels = array(
'name' => _x( 'Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add Category' ),
'new_item_name' => __( 'New Category' ),
'menu_name' => __( 'Categories' )
);
register_taxonomy('portfolio_categories',array('portfolio'), array(
'hierarchical' => true,
'labels' => $labels,
'query_var' => true,
'show_ui' => true
));
add_filter('manage_edit-portfolio_categories_columns', 'add_portfolio_categories_column' );
‘hierarchical’ => true -> makes a difference between checkboxes and autosuggest
Влезте в папката на вашата тема и отворете файла functions.php.
Извикайте файла city.php.
require_once ('functions/city.php');
city.php
add_action( 'init', 'city_register');
function city_register() {
$labels = array(
'name' => _x('Cities', 'post type general name'),
'singular_name' => _x('City', 'post type singular name'),
'add_new' => _x('Add New', 'City'),
'add_new_item' => __('Add New City'),
'edit_item' => __('Edit City'),
'new_item' => __('New City'),
'all_items' => __('All Cities'),
'view_item' => __('View Cities'),
'search_items' => __('Search Cities'),
'not_found' => __('No cities found'),
'not_found_in_trash' => __('No cities found in Trash'),
'parent_item_colon' => '',
'menu_name' => 'Cities'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
'menu_icon' => 'dashicons-flag'
);
register_post_type('city', $args);
}
След като вече сте създали новия тип постове, може да го извикате в предната част на сайта по следният начин:
template-city.php
<?php
$args = array( 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order'=>'ASC', 'post_type' => 'city');
query_posts($args);
$lastposts = get_posts( $args );
?>
<?php
foreach ( $lastposts as $post ) :
$post_orig = $post;
setup_postdata( $post ); ?>
<div class="city">
<h3><?php the_title(); ?></h3>
<div class="thumb">
<?php the_post_thumbnail(array(500, 500)); ?>
</div>
<?php the_content(); ?>
</div>
<?php endforeach; ?>
<?php wp_reset_postdata();?>
<?php wp_reset_query();?>
Влезте във functions.php на вашата тема и първото нещо, което трябва да направите е да включите поддръжката на изображения чрез команда:
add_theme_support('post-thumbnails');
Новият вид изображения се декларират по следният начин:
add_image_size('prod-thumb', 353, 235, true);
add_image_size('prod-thumb-2', 353, 353, true);
Във фронтенд-а викате създадените от системата картинки:
$thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), "prod-thumb"); <img src="<?php echo $thumb[0] ?>" alt="" width="<?php echo $thumb[1] ?>" height="<?php echo $thumb[2] ?>" />
Отворете functions.php на вашата тема и поставете следния код:
$i = 1;
$args = array(
'name' => "Right sidebar",
'id' => "sidebar-$i",
'description' => '',
'class' => '',
'before_widget' => '',
'after_widget' => "\n",
'before_title' => '<h2 class="widgettitle">',
'after_title' => "</h2>\n",
);
register_sidebar( $args );
По този начин може да декларирате колкото ви трябват sidebars.
Визуализацията във фронтенд-а става чрез следната функция:
<?php dynamic_sidebar( 'sidebar-1' ); ?>
<form method="post" action="" enctype="multipart/form-data">
<p>
<input type="file" name="myfile" id="myfile" />
</p>
<p><input type="submit" value="Uploaden" id="submit" name="submit" class="submit" /></p>
</form>
// https://cube3x.com/upload-files-to-wordpress-media-library-using-php/
if(@$_FILES['myfile']['size']){
if ( ! function_exists( 'wp_handle_upload' ) ) require_once( ABSPATH . 'wp-admin/includes/file.php' );
if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) require_once( ABSPATH . 'wp-admin/includes/image.php' );
$uploadedfile = $_FILES['myfile'];
if($uploadedfile){
$upload_overrides = array( 'test_form' => false );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if ( $movefile ) {
$post = array(
'post_title' => time(),
'post_content' => '',
'post_status' => 'publish',
'post_type' => 'card'
);
$upload_post_id = wp_insert_post($post);
do_action('wp_insert_post', 'wp_insert_post');
$wp_filetype = $movefile['type'];
$filename = $movefile['file'];
$wp_upload_dir = wp_upload_dir();
$attachment = array(
'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
'post_mime_type' => $wp_filetype,
'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment( $attachment, $filename, $upload_post_id);
$attach_data = wp_generate_attachment_metadata($attach_id, $filename);
//dump($attach_data); die;
wp_update_attachment_metadata($attach_id, $attach_data);
set_post_thumbnail( $upload_post_id, $attach_id);
if($attach_id) header("Location: ".get_permalink(PAGE_ID_EXAMPLE));
}
}
}


