X.
PROFESSIONAL
WordPress9
DESIGN AND DEVELOPMENT
Second Edition
Brad Williams
David Damstra
Hal Stern
WILEY
WordPress
.
.
X.
-
--
2014
32.988.02-018
004.738.5
36
., ., X.
36
ISBN 978-1118442272 .
ISBN 978-5-496-00948-5
..................................................................................................
18
............................
19
............................................................................................................ 20
1.
........................................................................26
2. ...........................................................................................50
3. WordPress ......................................................72
4. .......................................................................................... 90
5. (Loop)....................................................................................... 108
6. .......................................................................140
7. ,
.............................................................. 156
8. .................................................................. ....182
9. ................................................................................. 255
10. Multisite....................
311
.......................................................................................................... 18
.............
19
...............................................................................................
20
.......................................................................................................20
.................................................................................... 21
................................................................................................21
.................................................................................. 24
.............................................................................................................. 24
..............................................................................................................25
.................................................................................................................... 25
1. ...........................................................
.....26
WordPress?.....................................................................................
26
WordPress............................................................................................. 28
...........................................
28
...............
30
WordPress G P L.................................................................................................... 30
................................................................................................ 32
WordPress ....................................................... 32
............................................................................................ 34
............................................................................................................34
............................................................................................35
............................................................................................. 37
WordPress........................................................................
37
........................................................................... 40
................................................................................................................ 46
............................................................................... 46
....................................................................................................... 48
....................................................................................................................... 49
2. .......................................................................................... 50
..................................................................................................................... 50
................................................................................................... 50
.............................................................................................. 51
......................................................................................................... 51
.......................................................................................... 52
WordPress.................................................................................................. 53
wp-config.php................................................................................................ 54
wp-config........................................................................ 56
.htaccess................................................................................................................ 62
.maintenance................................................................................................. 67
wp-content..................................................................... 68
................................................................................................................68
..................................................................................................................... 69
..................................................................... 69
Upgrade.............................................................................................. 70
............................................................
70
....................................................................................................................... 71
3. WordPress ......................................................72
............................................................................. 72
.................
73
?..................................................................................... 74
.................................................... 75
............................................................... 75
WordPress ...................................................... 77
....................................................................................................... 78
-......................................................... 78
...................................................................................... 81
......................................................... 83
.................................................. 83
..................................................................... 86
............................................................................... 87
....................................................................................................................... 89
4. ..........................................................
90
?.......................................................................
90
......................................................................... 92
..................................................................................... 92
...................................................................................................... 93
..................................................................................................... 96
.....................
99
............................................................................100
WordPress
?................................................................................................100
........................................................................................100
.....................................................................................102
API WordPress.......................................................................................................103
....................................................................................................105
!...............................................................................................105
?.........................................................................................................106
.........................................................................106
.........................................................................................................
\
5. (Loop).................
108
.................................................................................................109
SQL...............................................................................110
WordPress.........................................................................112
................................................................................112
......................................................................................................114
............................................................................................................116
.......................................................................117
..................................................................................................118
..............................................................................118
WP_Query........................................................................119
......................................................................120
........................................................................... 123
query_posts() ...............................................................................124
get_posts() .................................................................................. 126
.................................................................
......................................................................................... 129
................................................................................................. 130
............................................................................................ 131
..................................................................................................... 132
10
10
.............................................................. .....................................133
...........................................................................................134
......................................................................................................134
?........................................................136
.......................................................................................................136
......................................................................................................................139
6.
...........
140
....................................................................................................140
...............................................................
WordPress.......................................................
WordPress............................................................................144
WordPress....................................................................................146
.............................................................................146
......................................................................147
...............................................................................................149
.............................................................................151
......................................................................................................................155
7. ,
.............................................................................156
WordPress.................................................................................156
?..............................................................157
......................................................157
.......................................................................163
.........................................................164
...................................................165
...............................................................................166
WordPress...............................................................................................168
...........................................................................168
..............................................................................169
.................................................................169
.........................................................................170
...................................................
.................................................................170
...........................................174
......................................................175
............................................................................................................... 177
?........................................................................................ 177
..........................................................................
.............................................................
170
178
11
..........................................................................................179
..................................................
..................................................................................
8. ..................................................
182
.................................................................................................. 183
.............................................................................
.................................................................................184
................................................................................................184
.......................................................................185
183
.......................................................................................... 186
.............................................................................................. 189
................................................................................................ 190
(Nonces).............................................................................. 191
................................................................................192
: ....................................................................195
.............................................................................................196
-....................................................
-.............................................................................199
.................................................. ;................................................ 201
.................................................
..............................................................................................202
......................................................................203
............................................................................206
WordPress.............................................................................................214
............................................................................................. 214
...............................................................................................218
................................................................................................219
............................................................................224
............................................................................225
........................................................................................227
.................................................................................228
....................................................
........................................................................................................247
..................................................................................................247
readme.txt..................................................................................248
SVN......................................................................................................251
...........................................
...................................................................
............................................................................................................
254
12
9. ...............................................
255
?........................................................................................ 255
..........................................................................................
FTP..................................................................................................257
256
.................................................................................................257
?.........................................................................................................258
....................................................................................................258
CSS.......................................................................................................................258
........................................................................................259
...............................................................................................................259
......................................................................................259
.......................................................................260
................................................................................ 261
. ....................................................................................262
: Style.css......................................................................................262
: Index.php............................................................................264
: index.php................................... 265
: DRY........................................................................................266
header.php............................................................................................................266
footer, php..............................................................................................................268
... sidebar.php..........................................................................................................
: ....................................................
268
269
: ............................................................270
: front-page.php...................................... 271
: archive.php............................................................273
: category.php.......................................................... 275
: tag.php...............................................................277
.................................................................................. 278
: single.php.......................................................... 278
: page.php................................................................
: attachment.php............................................280
..............................................................................................281
: .............................................. 282
404: 404.php...................................................................282
author, php.............................................................................................................284
comments.php...............................................................................
: functions.php................................... 286
search.php............................................................................ ............................... 289
searchform.php
.............................................................................................290
......................................................................................................291
280
13
..........................................................................292
.......................................... 292
.............................................. 293
Twenty Eleven........................................................................294
...........................................................................................295
............................................................................................... 295
............................................................
................................................................
.................................................................................................
300
.....................................................................................301
.................................................................................301
..........................................................306
Bones...........................................................................................................307
Carrington.....................................................................................................308
Genesis.........................................................................................................308
Hybrid Core...................................................................................................308
Roots....................................................................................................................309
StartBox.......................................................................................................309
Thematic......................................................................................................309
......................................................................................................................310
10. Multisite........................................................................................... 311
Multisite?....................................................................................................311
Multisite.........................................................................................312
...............................................................................................................312
Multisite.........................................................................................313
Multisite...............................................................................................313
.............................................................................................................315
..............................................................................315
.......................................................
.....................................
317
....................................................................................................317
............................................................................................................318
............................
318
Multisite.................................................. ,......................................319
...........................................................................................319
....................................................................................................319
.........................................................................................323
..................................................................................327
Multisite.............................................................................
.............................................................................................335
31
14
..........................................................................................338
.....................................................................................................339
Multisite.......................................................................................339
Multisite........................................................................ 340
.......................................................................... 340
......................................................................................................................341
11. .................................................
342
............................................................................................. 343
.................................................................................... 345
...........................................................................
, ?.......................................................................347
..........................................................................
348
........................................................................................... 349
YouTube................................................................................ 350
Twitter................................................................................................351
Google Maps......................................................................................................... 354
Facebook........................................................................................... 355
XM L................................................................................ 355
............................................................................................ 358
.....................................................................................................................360
...........................................................................
361
.......................................................................................... 362
........................................................................................... 365
......................................................................................................................367
12. .............................................. 368
............................................................... 369
.................................................................................................369
..................................................
................................................................................ 373
...........................................................................................374
JavaScript......................................................................................376
.....................................................................377
.................................................................................379
................. ...:............................381
........................................................................................383
.................................................................................385
........................................................................386
- .............................................387
HTML
.....................................................................................387
346
15
HTML....................................................................................................389
.............................................................................................
HTML5..................................................................................................................393
CSS3.....................................................................................................................395
..............................................................................................396
.................................................................396
...................................................................398
-......................................... 399
.............................................................................................400
..............................................................400
............................................................................................. 401
......................................................................................................................403
13. , , ............. 404
................................................................................................. 404
AWStats............................................................................................................... 405
Google Analytics................................................................................................... 408
WordPress JetPack....................., ..............................................................410
.................................................................................................... 412
WordPress............................................................................. 413
-............................................... 414
WordPress...............................................
................................................................................................... 418
MySQL............................................................................................419
WordPress........................................................ 420
.......................................................................................................422
.................................................................. 423
............................................................ 424
WordPress............................................................. 425
........................................ ................................................................425
WordPress.......................................................... 426
.............................................. 427
...................................................................... 427
............................................ ;................................428
......................................................................428
....................... >........................................ 428
.........................................................429
SSL . 430
Apache.......................................................................
MySQL.......................................................................431
................................. 431
390
16
\/155............................................................................ 435
: ..................
436
: .................................................................................................... 436
: ......................................................................................................... 436
: .................................................................................................... 437
: ........................................................................................... 437
: .................................................................................. 437
.........................................................................................................437
......................................................................................... 439
......................................................................................................................439
14. ........................440
............................................................................................. 440
.......................................................................... 442
............................................................ 443
................................................................................................. 444
.........................................................................................446
................................................................................. 447
............................................................................................ 449
............................................................................ 450
.............................................................................................. 453
..................................................................................
457
................................................................................................................457
..................................................................................................................457
...................................................................................... 458
.................................................................... 459
\/155 ......................................................................................... 459
\/155.................................................................. 460
......................................................................................................................461
, ,
. ,
.
,
.
, .
.
,
.
/ iStock.ph.oto
WebDevStudios.com,
W P Late Night, Professional WordPress (WordPress
) Professional WordPress Plugin Development (
WordPress). -
15 , 5
, WordPress.
WordCamp
WordPress WordCamp
.
http://strangework.com (@williamsba).
- CU* Answers,
, .
, - -
. , , WordPress
-. Zend
5. http://ws.cuanswers.com, ,
-,
-,
. http://mirmillo.com,
.
- ,
,
, .
,
Sun Microsystems, WordPress,
, , -
5 . WordPress, ,
URL .
, WordCamp.
http://snowmanonfire.com (@freeholdhal).
, , , ,
. ,
. WordPress ,
, .
, , , , ,
, . ,
, (
).
.
! , . W ordPress
-,
.
GPL
MySQL. ,
, WordPress,
, .
WordPress, , ,
HTML .
, , WordPress
-,
. WordPress
, , ;
-
, CNN. ,
,
- .
, , ,
WordPress :
, HTML?
* WordPress.
,
, . , -
, ,
. , ,
,
, , WordPress
, ,
.
, WordPress ,
21
, ,
. , ,
, ,
WordPress.
, ,
WordPress ,
WordPress, ,
, .
, : ,
WordPress, ,
. WordPress .
,
, ,
, .
WordPress,
, , ,
,
WordPress, .
. 1-4
WordPress,
, ,
WordPress . 5 -9
WordPress,
.
, WordPress
. , 10-14,
.
, .
1
WordPress; ;
, ,
; WordPress.
2
WordPress .
URL
22
,
HTML.
, .
3 WordPress
WordPress .
Microsoft Windows Apple.
, , , ,
.
4 ,
WordPress.
,
, .
,
.
5 (Loop) ,
. WordPress
MySQL,
, ,
, . ,
, ,
MySQL. , ,
,
WordPress.
6 5 MySQL.
,
MySQL ,
WordPress.
, MySQL,
,
, WordPress.
7 ,
WordPress.
WordPress.
. ,
WordPress.
8
, (hooks), (actions)
(filters),
23
W ordPress.
, , .
.
,
;
.
WordPress
WordPress.
9 8,
. ,
, CSS .
, ,
, , , ,
,
. .
10 Multisite W ordPress Multisite.
Multisite,
, , ,
.
Multisite ,
.
11 W ordPress .
- -,
.
-, WordPress API, WordPress ,
WordPress Facebook.
12 WordPress,
. ,
WordPress
, -
, Google.
11 WordPress,
,
.
,
WordPress.
13 , ,
. WordPress
,
. ,
.
, ,
24
,
.
14 WordPress ,
, WordPress
, .
HTML
(CSS),
.
,
,
.
, MySQL, ,
, ,
.
HTML.
(
, , vi ).
, ,
WordPress , , ,
, .
:
, - WordPress. 1
WordPress,
WordPress .
, ,
WordPress ,
WordPress:
. , ( );
, ,
.
- Wrox:
www.wrox.com/remtitle.cgi?isbn=9781118442272
, .
25
-------------------------------------------------------------------------, , ,
, .
------------------------------------------------------------------------- , , ,
.
:
.
:
p e rs is te n c e . properties.
:
.
, ,
, .
, , www.wrox.com.
:
www.wrox.com/remtitle.cgi?isbn=9781118442272
www.wrox.com .ZIP, .R A R
, . ,
, .
, .
, .
, ,
. ,
.
, :
www. wrox.com/remtitle.cgi?isbn=9781118442272
Errata.
.
:
WordPress
WordPress
, W ordPress
, !
,
-.
WordPress,
WordPress.
, ,
.
,
,
. , ,
WordPress,
2 .
WordPress?
WordPress
, ,
. TypePad,
Moveable Type, Google's Blogger Apache Roller, WordPress
WordPress?
27
,
() ().
,
, MySQL,
,
,
, ,
. WordPress ,
URL.
,
, .
WordPress,
.
WordPress
:
,
GPL.
b2/cafelog . WordPress
, .
WordPress 2003 MySQL
( ) .
,
.
, , WordPress
, , , ,
. WordPress
,
.
, WordPress ,
.
WordPress
, .
WordPress zedl.com
() . Automattic
- wordpress.com,
, Akismet,
WordPress Multisite Gravatar. Akismet ,
Automattic,
. WordPress MU, WordPress
Multisite wordpress.com
WordPress. Gravatar
, ,
. ,
28
1.
.
WordPress
. BuddyPress
, WordPress
,
, ,
, WordPress. bbPress
MySQL,
( ), WordPress,
.
WordPress
WordPress 3.5, .
WordPress ,
( (Dashboard)); ,
, .
WordPress,
.
. WordPress?
WordPress .
. 3 WordPress
. .
,
. Automattic 2011
100 WordPress (http://en.wordpress.com/
stats/). , WordPress ,
, , ,
, WordPress. WordPress
. Automattic 74
WordPress ,
wordpress.com (http://en.wordpress.com/stats/).
5 . 2008
WordPress 6300 , 2007 .
19 (http://
wordpress.org/news/2012/05/plugins-refreshed/).
WordPress 1500 ,
, .
,
,
WordPress
29
, .
, .
, , WordPress, .
2011
WordPress,
WordCamp -. WordPress
WordPress ,
. -,
, ,
WordPress.
, WordPress :
15 % 1 - W ord
Press.
22 100 WordPress.
200 .
18 000 170 000 .
wordpress.tv.
WordPress
, CNN, Wall StreetJournal's All Things D,
Reuters, Forbes , www.icanhazcheeseburger.
com. WordPress 500 , GM, UPS Sony.
.
, WordPress, ,
.
WordPress ( http://en.wordpress.com/notable-users/).
WordPress ,
, , - .
WordPress ,
. WordPress .
,
.
WordPress .
? wordpress.org :
. wordpress.org/extend, ,
, .
wordpress.org , .
wordpress.org/hosting , ,
30
1.
WordPress (
).
WordPress ,
.
:
.
WordCamp , .
. WordCamp
wordcamp.org, WordCamp
. WordCamp
, , , ,
, . WordCamp
WordPress. wordcamp.org,
, WordCamp.
, , WordCamp, WordPress
Meetup ( WordPress),
200 ( 40, ) .
meetup.com, , ,
wordpress.meetup.com,
, .
codex.
wordpress.org. WordPress,
, ,
WordPress, .
WordPress,
, , WordPress. ,
- .
, , ,
( ). :
codex.wordpress.org/mailing_lists. : wp-docs
, , wp-hackers ,
WordPress .
WordPress GPL
WordPress
GNU (GPL), 2, licence.txt
.
WordPress .
WordPress
31
- GPL
,
.
.
,
,
, .
, ,
WordPress . ,
. : WordPress CNN
Wall StreetJournal, ,
, , ,
.
GPL ,
GPL.
GPL,
, .
GPL . ,
.
WordPress, ,
, GPL
. , WordPress ,
,
.
, WordPress .
-
.
WordPress, ,
WordPress -. wordpress.com, Google
Linux-.
WordPress
- MySQL, ,
Apache WordPress;
WordPress.
( ,
, - ),
.
.
32
1.
, .
, - WordPress,
. ,
, . ,
WordPress.
GPL , WordPress.
, , WordPress,
WordPress. ,
.
WordPress GPL,
. , , ,
,
. : ,
, .
,
GPL, , ,
, , , .
, WordPress
, ,
.
WordPress
, .
,
, ,
.
, , ,
, WordPress
. .
, , . .
? ?
:
, ?
WordPress
:
, (,
33
), -
.
, ,
, ,
,
, ,
.
(CM S) , , ,
() ()
. CMS ,
,
.
WordPress
.
W ordPress
.
Drupal Joomla . Drupal Joomla
, ,
,
. WordPress , , .
.
,
. 14.
WordPress
. -- (Model-View-Controller),
. W ordPress : 1) MySQL ;
2) ;
3) ,
. , W ordPress
, WordPress
API. ,
, ,
HTML-, . ,
WordPress,
(), (),
, .
WordPress, , 6.
WordPress
, ,
( WordPress
).
34
1.
,
.
CMS .
,
.
, ,
. ,
. , ,
,
. , ,
, .
.
, ( ,
)? Twitter
, WordPress Twitter. :
Twitter WordPress,
. Facebook,
, Facebook
.
- , Google
,
. 11
WordPress
, 12
, WordPress.
, ,
(
WordPress ,
WordPress ,
, ). ,
:
.
.
,
.
35
.
MySQL, , WordPress,
? SQL
MySQL ,
, - .
. - Apache ,
MySQL W ordPress . ,
- ,
- . ,
,
(, -),
.
,
WordPress
, WordPress MySQL - .
WordPress,
.
wordpress.com, , Automattic
multi-site- WordPress ( WordPress MU).
,
, . ,
MySQL
WordPress . URL
wordpress.com,
URL, , , .
, ,
.
- www.wordpress,
org, wordpress.com.
WordPress
MySQL -.
.
, .
WordPress - ,
URL () MySQL. Apache
WordPress,
mod_php URL mod_rewrite. lighttpd
(Lighty) Apache, URL
. , IIS 7.0 Microsoft
36
1.
- U R L _ re w rite . URL
- WordPress ,
URL, , ,
. URL
MySQL,
WordPress
WordPress, 5. -
, WordPress
HTML , . h ta cc e ss,
URL ,
. URL
WordPress, ,
URL .
2, , WordPress.
MySQL ,
MySQL , .
MySQL, WordPress, MySQL.
MySQL,
.
, -, -
MySQL -.
MySQL, ,
, . WordPress
MySQL, ,
, WordPress MySQL
. WordPress
.
. (
-) MySQL
, ,
. MySQL
, ,
MySQL ,
MySQL MySQL.
WordPress ,
MySQL ,
WordPress ,
MySQL MySQL.
, ,
.
37
. -,
WordPress MySQL, , :
, .
W ordPress ,
.
, ,
,
WordPress MySQL.
( , -
MySQL ): WordPress
-, URL
. () .
WordPress ,
, ,
.
Mac OS X - Apache (
URL); MySQL www.mysql.conn
, (www.mamp.info, phpMyAdmin),
. , (www.apachefriends.org)
, Windows, MacOS
Linux.
, .
WordPress 3.
WordPress
WordPress www.wordpress.org, zip (
tarball), w ordpress.
WordPress -;
, , .
, , URL h ttp : / /
exam ple.com /w ordpress ,
. , , WordPress
,
.
, WordPress.
-, -, ,
38
1.
, public_html .
, ,
, , (, ,
, !).
- FTP-, ,
. zip
wordpress, ,
W ordPress http://example.com, http://example.com/
wordpress, , .
, WordPress
,
, WordPress
. .
WordPress ,
- . 1.1 index.php
wp-config- sample.php. WordPress,
- .
IS :\U seis\Sony\D ow nloads\w oidprcss-3.5-ru__R U \w oidpcess
j
J g lx
-- . . w. - --r-.~
^ j : wordpress
--- ----- -
* 4
4
26.11.2013 15:41
I wp-content
26.11.2013 15:41
|\ wp-includes
26.11.2013 15:41
index.php
08.01.2012 17:01
" "
license.txt
06.05.2012 7:28
20
readme.html
11.12.2012 16:45
14
wp-activate.php
17.11.2012 15:11
" "
wp-blog-header.php
08.01.2012 17:01
"PH P"
wp-comments-post.php
10.04.2012 17:21
" "
wp-config-sample, php
11.12.2012 16:45
" "
wp-cron.php
23.09.2012 16:57
" "
wp-links-opml.php
23.10.2010 12:17
"
wp-load.php
26.10.2012 19:40
" "
wp-login.php
30.11.2012 13:41
" "
29
wp-maH.php
25.09.2012 5:26
" "
wp-settings.php
22.11.2012 9:52
" "
10
wp-signup.php
11.09.2012 12:27
" "
18
wp-tiackback.php
08.01.2012 17:01
" "
xmlrpc.php
11.09.2012 20:11
"
wp-admin
: 19
: 19 .
...................
. 1.1. , WordPress
39
,
wp- co n f i g . php,
WordPress .
, WordPress ,
, ,
. 1.2 1.3, .
MySQL, ,
- conf ig . php . .
?
wp-conf ig . php -,
,
-.
wp_halstern
,
WP.
wp_user1
MySQL
foobar
... MySQL
localhost
wp_hs
lo c a lh o s t ,
-
WordPress ,
.
. 1.3.
40
1.
WordPress ( wp_ ).
,
. , ,
, , W ordPress ,
MySQL
, .
, HTML
WordPress ?
, , , , ,
. WordPress
, ,
,
WordPress.
WordPress , in d e x .h tm l,
. :
in d e x .h tm l WordPress, in d e x .p h p
in d e x . htm l,
Directory Index - .
, ,
.
, , ,
, WordPress .
WordPress ,
URL ,
WordPress.
-
wp-config. php , URL , WordPress
, - WordPress ,
. 1.4. , -
admin.
, . 1.5, ,
.
MySQL WordPress
, , SQL
. ,
.
- MySQL
, w p-config.php,
41
. MySQL,
, , MySQL .
,
, . ,
,
,
.
MySQL W ordPress
. , MySQL , MySQL
WordPress, ,
W o r d P r e ss
!
. ,
!
, , ,
.
* , , , ,
01.
,
,
*.
, !* 7 3 4 * 3 ).
freeholdhat@gmail.com
,
I WordPress |
. 1.4. -
42
1.
(^ IW o r d P ress
WordPress ? , )
halbstem
. 1.5.
WordPress.
MySQL phpMyAdmin
Chive, , MySQL
, ( -)
. MySQL
, root
Unix, root- Unix.
MySQL
MySQL,
, MySQL.
MySQL, , , ,
MySQL,
MySQL ( http://dev.mysql.com/doc/) ,
MySQL.
WordPress
. -
, ,
MySQL. : ,
( ) MySQL,
MySQL. , . 1.3, wp_
, ,
, WordPress.
WordPress MySQL?
. ,
.
1. - MySQL. MySQL wpconfig. php , -
43
MySQL - . .
MySQL MacOS MySQL /tm p /m y s q l.s o c k
, - WordPress / v a r / m y s q l/ m y s q l.
sock PH P- MySQL.
:
# In -s /tmp/mysql.sock /var/mysql/mysql.sock
MySQL
; .
, ,
, . ,
,
p r i n t f ().
w p -in c lu d e s / w p - d b .p h p , ,
WordPress.
(Error establishing
database connection) , e c h o ( m y s q l_ e rro r ( ) )
, ,
. 1.6:
if (!$this->dbh) {
echo(mysql_error());
$this->bail(sprintf(/*WP_I18N_DB_C0NN_ERR0R*/"
<hl>Error establishing a database connection</hl>
c.
, -conf ig . php ,
lo c a lh o s t. ,
, ?
, ?
, ?
, , -.
WordPress.
. 1.6. mysql_error( )
m y s q l_ e rro r( ) ,
, MySQL.
2. WordPress MySQL, .
MySQL, ,
-.
44
1.
, wp-config.php.
MySQL 4.1 MySQL 5.0 ,
.
MySQL 4.0. OLD_PASSWORD()
WordPress ,
. SQL (
MySQL SQL ):
SET PASSWORD FOR user@host = 0LD_PASSW0RD(password') ;
user@host WordPress
, a password () ,
.
3. WordPress MySQL, . ,
-
WordPress, ,
, . ,
mysql_error ()
wp-dp. php, :
function select($db) {
if (!@mysql_select_db({db, $this->dbh)) {
$this->ready = false;
echo(mysql_error());
{this- >bail(sprintf(/*WP_I18N_DB_SELECT_DB*/'
... <hl>Can't select database</hl>
m ysql_error(), ,
. 1.7, MySQL
, .
, MySQL, :
% /usr/local/mysql/bin/mysql -u wp_userl -
Enter password:
Welcome to the MySQL monitor. Commands end with; or \g.
Your MySQL connection id is 174
Server version: 5.1.37 MySQL Community Server (GPL)
mysql> show databases;
------------------
| Database
------------------
| information_schema |
1 test
j
H------------------
45
( , ),
w p_ h alsternl
, ?
wp_useri w p_ h a lstern i?
,
- usemamejvordpress. , ?
, , -
, WordPress.
. 1.7. MySQL
MySQL
MySQL,
, :
mysql> create database wp_halstern;
Query OK, 1 row affected (0.00 sec)
: ,
MySQL WordPress. MySQL
,
. WordPress
WordPress, .
, WordPress.
WordPress, ,
, wp-config.php. :
, MySQL:
mysql> use wp_halstern; show tables;
Database changed
-i------------------ h
| Tables_in_wp_halstern
------------------+
|
|
|
|
|
|
|
|
|
|
wp_hs_comments
wp_hs_links
wp_hs_options
wp_hs_postmeta
wp_hs_posts
wp_hs_term_relationships
wp_hs_term_taxonomy
wp_hs_terms
wp_hs_usermeta
wp_hs_users
------------------+
10 rows in set (0.00 sec)
*
|
46
1.
wp_hs_;
WordPress,
,
, .
WordPress 6. , MySQL,
.
MySQL .
, - WordPress.
.
,
, . 1.4,
WordPress, . 1.8.
Pyrk
d'ld Fnemb
:, ha! stern
(}
\/5$ 3.5
&
(
! / 3.5 ,
- . , .
@
$
1[$
. 1.8.
(Log In)
URL , ,
47
wp-admin (e x a m p le . com/wp-admin),
, .
WordPress,
.
, ,
. , ,
WordPress, (Update),
.
WordPress
( w p -a d m in /in c lu d e s /u p d a te .p h p , ).
,
MySQL,
r o o t @ lo c a lh o s t , *
- .
, ,
.
11. w p - c o n fig .p h p
. ,
WordPress
. URL :
-,
, . 1.8.
MySQL,
.
, , URL
W ordPress, (Settings)
(General), ,
WordPress. URL
W ordPress, , in d e x .p h p ,
,
WordPress.
,
, , ,
,
. ,
.
.
,
,
,
.
48
1.
WordPress
,
.
, QuickPress ( )
(,
) (Posts)
(Add New), WordPress.
. 1.9 .
.
* 'V
9V
yj-j :
/
iN U n L j lb
5g)
e W o rd P re ss!
> :
{1
g*
'
$|
re
iMaJ2WC-iO&t.SWti
&
cpft
Iff!
. m u e
A *
0^5 !
. noesi
+.
Twenty Twelve,
; ! ; :
WordPress 3.5
WordPress , ! *
1 . ,
,\0> ! ! "?! {
WordPress
The B<st seta of the 3.8 is now avalisoie. and the n*i dates to water out tor m e cod free/e on
Decerncer 5th and a final release on Decem&er 12th 3.8 Orinps tosefiier several of the
feaiuies as plugtns project* and winte mis tetn l uur tad roOeo, pea this to tie tnwe beta
than usual. | }(. .}
. 1.9.
,
, .
WYSYIWIG, Microsoft
Word OpenOffice, WordPress HTML,
. ,
, Illumnix Ecto,
WordPress Atom Publishing Protocol XML-RPC.
49
, ,
(Writing options).
(Publish), , , : , !
,
,
HTML.
.
.
, WordPress ,
.
W ordPress
. WordPress
, ,
.
:
WordPress
wp-config.php .htaccess
wp-content
WordPress
WordPress ,
,
. , ,
WordPress .
, WordPress
,
WordPress, wp-config. php . htaccess.
,
WordPress.
WordPress
, WordPress.
.
W ordPress
WordPress.org, http://wordpress.org/download/.
51
WordPress WordPress,
(Updates), .
(Download),
WordPress .
WordPress Subversion (SVN). Subversion
. WordPress Subversion
, .
WordPress, http://
core.svn.wordpress.org/trunk/.
SVN
WordPress.
. .
SVN ,
WordPress. SVN
() WordPress.
WordPress
zip la t e s t . zip. W ordPress tar
la te s t.ta r .g z . ,
.
zip tar :
http://wordpress.org/latest.zip
http://wordpress.org/latest.tar.gz
. WordPress
.
, WordPress, wordpress3.5. zip. , WordPress
.
WordPress.org WordPress.
WordPress 0.71.
http://wordpress.org/download/release-archive/.
,
WordPress, , ,
, , .
, ,
52
2.
,
.
, WordPress.
WordPress
. , WordPress
,
, , .
-
WordPress. , WordPress
.
,
WordPress, .
WordPress WordPress ,
.
WordPress ,
JavaScript CSS. .
, ,
, , WordPress.
WordPress WordPress.
WordPress
WordPress, . 2.1.
W ordPress : w p -a d m in , w p - c o n t e n t
w p -in c lu d e s . wp-admin wpin c lu d e s , WordPress.
w p -co nten t , ,
. ,
WordPress. HTM L- WordPress,
, MySQL ,
, 6.
WordPress
. , ,
WordPress,
.
WordPress,
. ,
WordPress ,
WordPress ,
, , ,
. -
WordPress
jfc wp-admin
26.11.2013 15:41
L wp-content
26.11.2013 15:41
1, wp-indudes
26.11.2013 15:41
08.01.2012 17:01
"*'
06.05.2012 7:28
fndex.php
license.txt
readme.html
11.12.2012 16:45
wp-activate.php
17.11.2012 15:11
""
J wp-blog-header.php
08.01.2012 17:01
""
J wp-comments-post.php
10.04.2012 17:21
""
J]
11.12.2012 16:45
""
3 wp-cron.php
wp-conflg-sample.php
23.09.2012 16:57
""
3 wp-links-opml.php
23.10.2010 12:17
""
J wp-load.php
26.10.2012 19:40
""
3 wp-logln.php
30.11.2012 13:41
""
j wp-mail.php
25.09.2012 5:26
""
3 wp-settings.php
22.11.2012 9:52
""
wp-signup.php
11.09.2012 12:27
""
3 wp-trackback.php
08.01.2012 17:01
""
3 xmlrpcphp
11.09.2012 20:11
""
53
. 2.1. WordPress
WordPress
, .
WordPress, wpadmin, w p-includes ,
,
. ,
4: !
WordPress
W ordPress ,
. WordPress.
,
.
,
FTP,
w p-config. php. . htaccess,
, .
54
2.
wp-config.php
WordPress wp-config.php.
, ,
MySQL.
.
wp-config.php wp-config-sample.php.
wp-config. php WordPress.
wp-config. php WordPress.
wp-config .
WordPress :
/public_html/my_website/wp-config.php
:
/public_html/wp-config.php
WordPress wp-config , ,
, . ,
.
------------------------------------------------------------------------- w p -c o n fig .p h p WordPress
,
.
WordPress ,
wp-config. php. :
define( 1OPTION_NAME1, 'value' );
, ; v a lu e
,
. wp-config. php
:
OPTION_NAME
/ * , . !
*/
\55* ,
, .
(Error establishing a database connection),
, DB_NAME, DB USER DB_PASSWORD
. , DBJHOST
. localhost,
WordPress -
MySQL ,
MySQL.
WordPress
55
, .
( c h a rs e t) ,
DB_CHARSET. u t f 8 (Unicode UTF-8).
.
WordPress 2.2 DB_COLLATE
, . (
, .
, .)
.
, ,
. WordPress.
WordPress.
WordPress , w p - c o n f ig . php
. ,
()
. WordPress,
.
w p - c o n f ig . p h p WordPress.org (https://api.
wordpress.org/secret-key/1.1/salt/), . 2.2.
(put your unique phrase here).
, 100 % .
1
h t t p v /.'a p i.w o (d p r .o r g .T
\ * ( +
, >
* / f
4% - F
5 ,
d e f i n e ( *A D T H J Y ',
d e f i n e ( SEC0RE_AUTH_XE Y * ,
d e f i n e ( LOGGED~IN_KY',
d e f i n e ( *N0NCE_KEY ,
d e f i n e ( , AOTH_SA,T\
d e f i n e ( SECORE_ATH_SALT ,
d e f i n e <LOGGED _IN _SA LT',
d e f i n e ( NONC_SALT ,
. 2.2.
. ,
: WordPress ,
.
, w p - c o n fig . php,
WordPress.
wp_. ,
$ t a b le _ p r e f i x , , :
$table_prefix = 'bwar_;
56
2.
, SQL-,
, , ,
SQL-.
WordPress .
WordPress,
W P Security Scan (http://wordpress.org/extend/plugins/wp-security-scan/).
, , .
wp-config WordPress.
W ordPress
. WPLANG WordPress .
, wp-content/languages
( ).
( ),
WordPress .
GNU gettext, WordPress. ,
:
WordPress (in Your Language) http://
codex.wordpress.org/WordPress_in_Your_Language
WordPress , WP_DEBUG.
, WP_DEBUG WordPress ,
. WP_DEBUG,
true:
define( 'WP_DEBUG', true );
wp-config
wp-config .
, .
WordPress , :
define( 'WP_SITEURL', 'http://example.com/wordpress' );
define( W P H O M E 1, 'http://example.com/wordpress' );
WordPress
57
2.6 ,
w p -co n te n t. :
define( 'WP_C0NTENT_DIR', $_SERVER['DOCUMENT_ROOT] .
'/wordpress/blog/wp-content' );
define( 'WP_CONTENT_URL', 'http://domain.com/wordpress/blog/wp-content);
WP_CONTENT_DIR
w p -c o n te n t. WP_CONTENT_URL URI .
:
define( 'WP_PLUGIN_DIR', $ SERVER['DOCUMENT_ROOT'] . '/blog/wp-content/plugins );
define( 'WP_PLUGIN_URL', 'http://example/blog/wp-content/plugins');
WP_PLUGIN_URL ,
.
, ,
w p-content.
w p -c o n te n t
.
WP_PLUGIN_DIR
WordPress
. (Save)
(Publish) WordPress
. , 10 .
100 , 1.000 . ,
,
,
. , WordPress
WP_POST_REVISIONS. f a ls e ,
,
, .
:
define( 1WP_POST_REVISIONS', false );
define( 'WP_POST_REVISIONS1, 5 );
58
2.
,
WordPress AJAX. 60 .
wp-config.
5 , :
AUT0SAVE_INTERVAL.
SAVEQUERIES.
,
.
, , WordPress
.
, ,
WordPress . ,
tru e :
define( 'SAVEQUERIES', true );
,
:
if ( current_user_can( 'manage_options' ) ) {
global $wpdb;
print_r( $wpdb->queries );
>
,
.
,
. 9 .
()
wp-config. ,
php_error. log WordPress.
log_errors :
@ini_set( *log_errors','On' );
@ini_set( 'display_errors', 'Off' );
@ini_set( 'error_log','/public_html/wordpress/php_error.log' );
, ,
WP_DEBUG, .
d is p la y _ e rro r s O ff,
, , .
,
. , e r r o r _ lo g
-, WordPress.
,
W ordPress, WP_MEM0RY_LIMIT.
WordPress
59
WordPress ,
(Allowed memory size of xxxxx bytes
exhausted). .
:
define( 'WP_NIEMORY_LIMIT', '32' );
,
.
.
,
, - ,
.
WordPress,
, .
, ph p _ valu e m e m o ry_ lim it p h p .in i.
, , ,
, , , .
WordPress .
WordPress ,
, .
WPLANG WordPress :
define ( WPLANG', 'en-GB' );
, , ISO-639,
ISO-3166. , en-GB (
). . . .
LANGDIR. ,
.. .
WordPress w p -co n te n t/la n g u a g e s . ,
LANGDIR:
define( 'LANGDIR', '/wp-content/bury/my/languages' );
W ordPress .mo .
CUSTOM_USER_TABLE CUSTOM_USER_META_TABLE .
, WordPress
.
WordPress.
define( 'CUSTOM_USER_TABLE', 'joined_users );
define( 'CUSTOM_USER_META_TABLE', 'joined_usermeta' );
WordPress .
, , ,
60
2.
, . .
WordPress, .
,
WordPress, - ,
CUSTOM_USER_META_TABLE. , ,
, (
, . .).
, C00KIE_D0MAIN,
SITEC00K IEPATH .
WordPress Multisite, .
,
:
C00KIEPATH
,
, .
,
FTP
wp-config. ,
, ,
WordPress FTP.
FTP WordPress, wp-config
:
d e f i n e ( ' F T P_U SER ' ,
d e f i n e ( ' FTP_PASS' ,
d e f i n e ( 1FTP_HOST' ,
'u se rn a m e ' );
'p a s s w o r d ' );
' f t p . e x a m p le .co m :2 1 '
);
FTP, !
WordPress FTP
.
FT P/SSH
:
// : "direct", "ssh", "ftpext", "ftpsockets"
define( 'FS_METHOD', 'ftpext' );
// , WordPressabsolute path to
root installation directory
define( FTP_BASE', '/public_html/wordpress/' );
// wp-content
define( 'FTP_CONTENT_DIR', '/public_html/wordpress/wp-content/ );
// wp-plugins
define( 'FTP_PLUGIN_DIR ', '/ public_html /wordpress/wp-content/plugins/' );
// SSH
define( 'FTP_PUBKEY', '/home/username/.ssh/id_rsa.pub' );
WordPress
61
// SSH
define( 'FTP_PRIVKEY', '/home/username/.ssh/id_rsa' );
// SSL- FTP,
define( 1FTP_SSL', false )j
, WordPress
, FS_CHMOD_FILE FS_CHM0D_DIR:
define( 'FS_CHMOD_FILE',0644 );
dfine( 'FS_CHMOD_DIR',0755 );
(User), (Group) (W orld),
-. WordPress
, http://codex.wordpress.org/Changing_File_Permissions.
,
. , WordPress
.
WP_CACHE -.
w p -co n te n t/a d va n ce d -c a c h e , php.
, :
define( 'WP_CACHE', true );
WordPress ,
. , ,
:
print_r( @get_defined_constants() );
WordPress. HTTPS,
, , .
SSL, F0RCE_SSL_L0GIN :
define( 'FORCE_SSL_LOGIN', true );
SSL.
F0RCE_SSL_ADMIN:
define( 'FORCE_SSL_ADMIN1, true );
62
2.
SSL WordPress
. , WordPress, ,
WordPress.
2.9 WordPress .
, , , .
, WordPress.
30 .
. ,
EMPTY_TRASH_DAYS:
define( 'EMPTY_TRASH_DAYS', 7 );
7 .
, 0.
(Delete Permanently).
, WordPress .
WordPress cron. Cron WordPress
.
WordPress, . WordPress cron,
wp - c o n f ig:
define( 1DISABLE_WP_CRON', true );
w p -c o n fig . WordPress .
: http://codex.
wordpress.org/Editing_wp-config.php.
.htaccess
. htaccess
URL . W ordPress
,
, , , http://example.com/?p=45. URL
,
. , WordPress URL
, ,
.
,
WordPress, . 2.3.
, ,
(Save Changes).
WordPress
63
, WordPress . h ta c c e s s .
WordPress ,
. WordPress . h ta c c e s s ,
, . 2.4.
'' ,
,
h t t p : / / l o c a l h o s t /214/1/231*-p o s t/
h t t p - ./ /l o c a l h o s t/ t r u n k / e iV e i/s e J * p le -p o s t/
h t t p :/ / l o c e l h o s t / t r u n l c / e r e h l v e s / l2 J
h t t p : / / l o c a l h o s t / t runlc/sam ple-post/
, -
, .
. 2.3. WordPress
.h ta c c e s s
.h ta c c e s s .
ctrl
+ * .
<lfModule mod_rewrtte.c>
RewriteEngine On
RewriteBase I
RewriteRule NndexVphpS - [Li
RewrtteCond %{REQUEST_FILENAME} !4
RewriteCond %{REQUEST_FILENAHE) !-d
. 2.4. .htaccess
, , ,
/%year%/%monthnum%/%postname%/
:
http://example.com/2012/10/halloween-party/
64
2.
, :
(SEO). URL
SEO.
.
. ,
(WordPress, Drupal, Joomla!),
.
. URL,
, .
, .
. -
.
URL
.
.htaccess
- URL,
, ,
HTML, .
WordPress, w p - lo g in . php,
. , exam ple. co m /2 0 1 2 /tra v e l/
haddonf ie ld , - WordPress,
URL ,
Haddonfield Travel.
,
, WordPress .
.
WordPress
, .h t a c c e s s
:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [ L]
. URL,
, ,
. ! -f ! -d
; . h ta c c e s s , URL -
. URL
, WordPress, w p - lo g in . php,
- (
WordPress
65
). , URL,
, in d e x.
php, WordPress. ,
URL MySQL,
5.
-------------------------------------------------------------------------
, , WordPress,
, WordPress. , ,
wp-content: example.com/wp-content example.com/images.
WordPress,
. ,
URL , ?
.htaccess ,
, WordPress.
404 URL.
WordPress,
WordPress (example.com/wordpress),
.htaccess ,
URL -:
RewriteRule Aimages/(.*) images/$l [L]
, : URL, images,
-. [L] :
,
, . ,
WordPress,
.
.htaccess URL.
(About) http://example.com/about http://example.
com/about-me, , , 404.
URL ,
. URL ,
.
301
:
redirect 301 /about http://example.com/about-me
WordPress URL
, 5.
.htaccess
. htaccess , ,
URL. , . htaccess,
66
2.
. , ,
:
php_value memory_limit 64
64 .
:
php_value upload_max_filesize 20
php_value post_max_size 20M
,
, 20 .
2 ,
.
. h ta c c e s s ,
.
.h ta c c e s s .
.h t a c c e s s 1-,
, .
IP -, .h ta c c e s s :
AuthllserFile /dev/null
AuthGroupFile /dev/null
AuthName "Access Control"
AuthType Basic
order deny,allow
deny from all
#IP address to whitelist
allow from xxx.xxx.xxx.xxx
x x x. x xx . xx x. xxx IP -,
. a llo w from , ,
IP-, .
IP -, .
wp-admin.
URL
IP -, WordPress
. , . h ta cc e s s
wp-admin.
, -
, IP -
. ,
. h ta c c e s s , IP-, .
, ,
wp-admin.
WordPress
67
IP -,
. , 123.123.123. * ,
IP - ,
. , 123.123.123.110-230
IP - 123.123.123.110 123.123.123.230.
. h t a c c e s s .
p h p - e r r o r s . lo g W ordPress.
. h ta c c e s s ,
:
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_flag log_ernors on
php_value error_log /public_html/php-errors.log
,
- . ,
, .
.maintenance
WordPress ,
.m ain ten an ce. . m ain ten an ce
W ordPress .
-
WordPress. ,
.m ain ten an ce :
<?php {upgrading = time(); ?>
WordPress,
. ,
: - .
(Briefly unavailable for scheduled maintenance. Check back in a minute).
time( )
UNIX.
, m ain ten an ce. php
w p -co n te n t. WordPress
.
.
W ordPress. . m a in t e n a n c e ,
68
2.
\VordPress .
,
.
wp-content
wp-content
WordPress. ,
WordPress .
wp-content index.php.
:
<?php
// Silence is golden.
// - .
?>
? .
wp-contents. index.php ,
- ,
http://example.com/wp-contents,
. ,
. , ,
WordPress
,
.
WordPress , ,
wp-content.
w p-content/plugins.
.
/p lu g in s WordPress, ,
W ordPress.
,
.
-------------------------------------------------------------------------,
/plugins. - , WordPress
, .
wp-content
69
w p -co n te n t /m u -p lu g in s .
(must-use plugins) ,
WordPress . ,
, .
, ,
. , http://
codex.wordpress.org/Must_Use_Plugins.
8 .
w p-content/them es.
-
, WordPress , .
in d e x .p h p s t y le . c s s ,
,
.
WordPress , .
. 9.
W ordPress w p - c o n t e n t/ u p lo a d s .
WordPress .
WordPress.
WordPress . ,
:
/wp-content/uploads/2012/06/image.png
-
WordPress, /w p-content.
WordPress
/u p lo a d s .
, /w p -c o n te n t , 755.
,
FTP WordPress.
u p lo a d s, (, NextGen Gallery,
),
.
WordPress Multisite .
M ultisite b l o g s . d i r .
, (ID).
70
2.
,
. Multisite .
10. ,
WordPress Multisite :
/blogs.dir/1/files/
Upgrade
w p -co n te n t/u p g ra d e WordPress
. WordPress
WordPress, WordPress.org.
WordPress .
, .
, WordPress
.
, ,
w p -co n te n t.
Super Cache (http://wordpress.org/extend/plugins/wp-super-cache/)
/w p -c o n te n t/c a c h e
.
, HTML.
, , HTML.
WordPress ,
,
.
Super Cache w p-content: advanced w p -c a c h e -c o n fig .p h p . Super
Cache. , .
,
. Super Cache
w p -co n te n t.
ca ch e .p h p
71
WordPress.
WordPress: w p -c o n fig .p h p .h ta c c e s s ,
. ,
w p -co n te n t WordPress
.
WordPress
,
, .
WordPress
:
, , WordPress ,
, WordPress - ,
. 1,
WordPress
-. WordPress.
(sandbox), ,
, ,
.
WordPress
. WordPress
.
.
-,
,
73
, . ,
.
? ,
WordPress, ,
.
.
,
, , .
,
,
. . ,
: , .
, ,
WordPress.
, .
, (
) .
.
, , .
, . ,
, Linux,
,
Microsoft Exchange, Windows.
: .
,
.
,
. ,
, , Windows, Mac OS X
Linux. ,
, .
WordPress
.
,
, . (
) , -
. ,
.
74
3. WordPress
?
, , , ,
,
.
,
.
-, ,
, . ,
.
, .
- -.
-, .
, , ,
. , .
-, ,
.
. , WordPress,
. ,
- , ,
. ,
- , , , ,
, , .
, ,
,
.
. ,
.
. ,
, .
.
FTP.
, ,
. ,
, ,
, , .
WordPress.
, ,
, , .
.
.
75
WordPress. ,
WordPress.
WordPress ,
. ,
WordPress,
WordPress, -
. WordPress,
.
.
: , .
,
: .
,
.
WordPress .
- MySQL.
.
, WordPress, .
WordPress -. , -. WordPress
, . , -
. ( )
Apache, ,
Microsoft IIS Nginx. WordPress 3.2
5.2.4. -, URL,
. Apache m od_rewrite.
WordPress .
WordPress MySQL, 3.2
MySQL 5.0 . ,
MySQL .
.
.
WordPress , , WordPress
. LAMP (Linux, Apache, MySQL
PHP). -,
76
3. WordPress
77
-, WordPress. WAMP
,
.
, .
.
WordPress
, , WordPress. , ,
,
. WordPress? ,
?
WordPress Multisite ?
.
WordPress.
WordPress,
Git Subversion, 2.
http://wordpress.org.
, WordPress,
-.
(Preferences) Apache.
,
. (Sites).
WAMP c:\wamp\www.
, www d ir e c t o r y
WAMPSERVER.
W ordPress
.
- http://localhost. ,
,
. , WordPress
,
URL , http://localhost/ddamstra/Documents/www.
- , WordPress
,
WordPress, . 3.1.
WordPress,
. WAMP, phpMyAdmin MySQL.
WAMP , phpMyAdmin
.
78
3. WordPress
, wp-config.php . .
? .
w p-config. php -, .
.
I j
. 3.1. WordPress
, 5- WordPress,
1.
,
,
. ,
, ,
,
WordPress .
, .
, .
,
.
LAMP.
.
, -,
.
-
Apache
.
.
,
Apache
: \www. .
, , . :
79
: \
Users\ddamstra\Documents\www,
Documents.
. ,
,
, .
. WAMP
Apache. h t t p d .
conf, WAMPSERVER
Apache.
(DocumentRoot),
, . 3.2.
file
d rt
T o o ls
S y n ta x
g o ff e rs
W in d o w
H elp
a a &&:&&&! t
165 * ServerNome gives the no me and port thot' the server uses to identify itself
16 n T h i s c o n often be determined automaticalty, but we recommend yo u specify
167 2 it explicitly to prevent problems during startup.
168
1 6 9 2 I f yo u r host doesn't have a registered DNS name, enter its IP address here
17%
171
172
173
174
175
176
177
178
179
180
181
S e rv e rN a m e l o c a l h o s t : 8
102 4
Each directory to which Apache has access can be configured with respect
1S3 # to which services and features are allowed and/or disabled in that
184 2 directory (and its subdirectories).
4$___
httpd.conf
a, a- 1
. 3.2. Apache
, ,
. 3.3.
WAMP
Apache ( ), .
,
, .
, ,
.
. ,
80
3. WordPress
j f ile
d it
X ools
S yntax
gutters
o 'Q fi!
Window Help
& S.
D en y fr o m a l l
/ D ir e c t o r y
' Note that from this point forward you m u st specifically allow
' particular features to be enabled - so if something's net working os
you might expect, make sure that you have specifically enobled i t
below.
"Options All"
2 3 4 ,4 6
. 3.3. Apache
...
I File
_c ,.f :
dit
Io o ls
ja S Q
Syntax
g u tters
W indow
Plugin
Help
,6
h t t p d .c o n f [
11;
I n c lu d e
D i r e c t o r y ~ " . * \ . s v n *>
O rd e r a llo w ,d e n y
Deny fro m a l l
S a t is f y A l l
I .j< / D ire c tc rry >
D ir e c t o r y -
s q l * *
O rd e r a llo w , deny
D eny fro m a l l
S a t is f y A l l
; < / D ir e c t o r y
i< D ir e c t o r y K a t c h A/ . * / \ _ n o t e s / " >
O rd e r d e n y , a l l o w
D eny fro m a l l
1 / D ir e c t o r y K a t c h
j< F i 1 e s M a tc h
ih tt p d .c o n f
96K
. ?
, Git Hub, ,
wp - conf ig . php
. , ,
81
, .
, Subversion,
,
.
,
Apache. Apache ,
. svn, , . 3.4,
httpd.conf.
. .
,
.
1, ,
. .
,
, , .
php. ini. WAMP,
WAMP,
. E_ALL E_STRICT,
. 3.5.
1
d it
T o o ls
a
Syntax
S u ffe rs
W in d o w
H99'
H e lp
&
&
340
- S h ow alt e r r o r s , except fo r notices and coding standards warnings
341
342 ;errarreparting * E^ALL 8, ~ENOTICE
34 3
3 44
S h ow alL e r r o r s , except for notices
345
346 ;errcrreporting = E_ALL & ~ENOTICE { E_STRICT
347
1
3 48
1 3 49
3 50
351
352
: 353
3 54
! 3 55
! 3 56
} 357
* 1
us
- Sh ew only errors
e r r o r , report ing = E _ C P I L E_ ERROR / E_ RECOVERABL EERROR / E_ ERROR / ECORE ERROR
Show alL errors,
ir-cr re p ort in g
E_A LL
! E _ S T R IC T
. 3 .5 .
82
3. WordPress
5.4
E_ALL.
, ,
,
.
: Apache,
.
,
,
API. , p h p $_SERVER[] Windows
Linux. Windows
, Linux.
, .
, .
WordPress.
, W ordPress
.
-.
WordPress, w p - c o n fig .p h p
WP_DEBUG true, . 3.6.
Apache ,
, WordPress.
w p -c o n fig .p h p
I F ile
d rt
T o o ls
( ~ \D o c u m e n ts \w w w \w o r d p f e s s )
S yntax
g u tte rs
W in d o w
"[si bm&sF
GVIM 1
H e lp
1 @I ^ as I &&&I &
&
1f | ?
d e f in e ( WPLANG', ' ) ;
]/**
|| * For develo pe rs: WordPress debugging mode.
|| * Change this to true to enable the display of notices during development.
|| * It is strongly recommended that plugin and theme developers use WP _DEBUG
IV
[ d e f i n e ( *WP D E B U G ' ,
||/ *
tru e ) ;
* '/ ) ;
* /.
. 3.6. WordPress
83
WordPress . ,
,
MySQL, . ,
.
localhost
MySQL ,
. .
,
:
http://marlgaquith.wordpress.com/2011/06/24/wordpress-local-dev-tips/. ,
wp-conf ig . php , ,
, .
w p-config-local.php
,
, .
WordPress
Apache. -,
.
. -
, .
.
.
, . com,. net,
.org . DNS,
DNS- 1-
- , .
DNS,
, .
hosts file.
Apache,
.
.
, ,
, DNS. , ,
84
3. WordPress
,
. , IP -
mirmillo.com, IP localhost, 127.0.0.1.
,
SQL .
m ir m illo . lo c a l,
( ). ,
m ir m illo . , DNS, -
, m ir m illo . l o c a l
. .
Apache .
Apache. WAMP
Apache.
h t t p d - v h o s t s .c o n f, C:\w am p \b in \
a p ach e\A pach e2 .2. ll\ c o n f \ e x t r a .
.
lo c a lh o s t . ,
, , m ir m illo .
lo c a l, . 3.7.
File
d it
T ools
Syntax
guffers
Vindow
H elp
v~ The first VirtuatHost section is used for all requests that do not
p d - v h o s t s .c o n f
27,1
. 3.7. mirmillo.local
Apache .
h t t p d . c o n f , . . 3.8,
, .
dit lo o t s Syntax
Buffers
W in d o w
85
Help
Language settings
wflnclude conf/extro/httpd-languages.conf
Ip
. 3.8. Apache
h o sts. Mac OS X : / p r iv a t e /
Linux : / e t c / h o s t s , Windows : C :\W in d ow s\S ystem 32\
- .
. 3.9, m i r m i ll o . lo c a l.
e tc /h o s ts,
d r iv e r s \ e t c .
file
fdit
T oots
Syntax
Window
B uffers
0 5100! *
jjeip
; ? ft
1# For example:
162.54.94.97
38.25.63.16
rhino.acme.com
x..com
4 source server
4 x client host
lo c a lh o s t
lo c a lh o s t
m ir m illo . lo c a l
Hhosts fRO ]
"h o s ts "
[ r e a d o n ly ]
2 5 1 , 835C
. 3 .9 . Hosts
86
3. WordPress
Apache http://mirmillo.local,
WordPress, 1.
,
. ,
, ,
, ,
. ,
WordPress, http://codex.wordpress.org/Theme_Unit_Test.
, .
W PCandy http://wpcandy.com/made/thesample-post-collection. WordPress
, , .
http://
1^^55._01_115
9 .
,
, ,
, .
WordPress Multisite. WordPress Multisite ,
, 10. ,
WordPress Multisite
WordPress WordPress. ,
WordPress .
.
.
WordPress,
.
, , WordPress Multisite,
, .
WordPress,
, , ,
.
WordPress,
, : -
, . ,
, . 8
.
,
WordPress ,
.
.
87
, . ,
, . ,
, , ;
. , ,
.
. .
WordPress , , -,
, .
, FTP-. , ,
SFTP,
FTP.
. WordPress
. (
HREF) .
, WordPress, .
.
,
,
. ,
. ,
,
.
-, WordPress http://codex.wordpress.org/Moving_WordPress
. .
, , ,
.
,
. ,
, , ,
, URL ,
, .
wp-DBManager, .
,
SQL-.
WordPress phpMyAdmin.
,
m irm illo. lo c al m irm illo. .
.
88
3. WordPress
, .
, - .
SQL , . 3.10,
URL . , URL
HTML.
.
WordPress . .
.
.....
(N o N am e)
tle
J o o ls
y s
a
'
drt
Syntax
g u ffe rs
Jfmdow
\ Y m
ife a
P lugin
fit &
Hjelp
j
db
&
(N o N a m e ] j
);
H H j P D A T E
w p _ _ p o s ts ' SET p o s t _ c o n t e n t = r e p l a c e ( p o s t _ e o n t e n t , ' s r c = " h t t p : / / m i r m i l l
l o c a l / * , * s r c * H/ ) ;
, jUPDATE %w p _ p o s t s '
j;; J k-mi 11 . / ) ;
!(* >
If - -
n ~ i
_______
IN S E R T
. 3.10. SQL
.
WordPress . :
, ,
.
,
. , ,
. , RAMP Crowd
Lavorite , http://crowdfavorite.com/wordpress/ramp/.
, . ,
, W ordPress ,
.
. , .
WordPress: ,
89
.
, , , ,
.
,
. , ,
WordPress . ,
.
WordPress .
:
WordPress
WordPress
, WordPress,
. , ,
WordPress, . WordPress
.
WordPress WordPress.
,
. ,
WordPress, ! ,
.
?
W ordPress ,
W ordPress.
, WordPress
. , ,
WordPress .
, ,
, . htaccess . . ,
91
WordPress. , WordPress
, .
WordPress ,
CSS, JavaScript, XML, HTML .
WordPress, ,
, ,
. ,
:
, . , ,
WordPress.
,
, 5 .
.
. 7.
. WordPress.
9.
, WordPress,
8.
. ,
12 14.
, .
.
WordPress.
, ,
WordPress. WordPress
.
.
WordPress:
WordPress,
, .
WordPress : Akismet Hello Dolly.
wp-content.
WordPress,
,
.
WordPress : Twenty Ten, Twenty Eleven
Twenty Twelve. Twenty Twelve no WordPress. ,
, ,
.
92
4.
W ordPress , ,
. W ordPress
.
,
.
, wp-login. php,
WordPress. ,
, :
/**
* WordPress User Page
* , , .
*
*
* ^package WordPress
*/
, ,
.
,
. ,
, ,
.
WordPress.org
http://codex.wordpress.Org/Glossary#Text_editor.
WordPress
PHPDoc. PHPDoc
. ,
.
WordPress:
/**
*
* ^package WordPress
* @since version
* (Sparam
* @return
*/
type
type
{varname
93
.
. WordPress,
. ,
WordPress .
.
, . ,
ID , , in t ().
.
.
, W ordPress,
.
WordPress : http://codex.wordpress.org/
Inline_Documentation.
,
WordPress. ,
, .
,
WordPress. WordPress.
, (
TextPad Windows Textmate ).
. ,
, function wp_head. WordPress
, .
, function .
(*. *), . txt.
is_super_admin( ). ,
WordPress Multisite.
, , .
W ordPress function
is_supen_admin. wp-includes/capabilities. php:
function is_super_admin( $user_id = false ) {
, :
$user_id. ,
. is_super_admin()
:
/**
* , .
* @since 3.0.0
94
4.
*
* @param int $user_id (Optional) ID . -
.
* (Sreturn bool True, .
*/
.
, . : ,
. ,
( 3.0.0). ,
, , .
, .
True,
, F a ls e , .
, , ,
.
:
if ( $user_id )
{user = new WP_User( {user_id );
else
{user = wp_get_current_user();
PHPDoc, , ,
{ u s e r_ id , ,
, { u s e r _ id .
i f , $ u s e r_ id .
,
WordPress, WP_User ID. $ u s e r_ id ,
w p _ g e t_ cu rre n t_ u se r ( ),
, .
, , , {user
, , false.
if ( ! {user->exists() )
return false;
, , {user ,
, :
if ( is_multisite() ) {
{super_admins = get_super_admins();
if ( is_array( {super_admins ) && in_array( {user->user_login,
{super_admins ) )
return true;
) else {
if ( $user->has_cap(delete_users') )
return true;
>
95
i f :
if ( is_multisite() ) {
i f , Multisite WordPress,
is _ m u ltisite ( ).
Multisite WordPress.
WordPress , Multisite , get_super_
admins ( ), WordPress,
:
$super_admins = get_super_admins();
$super_admins
. .
, ,
WordPress:
$super_admins = get_super_admins();
if ( is_array( $super_admins ) && in_array( $user->user_login, $super_admins ) )
return true;
, ,
, is_array( ).
in_array( ), ,
. ,
,
true.
is_m ultisite( ) false,
eise:
} eise {
if ( $user->has_cap('delete_users ') )
return true;
}
, delete_
users ( ).
WordPress. Multisite
WordPress, ,
true is_super_admin( ).
:
return false;
, , , is_super_admin( )
, false. ,
, true fa lse .
96
4.
, ,
WordPress. ,
, .
, ,
.
WordPress ,
WordPress. API WordPress
.
,
WordPress. , ,
/wp-includes.
Functions, php
functions. php API WordPress.
WordPress .
, WordPress :
current_time .
force_ssl_login SSL (https) WordPress.
wp_nonce_f ield .
WordPress.
.
absint .
Option.php
option. php API WordPress.
:
add_option, update_option, get_option ,
.
set_transient, get_transient, delete_transient ,
WordPress.
.
WordPress.
add_site_option, update_site_option, get_site_option ,
. Multisite,
,
.
97
Formatting.php
formatting. php WordPress.
:
esc_atti HTML.
esc_html HTML.
esc_url URL.
san itize_text_f ield ,
.
is_email , .
c a p ita l_ P _ d a n g it , WordPress
.
Pluggable.php
WordPress. WordPress ,
. :
wpjnail WordPress.
get_userdata
ID .
get_currentuserinfo
, .
wp_set_pas sword .
wp_rand .
w p_ logou t , .
w p _ re d ir e c t .
get_avatai .
Plugin.php
p l u g in . php API WordPress, :
add_f i l t e r W ordPress ,
.
a d d _ a c tio n WordPress
.
r e g is t e r _ a c t iv a t io n _ h o o k , .
98
4.
register_deactivation_hook , .
plugin_dir_url
.
plugin_dir_path URL .
User.php
user. php API WordPress, :
get_users ,
.
add_user_meta, get_user_meta, delete_user_meta ,
.
username_exists , .
em ail_exists , .
wp_insert_user wp_update_user
.
Post.php
post. php , WordPress,
:
wp_insert_post .
get jDosts , .
add_post_meta ( ) .
get_post_meta ( )
.
get_post_custom
( ) .
set_post_thumbnail .
register_post_type WordPress.
add_f ilt e r ( ) add_hook( )
, WordPress ,
, WordPress.
7.
Taxonomy.php
taxonomy. php , API WordPress.
99
, (. 6)
, 7. :
register_taxonomy WordPress.
get_taxonomies .
wp_insert_term, wp_update_term
.
,
WordPress.
/wp-includes.
API WordPress.
,
. ,
, , .
API 8. ,
, 9.
WordPress
. , WordPress,
.
.
. ,
, ,
WordPress.
WordPress ,
. . ,
WordPress
, ,
WordPress,
.
get_current_
theme():
/**
* .
*
*
*
*
*
@since 1.5.0
^deprecated 3.4.0
^deprecated Use (string) wp_get_theme()
@see wp_get_theme()
* @return string
*/
100
4.
. , , WordPress
: @deprecated, 3.4.
@see , ,
wp_get_theme( ).
d ep recated . php
WordPress. ,
.
WordPress,
, .
WordPress
-,
WordPress .
.
?
WordPress - WordPress,
WordPress.org. WordPress.org
WordPress. , http://codex.wordpress.org
Docs WordPress.org.
-, , ,
.
WordPress. WordPress
, WordPress.
. ,
Multilingual Codex http://codex.wordpress.org/Multilingual_Codex.
, .
.
.
http://wordpress.org/search/, ,
.
WordPress.org Google Custom Search (
Google), . 4.1.
WordPress
101
WordPress.org, , .
http://codex.wordpress.Org/Special:Search.
Search
comments
. 4.1. WordPress.org
.
.
WordPress.
, ,
, .
.
, .
http://codex.wordpress.org/Glossary.
.
. http://codex.
w0rdpress.0rg/C0dex:Quick_index.
WordPress Lessons ( WordPress) http://codex.
wordpress.org/WordPress_Lessons.
WordPress. . ,
, .
102
4.
WordPress
API WordPress. ,
WordPress (. 4.2).
WordPress .
http://
codex, word press. org/Function_Reference.
Codex
Function Reference/get userdata
LsnguQs: English
(Add your }
Description
Contents
Returns a W P J J s e r object with the information pertaining to the user whose 10 is passed to it.
tuaei
Properties map directly to wp_users and w pjrserm eta tables in the database (see Database
a 1 Description
Description).
2 Use;
3 Param eters
4 Return Values
e S Exemples
An alias of get_user_byOcf).
e 5.1 D e ts u t Usage
Usage
6 Notes
e 7 Source Ffe
O p h p g et_userdata( S u s trid ) ;
8 See Also
9 Related
. 4.2. get_userdata
-
.
.
.
.
, . get_userdata:
<?php $usen_info = get_userdata(l);
echo 'Username: ' . $user_info->user_login . \n";
echo 'User level: ' . $user_info->user_level . "\n";
echo 'User ID: ' . $user_info->ID . "\n";
?>
,
ID 1. :
Username: michael_myers
User Level: 10
User ID: 1
WordPress
103
,
, .
.
,
, . , wp_insert_post ( )
wp_update_post ( ) wp_delete_post ( ).
API WordPress ,
. ,
,
. ,
, - .
------------------------------------------------------------------------- WordPress.
, ,
WordPress.
API WordPress
WordPress API (
), WordPress. ,
API ,
WordPress .
API ,
wp-content WordPress.
API , API. API
,
. API
WordPress:
Plugin API. .
Plugin API.
( ), ,
WordPress
. Plugin API
API,
/w p-includes/plugins.php.
http://codex.wordpress.org/Plugin_API
W idgets API.
.
.
http://codex.wordpress.org/Widgets_API
104
4.
Shortcode API. .
, ,
,
.
.
WordPress [g a llery ].
[gallery] ,
, .
[gallery],
.
http://codex.wordpress.org/Shortcode_API
Options API.
WordPress. API , ,
.
http://codex.wordpress.org/Options_API
105
Rewrite API.
. API ,
.htaccess.
( %postname%),
( /-page/)
. Rewrite /wp-includes/rewrite.php
http://codex.wordpress.org/Rewrite_API.
He , API W ordPress
. W ordPress
.
API
WordPress.
API WordPress
http://codex.wordpress.org/WordPress_APrs.
,
. , , . WordPress
, , .
, ,
. WordPress ,
.
.
,
. ,
, WordPress ,
, , .
!
WordPress
, .
- WordPress.
, ,
.
106
4.
?
WordPress
WordPress. WordPress
-.
.
, ,
, .
,
W ordPress
. ,
,
.
, .
W ordPress
. ,
. ,
,
WordPress.
, , ,
. ,
. , ,
. ,
, ,
- .
,
WordPress. ,
, , ,
, .
, WordPress,
.
, . (
, , .)
WordPress , ,
. !
WordPress ,
WordPress,
.
107
WordPress.
, ,
WordPress ,
. WordPress
WordPress API.
, , WordPress, ,
WordPress .
(Loop)
:
, WordPress (,
) .
,
,
.
WordPress ?
MySQL .
URL, WordPress. ,
. , ,
URL http://example.com/category/zombies,
, ( ).
,
. W ordPress
,
109
.
, , URL ,
.
, ,
.
, WordPress. ,
, .
, , .
, ,
WordPress. WordPress,
, WordPress
, .
, , WordPress ,
:
1. URL , WordPress.
, -. WordPress, ,
. URL -
WordPress, -
WordPress . h ta c c e s s . 2
.
2. URL WordPress, ,
, . -
WordPress in d e x , php, .
- , http://example.com/tag/bacon, WordPress
, , ,
, ,
.
3. URL
p a rse _ q u e ry ( ) WP_Query, WordPress
. WordPress URL ,
. URL
,
.
,
. , http://example.com/tag/bacon , http://example.
com?tag=bacon, bacon.
110
5. (Loop)
4. WordPress
MySQL, .
g e t _ p o s t s ( ) WP_Query,
. g e t_ p o s ts ( )
SQL, SQL
MySQL . , ,
WP_Query, W ordPress,
.
5. WordPress i s _ ,
is_hom e( ) is _ p a g e ( ).
URL, ,
.
6. W ordPress ,
, ,
,
.
. ,
.
-
.
, .
,
.
SQL
URL,
, ,
g e t _ p o s t s ( ) WP_Query SQL
. ,
, WordPress
, SQL
.
SQL: SELECT fieLds FROM tabie WHERE conditions (
). ,
. . ,
WHERE, ,
. SQL,
re q u e s t WP_Query, , WHERE SQL 1=1
. , 1=1 ,
SQL
111
112
5. (Loop)
WordPress
Loop, ,
WordPress. WordPress :
. 6 ,
MySQL . WordPress 2.9
,
WordPress. ,
, WordPress.
, ,
WordPress .
7.
, .
MySQL HTML,
. , , WordPress
. ,
.
WordPress , .
. 5.1 , ,
.
.
WordPress.
, . 5.2.
.
WordPress,
,
.
.
, ,
. , , .
, , ,
.
URL,
WordPress,
.
W o r d P r e s s
. 5.1. WordPress
"
. 5.2.
113
114
5. (Loop)
WordPress,
. ,
.
Loop
, , . Loop
i f , , ,
.
, w h ile ,
, . , th e _ p o s t ( )
,
WordPress.
, .
. ,
:
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
/ / ( , html .)
endwhile;
endif;
?>
, , <?php ?>.
. ,
Loop,
, $wp_query,
WP_Query,
. , . ,
WordPress g e t_ p o s t s ( )
,
URL,
. , ,
,
,
$wp_query.
WordPress.
, :
if ( have_posts() ) :
115
,
- . ,
:
while ( have_posts() ) :
w h ile ,
, ,
. ,
. , .
h a v e _ p o s t s ( ) ,
.
the_post();
th e_ p o st () . *
,
. th e _ p o s t () s e tu p _ p o s td a ta ( ),
, ,
, .
.
th e _ p o s t () $ p ost,
,
.
, WordPress. WordPress
,
. , , ,
Google AdSense ,
. , ,
JavaScript
, .
8,
WordPress
, .
/ /
,
.
.
endwhile;
endif;
e n d w h ile e n d if . ,
, .
e is e ,
Loop .
116
5. (Loop)
HTML.
, Twenty Eleven,
WordPress:
<div id="primary">
<div id="content" role="main">
<?php if ( have_posts() ) : ?>
<?php twentyeleven_content_nav( nav-above' ); ?>
<?php /* */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>
<?php else : ?>
article id="post-0" class="post no-results not-found">
header class="entry-header">
<hl class="entry-title">
<?php _e( 'Nothing Found', 'twentyeleven' ); ?>
</hl>
/header!-- .entry-header -->
div class="entry-content">
<P>
<?php _e( 'Apologies, but no results were found
for the requested archive. Perhaps searching will
help find a related post.', 'twentyeleven' ); ?>
</p>
<?php get_search_form(); ?>
</div><!-- .entry-content -->
/article!-- #post-0 -->
<?php endif; ?>
</div><!-- #content -->
</div><!-- #primary -->
, , HTM L
. HTML, , ,
.
, , .
, WordPress
, (template tags).
.
.
, t h e _ title ()
Loop. ,
.
WordPress .
,
117
. ,
WordPress,
. , ,
. ,
, .
http://codex.wordpress.org/Template_Tags.
,
. , .
.
the_permalink() URL .
th e _ title () .
th e _ ID () ID .
the_content () .
th e_excerp t() . ,
(Excerpt) . ,
WordPress .
the_tim e() / .
the_author() .
the_tags() .
the_category() .
edit_post_link() edit, ,
. .
comments_popup_link() .
, ,
Loop , . ,
:
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<br />
<?php
the_content();
endwhile;
endif;
?>
118
5. (Loop)
,
. .
,
. , th e _ c o n te n t( )
. more :
<?php the_content( 'Read more', false ); ?>
,
<! --m o re --> WordPress Read more,
. ,
- .
f a ls e , .
------------------------------------------------------------------------- more WordPress
. , ,
,
. , <! --m o re --> HTML
, . More
.
,
. , t h e _ t i t l e ( ) :
{ b e fo re , { a f t e r {echo. t h e _ t i t l e ( ) { b e fo re
{ a f t e r h l:
<?php the_title( '<hl>'j '</hl>' ); ?>
WordPress.
w p - in c lu d e s / p o s t- te m p la te .p h p .
f u n c t io n t h e _ t i t le ( ) ,
t h e _ t i t le ( ) .
, . : http://codex.
wordpress.11_5_.
,
g e t_ p o s ts () WP_Query.
, ,
WP_Query .
q u e r y _ p o s t s ( ) g e t _ p o s t s ( )
119
( WP_Query ),
, .
q u e r y _ p o s t s ( ), g e t _ p o s t s ( ) WP_Query,
. ,
,
.
WP_Query
WordPress URL -,
URL .
,
WP_Query.
, WordPress,
. q u e ry _ p o s ts (), g e t _ p o s t s ( ) WP_Query
WordPress. q u e r y _ p o s ts ( ),
$wp_query WP_Query, $wp_query
.
. WP_Query.
WP_Query
WP_Query,
,
URL.
, ,
.
,
:
<?php
{myPosts = new WP_Query( 'posts_per_page=5' );while ( $myPosts->have_posts() )
: $myPosts->the_post();
?>
<!-- , -->
<?php endwhile; ?>
h a v e _ p o s ts () t h e _ p o s t ( ),
,
W P Q u e ry {m yPosts. , ,
h a v e _ p o s ts () ; h a v e _ p o s ts ( ),
, $ w p _ q u ery -> h av e _ p o sts( )
, ,
URL, WordPress -.
URL WordPress.
, , URL
120
5. (Loop)
p a rs e _ q u e ry () .
,
. ,
:
$ m yP o sts-> q u e ry() SQL-
$ m y P o s ts -> g e t_ p o s ts ( ),
MySQL .
, ,
is _ h o m e () i s _ s i n g l e ( ),
.
, , WordPress,
.
,
.
,
, , .
, , ,
. ,
,
.
.
http://codex.wordpress.
org/Class_Reference/WP_Query#Parameters.
:
=2 ID.
nam e=m y-slug (slug) (
).
p o s t_ s ta tu s = p e n d in g . ,
, p o s t_ s ta tu s = d ra f t.
121
ignore_sticky_posts
. (sticky post) ,
, ,
. ,
,
.
.
post_type=page .
, , : post_type=page.
, 7.
p o s ts _ p e r_ p a g e = 5 .
. , -1.
o ff set= l , .
:
page_id=5 ID. ID
, ID ,
URL, .
p a g e n a m e = C o n ta ct ,
Contact.
pagename=parent/child
( ).
,
,
, :
cat=3,4, 5 ID .
category_nam e=About Us .
, ,
.
tag=w riting .
tag_id=34 ID .
author=l ID .
author_name=brad .
122
5. (Loop)
, ,
. .
- ,
,
.
monthnum=6 , .
day=9 , 9- .
=2012 , 2012 .
o rd e rb y ^ title ...
order=ASC ord e rb y .
meta_key=color .
7, ,
.
meta_value=blue .
meta_key.
.
{ m y P o s ts - q u e ry ()
$m yPosts , ,
.
ID :
{myPosts = new WP_Query( '=1' );
, :
$myPosts.= new WP_Query( 'posts_per_page=5&offset=l* );
:
{today = getdate(); //
{myPosts = new WP_Query('year= .{today["year"]
.&monthnum=' .{today["mon"] .'&day=' .{today["mday"] );
31 2013 :
{myPosts = new WP_Query( 'monthnum=10&day=31&year=2013' );
ID 5 bacon:
{myPosts = new WP_Query( 'cat=5&tag=bacon' );
123
bacon, ID 5:
{myPosts = new WP_Query( 'cat=-5&tag=bacon' );
w r it in g re a d in g :
{myPosts = new WP_Query( 'tag=writing,reading' );
w r it in g , re a d in g t v :
{myPosts = new WP_Query( 'tag=writing+reading+tv' );
c o l o r () b lu e
():
{myPosts = new WP_Query( 'meta_key=color&meta_value=blue' );
,
, ( ),
.
$wp_query. ,
, .
WordPress ,
-$w p_query, .
<?php
$temp = $wp_query;
$wp_query= null;
{paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
{wp_query = new WP_Query( 'posts_per_page=5&paged='.{paged );
while ( {wp_query->have_posts() ) : {wp_query->the_post();
?>
<h2>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</h2>
<?php the_excerpt(); ?>
<?php endwhile; ?>
{wp_query
{temp. {wp_query ,
. ,
WordPress .
WP_Query {wp_query , query ()
.
{paged, . ,
g e t_ q u e ry _ v a r(), WordPress ,
. :
<div class="navigation">
<div class="alignleft"x?php previous_posts_link( « Previous' ); ?></div>
124
5. (Loop)
, $wp_query :
<?php
$wp_query = null;
$wp_query = $temp;
?>
.
query_posts( )
,
. WP_Query
WordPress,
, .
q u e ry_ p o sts( ) ,
. , ,
$wp_query ,
, q u e ry _ p o s ts ( ).
q u e r y _ p o s ts ( )
, , .
q u e r y _ p o s t s ( )
:
query_posts( 'posts_per_page=5&paged='.{paged );
if ( have_posts() ) :
while ( have_posts() ) : the_post();
/J ( , html .)
endwhile;
endif;
WordPress .
q u e r y _ p o s t s ( )
, . , ,
, q u e r y _ p o s t s ( ) .
, WordPress URL
http://example.com/category/zombie/,
q u e ry _ p o s ts ( ),
. ,
URL ,
q u e ry _ p o s ts ().
,
, { q u e ry _ s tr in g :
125
// query_string
global $query_string;
//
query_posts( $query_string . "&orderby=title&order=ASC" );
-
, .
.
q u e r y _ p o s t s ( ) ,
. ,
W ordPress, $ a rg s
:
Jangs = array(
'posts_per_page' => 1 ,
'post in' => get_option( 'sticky_posts' )
);
query_posts( $args );
,
. q u e ry _ p o s ts ( )
.
.
,
, q u e r y _ p o s t s ( )
.
:
q u e r y _ p o s t s ( ) $w p_query
.
. q u e ry _ p o s ts ()
,
, .
q u e r y _ p o s t s ( )
.
q u e ry _ p o s ts ( ) $wp_query,
, i s _
page() is_ ho m e (). WP_Query
. , ,
, , , , is _ s in g le ( )
.
q u e r y _ p o s t s ( ) ,
126
5. (Loop)
.
MySQL. ,
,
,
.
get_posts( )
q u e r y _ p o s t s ( )
.
,
, ,
.
,
, WP_Query.
g e t _ p o s t s ( ),
g e t _ p o s t s ( ),
g e t_ p o s ts (),
, ,
. ,
g e t _ p o s t s ( ) . ,
s e tu p _ p o s td a ta () ,
. ,
, g e t_ p o s ts ( ) :
<?php
{randompost = get_posts( numberposts=l&orderby=rand' );
foreach( {randompost as {post ) :
setup_postdata( {post );
?>
<hlxa href="<?php the_permalink(); ?>"x?php the_title(); ?x/ax/hl>
<?php the_content(); ?>
<?php endforeach; ?>
g e t_ p o s ts ( ) :
. foreach
. ,
, .
s e tu p _ p o s td a ta () .
, g e t_ p o s ts ( ), :
<?php
{args = array(
'numberposts' => 1,
'orderby' => rand
);
127
,
q u e r y _ p o s t s ( ), WP_Query
.
, g e t _ p o s t s ( ) ,
.
g e t_ p o s ts ()
, . WordPress
: w p _ re s e t_ p o s td a ta ()
wp_reset_query().
w p _ re se t_ p o std a ta ( ) . , ,
{ p o s t
. WP_Query
.
, ,
header.php:
<?php
{myPosts = new WP_Query( 'posts_per_page=l&orderby=rand' );
//
while ( {myPosts->have_posts() ) : {myPosts->the_post();
?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></axbr /xPphp
endwhile;
?>
.
.
,
.
, wp_reset_postdata ()
:
{myPosts = new WP_Query( 'posts_per_page=l&orderby=rand' );
//
while ( {myPosts->have_posts() ) : {myPosts->the_post();
? x a href="<?php the_permalink(); ?>"x?php the_title(); ? x / a x b r /xPphp
endwhile;
// {postwp_reset_postdata();
{post
. ,
.
wp_reset_query ().
128
5. (Loop)
.
WordPress,
is_ h o m e ( ) ,
. query_posts( ),
.
, wp_reset_queny ( ).
, ,
URL.
:
<?php query_posts( posts_per_page=5 ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></axbr />
<?php endwhile; endif; ?>
<?php
if( is_home() && !is_paged() ):
wp_list_bookmarks( 'title_li=&categorize=0' );
endif;
?>
,
WordPress. ,
, , is_hom e( )
. , ,
. , w p _ re set_
q u e r y () Loop:
<?php query_posts( 'posts_per_page=5' ); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></axbr />
<?php endwhile; endif; ?>
<?php wp_reset_queny(); ?>
<?php
if( is_home() && !is_paged() ):
wp_list_bookmarks( 'title_li=&categorize=0 );
endif;
?>
,
WP_Query, is_hom e( )
.
w p_reset_query ( ) q u e ry _ p o sts( ) ,
. w p _ re se t_ q u e ry ( )
w p_reset_postdata ( ) , .
, . , w p_reset_query ( )
, q u e ry _ p o s ts ( ) ,
a w p _ re se t_ p o std a ta ( ) ,
WP_Query g e t_ p o s ts ( ) .
129
.
WordPress. ,
. , ,
,
.
WP_Query. ,
.
:
<?php
if ( have_posts() ) :
while ( have_posts() ) :
the_post();
// ( , html .)
?>
chlxa href="<?php the_permalink(); ?>"x?php the_title(); ?x/ax/hl>
<?php
the_content();
{tags = wp_get_post_terms( get_the_ID() );
if ( {tags ) {
echo 'Related Posts';
{tagcount = count( {tags );
for ( $i = 0; {i < {tagcount; {i++ ) {
{tagIDs[{i] = $tags[{i]->term_id;
>
$args=array(
tag in' => {taglDs,
'post not_in' => array( $post->ID ),
'posts_per_page' => 5,
'ignore_sticky_posts' => 1
);
{relatedPosts = new WP_Query( {args );
if( {relatedPosts->have_posts() ) {
//
while ( {relatedPosts->have_posts() ) :
{relatedPosts->the_post(); ?>
<p xa href="<?php the_permalink(); ?>">
<?php the_title(); ? x / a x/ p>
<?php
endwhile;
>
>
endwhile;
endif;
130
5. (Loop)
.
, , , .
, ,
. ,
.
rew in d_po st s () ,
,
.
. :
<?php while ( have_posts() ) : the_post(); ?>
<!-- content. -->
<?php endwhile; ?>
<?php rewind_posts(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<!-- content -->
<?php endwhile; ?>
.
,
meta_compare:
$args = array(
'posts_per_page' => '-1',
'post_type' => 'product',
'meta_key' => 'price',
'meta_value' => '13',
'meta_compare' => <='
);
, m e ta _ c o m p a re
(<=) 13. m eta_
com pare : !=, >, >=, <, <=,
=.
m e ta_ q u ery.
.
13
:
131
$args = array(
post_type' => 'product',
meta_query' => array(
array(
'key' => 'color',
'value' => 'blue',
'compare' => '='
),
array(
'key' => 'price',
'value' => '13',
'type' => 'numeric',
'compare' => '<='
)
)
);
, m eta_query .
, ,
. , , 13.
.
.
,
WordPress.
,
WordPress,
MySQL.
, , .
WordPress,
,
,
.
,
, .
,
, ,
.
132
5. (Loop)
, the_post ().
, WordPress,
. {post.
{post , .
, {post
.
,
{post ,
print_r().
<?php
global {post;
print_r( {post );
// , {post
?>
{post.
WordPress :
stdClass Object
[ID] => 1
[post_author] => 1
[post_date] => 2012-06-09 19:05:19
[post_date_gmt] => 2012-06-09 17:23:50
[post_content] => Welcome to WordPress. This is your first post.
Edit or delete it, then start blogging!
[postjtitle] => Hello world!
[post_excerpt] =>
[post_status] => publish
[comment_status] => open
[ping_status] => open
[post_password] =>
[post_name] => hello-world
[to_ping] =>
[pinged] =>
[postjnodified] => 2012-06-09 19:04:12
[post_modified_gmt] => 2012-06-09 19:04:12
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://localhost/Brad/?p=l
[menu_order] = > 0
[post_type] => post
[post_mime_type] =>
[comment_count] => 1
[ancestors] => Array
(
)
133
, $post
. ,
:
<?php
global $post;
echo $post->post_title;
echo $post->post_content;
//
//
?>
$post ,
. ,
, . ,
[g allery ]
, , [gallery]
.
, WordPress ,
,
. ,
,
:
<?php
global $post;
echo get_permalink( $post->ID );
//
?>
.
{authordata ,
.
:
<?php
global {authordata;
echo 'Author: .$authordata->display_name;
?>
{authordata , setu p _ p o std ata()
th e_ p o st() Loop. ,
$authordata Loop.
, .
: , ,
.
134
5. (Loop)
,
' ,
WordPress. , :
<?php
echo 'Author: ' .get_the_author_meta( 'display_name );
?>
g e t_ th e _ a u th o r_ m e ta ( ) th e _ a u th o r_ m e ta ()
, .
, ID , ID
, .
>
$ c u rr e n t_ u s e r ,
. ,
WordPress. ,
:
<?php
global $current_user;
echo $current_user->display_name;
?>
,
. ,
.
, :
<?php
global $current_user;
if ( $current_user->display_name ) {
echo 'Welcome ' .$current_user->display_name;
>
?>
WordPress ,
. ,
WordPress, :
<?php
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4,
$is_safari, $is_chrome, $is_iphone;
if ( $is_lynx ) {
echo "You are using Lynx";
Jelseif ( $is_gecko ) {
echo "You are using Firefox";
135
}elseif ( $is_IE ) {
echo "You are using Internet Explorer";
Jelseif ( $is_opera ) {
echo "You are using Opera";
}elseif ( $is_NS4 ) {
echo "You are using Netscape";
}elseif ( $is_safari ) {
echo "You are using Safari";
}elseif ( $is_chrome ) {
echo "You are using Chrome";
}elseif ( $is_iphone ) {
echo "You are using an iPhone";
}
?>
,
. ,
-
, .
, $ is _ ip h o n e
iPhone.
W ordP ress
, ,
. $ is _ m o b ile .
,
w p _ is _ m o b ile (). ,
. , tru e ;
f a ls e :
if { wp_is_mobile() ) {
echo "You are viewing this website on a mobile device";
}else{
echo "You are not on a mobile device";
}
WordPress , - ,
$ is _ I I S $ is_ a p a ch e . :
<?php
global $is_apache, $is_IIS;
if ( $is_apache ) {
echo "web server is running Apache";
Jelseif ( $is_IIS ) {
echo "web server is running IIS";
>
?>
, - ,
. ,
WordPress
. ,
.
136
5. (Loop)
?
.
, .
.
, ,
,
.
, ,
:
<?php apply_filters( 'the_content', $post->post_content );?>
,
,
,
.
Loop. WordPress
.
WordPress
,
. ,
Loop:
wp_list_pages() ;
wp_list_categories( ) ;
wp_list_bookmarks() ,
(Links);
wp_tag_cloud( ) ;
get_permalink( ) ;
next_posts_link( ) ;
previous_posts_link() .
, , next_posts_
lin k () previous_posts_link() .
, , .
137
WordPress,
wp_list_pages ( ) . ,
<ul>:
<ul>
< ?php w p _ lis t _ p a g e s (
< /ul>
t it le _ li= '
);
?>
W ordPress .
: t i t l e _ l i ,
.
:
<ul>
< l i c la s s = " p a g e _ it e m p a g e - it e m - l" >
<a h n e f= " h t t p : / / e x a m p le . c o m / a b o u t/ " t it le = " A b o u t " > A b o u t < / a >
< / li>
< l i c la s s = " p a g e _ it e m p a g e - it e m - 2 " >
<a h r e f = " h t t p : / / e x a m p le . c o m / o r d e r / " t it le = " O r d e r " > O r d e r < / a >
< / li>
< l i c la s s = " p a g e _ it e m p a g e - it e m - 3 " >
<a h n e f= " h t t p : / / e x a m p le . c o m / c o n t a c t / " t it le = " C o n t a c t " > C o n t a c t < / a >
< / li>
< /u l>
,
wp_page_menu(). .
show_home,
( ) .
t i t l e _ l i , .
<div>,
:
<?php w p_page_m enu(
?>
w p_list_
c a te g o r ie s (). .
:
<ul>
<?php w p _ li s t _ c a t e g o r ie s (
< /u l>
);
?>
. ,
, .
4. ,
. .
(8,16 34) IDs.
next_posts_link() previous_posts_link()
.
.
13 8
5. (Loop)
, next_posts_link( )
. , WordPress
,
, .
, Loop.
, get_post () .
ID 1031:
<?php
$my_id = 1031;
$myPost = get_post( $my_id );
echo 'Post Title: ' .$myPost->post_title .<br />';
echo 'Post Content: ' .$myPost->post_content .'<br />';
?>
get_post() : ID ,
. , ID.
(, 5) .
, :
, .
. :
<?php
$my_id = 1031;
$myPost = get_post( $my_id, ARRAY_A );
echo 'Post Title: ' .$myPost['post_title'] .'<br />';
echo 'Post Content: ' .$myPost['post_content'] .'<br />';
?>
, , get_post()
WordPress. ,
, .
setup_postdata() get_post()
:
< ?php
$my_id = 1031;
$myPost=get_post( $my_id );
setup_postdata( $myPost );
the_title();
the_content();
?>
get_post( ) WordPress. ,
,
. ,
.
, ,
. , the_author_meta ()
:
The email address for user id 1 is <?php the_author_meta( 'user_email', 1 ); ?>
139
, , th e_ au th or_ m eta ( ) ,
ID , .
, ID,
.
W ordPress
. , g e t_ th e _
t i t l e ( ), ID:
<?php
echo 'Title: ' .get_the_title( 1031 );
?>
(
) . ,
g e t_ p o st_ m e ta ():
<?php
echo 'Color: .get_post_meta( 1031, 'color', true );
WordPress
WordPress,
. WordPress
. WordPress
6, , ,
, .
7 ,
, ,
WordPress.
8.
WordPress .
9.
:
WordPress
WordPress
,
. WordPress ,
MySQL. ,
, , , , .
, WordPress,
.
WordPress 11 . WordPress
, .
,
WordPress. ,
.
6.1 WordPress,
. ,
. WordPress Multisite
, WordPress ,
.
w p.eo m m en ts
3 wp_us*fa
t BGINT(20)
- commentJ O BKNT(20)
I ID BIGINT(20)
po*Lvtffo< B1QNT(20)
G comment_po*J O BK3INT(20)
>po*LJ DATETIME
G oomnwnljauthor TINYTEXT
G comment_author_omal VARCHAR(100)
j po*Ldate_smt DATETIME
Goommentjtutttorjjr t VARCMAR(200)
po*t__contefTt LONGTEXT
G user_pass VARCHAR(M)
G use_ntename VARCHAR(SO)
G uter.om al VARCHAR(tOO)
./ comm*nt_authorJP VARCHAR(WO)
poaL_tlO* TEXT
comment_dats 0
G pot_excerpt TEXT
:>oomnnt_dto_gmt OA TIME
G pot_*Utua VARCHAR(20)
>oomment^contenl TEXT
oomment_status VARCHAR(20)
G user.urt VARCHAR(IOO)
v user, tsgitto fed DATETIME
G oommentJtarma (NT(11)
plng_status VARCHAR(20)
G oomnwnt_sppiovcd VARCHAR(20)
poetjsa#ord VARCHAR(20)
>comment_eont VARCHAR(255)
G postjuune VARCHAR(200)
G commentJype VARCHAR(20)
141
G user_acttuatton_key VARCHAR(60)
Guser_statuslN T(l1)
G dtoplayjtamo VARCHAR(250)
G comment_pai*nt B)GINT(20)
<>to_ping TEXT
pinged TEXT
uaf_U B1GINT(20)
G post_modiflsd QATETIME
I
3 wp_comment*mta
r
mota_ BlGINT(20)
3 Wpjm rm tta
>postjxtntentjilered TEXT
f umettJ d BK3INT(20)
post_param BIGINT(20)
G
G user.Id BIGINT(20)
VARCHAfl(255)
G meu.key VARCHAR(255)
G meta.value LONGTEXT
v m iu _ d a flN T (i1 )
v poal_typa VARCHAR(20)
post_mlme_type VARCHAR(WO)
oommontjd BK3INT(20)
G ma_key VARCHAR(2S5)
comment.count BIGINT(20)
3 wpjNMm_fe*tlooaWpe
3 wpjxMtmeta
t o|eca_id B*GINT(20)
f term,taxonomyJ S BK3tNT(20)
t mata_ldBIGINT(20)
Gterm_orderlNT(l1)
G post, BIGNT(20)
! optionJd BlGINTi'20)
G mata_toy VARCHAR(2S5)
Jb to g jd INT(11)
0 meta_value LONGTEXT
w p je rm jM o n o m y
tr
term_taxonomy_id 1(20) |
Gterm xj BIGINT(20)
G taxonomy VAHCHAR(32)
V 0 description LONGTEXT
G parent BIGINT(20)
G count BIGINT(20)
rnirT
3 p jw m
term jd BK3INTI20)
1_ BIGINT(20)
G lnk_Ufl VARCHAR(2SS)
G name VARCHAR(200)
G *li0 VARCHARI200)
G lnk_taiget VARCHAR(25)
G Ink.deacription VARCHAR(255)
G lnk_vistole VARCHAR(20)
v Ink.owner BIGINT(20)
G Ink. rating INT(11)
G lnk_updated DATETIME
G Ink.ml VARCHAR(2S5)
I ftk_ notes MEDIUMTEXT
G lnk_tss VARCHAR(255)
. 6.1. \/155
\155
. . ,
, .
\188,
, ,
.
, ,
: ://1.\188.
/05_05#111.
142
W ordPress .
ID, ,
,
. 5,
, , ,
, .
, ID.
ID,
. ,
WordPress , !.
, wp_posts, ID 1.
ID,
, .
, ,
.
wp_posts ID. , ID
.
, ID 1, 15.
, .
WordPress :
wp_commentmeta .
wp_comments WordPress,
ID.
wp_links , .
wp_options , ,
, .
wp_postmeta ( ).
wp_posts ( ),
, .
.
wp_terms , -,
,
.
wp_term_relationships ,
. ,
, .
143
wp_term_taxonomy ,
.
, .
wp_users ( , ,
).
wp_usermeta (/, ,
. .).
WordPress.
.
WordPress
wp_posts.
, , .
, .
. SQL
, ,
, WordPress:
SELECT * FROM wp_posts
WHERE post_type = 'post'
AND post_status = 'publish'
ORDER BY post_date DESC
144
6.
4. p riv ate .
5. f u t u r e ,
.
6. d r a f t .
7. tra sh .
,
. 12,
14. WordPress,
.
.
: , , .
WordPress 2.9 ,
WordPress.
p o s t_ ty p e
w p _ u sers .
ID,
. u s e r_ lo g in .
WordPress. u s e r_ p a ss phpass-
.
u s e r_ e m a il. u s e r _ u r l ,
u s e r _ r e g is te r e d .
wp_comments. , -.
, ID comment_ID.
-
. comment_post_ID ID ,
. , ,
WordPress. ,
.
com ment_author .
, , . comment_
a u t h o r _ e m a il ,
com m ent_author_url. comment_date,
.
.
WordPress
, ,
, ,
145
.
. ,
, wp_posts,
, ,
, .
,
:
1. wp_terms
URL.
() .
2. wp_term_taxonomy
.
.
,
wp_term_taxonomy , .
3. wp_term_relationships
.
SQL JOIN,
( ) . JOIN
,
. WHERE, JOIN, ,
.
, WordPress -,
wp_term_relationships,
JOIN wp_posts .
JOIN SQL
, .
. 6.2 wp_posts
.
wp posts
wp_term_relationships
w pterrntaxonom y
p o * t_ id
post_dat
taxonomy
d e s c r ip t io n
p oet co n te n t
wp_terms
ta rn id
M UM
s lu g
. 6.2.
146
6.
SQL
, JOIN
,
, ,
.
WordPress
WordPress
. wpdb wpin c lu d e s /w p -d b .p h p . , WordPress
, wpdb.
W ordPress
.
wpdb $wpdb
. ,
$wpdb:
global $wpdb;
wpdb ( ) .
, SQL.
SQL- -.
prpar. :
< ?php
$field_key = "address";
$field_value = "123 Elm St";
$wpdb->qury( $wpdb->prepare( "INSERT INTO $wpdb->my_custom_table
( id, field_key, field_value ) VALUES ( %d, %s, %s )", 1,
$field_key, $field_value ) );
?>
WordPress (
WordPress), .
p r p a r ( ), ,
%s %d .
p r p a r () . %d 1, %s
$ f ie ld _ k e y , %s $ f ie ld _ v a lu e . p r p a r
.
, $w pdb->m y_custom _table
WordPress. wp_m y_custom _table,
WordPress
147
wp_ .
WordPress.
---------------------------------------------------------------------
WordPress
. wp_,
. $wpdb->
WordPress.
wpdb query ( ) .
SELECT DELETE.
SQL SELECT,
SQL . :
<?php
$wpdb-query( $wpdb-prepare( " DELETE FROM $wpdb-my_custom_table WHERE
id = 1' AND field_key = 'address " ) );
?
, query ( )
wpdb fie ld "address" ID 1. queryQ
SQL WordPress,
SELECT. ,
get_var( ) :
<?php
global $wpdb;
$comment_count = $wpdb-get_var( $wpdb-prepare( "SELECT COUNT(*)
FROM $wpdb-comments;" ) );
echo <pTotal comments: ' . $comment_count . '</p>';
?
W ordPress
. ,
. ,
, WHERE,
, .
, .
.
, get_row( ).
get_row( ) ,
.
, . :
<?php
$thepost = $wpdb-get_row( $wpdb-prepare( "SELECT *
148
6.
?>
ID 1, .
{ th e p o st ,
wp_posts. , g et_ ro w ( )
:
< ?php
{thepost = $wpdb->get_row( {wpdb->prepare( "SELECT *
FROM $wpdb->postS WHERE ID = 1 " ), ARRAY_A );
print_r ( {thepost );
?>
ARRAY_A g e t_ ro w (),
.
ARRAY_N, .
SELECT g e t _ r e s u lt s ( )
.
SQL :
< ?php
{liveposts = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_title
FROM $wpdb->posts WHERE post_status = 'publish' " ) );
foreach ( {liveposts as {livepost ) {
echo '<p>' .$livepost->post_title. '</p>';
>
?>
WordPress
.
{ liv e p o s t s ,
.
WordPress
INSERT.
SQL, WordPress ,
. i n s e r t ():
UPDATE
{ t a b le , .
{ d a ta
. , ,
:
<?php
WordPress
149
, , ,
. in s e r t ( ),
. : f ie ld _ o n e f ie ld _ tw o
, .
, , .
u p d a te () i n s e r t (),
, WHERE, WordPress ,
:
$wpdb->update( {table, {data, {where );
.
{m y_id, ID .
u p d a te (). ,
, WHERE,
ID . ID 1.
, WHERE
.
in s e r t ( ) update ( )
, , ()
, . ,
INSERT UPDATE WordPress .
p re p a re Q .
.
,
, . wpdb
MySQL . :
<?php
{wpdb->show_errors();
{liveposts = {wpdb-get_results( {wpdb->prepare("SELECT ID, post_title
FROM {wpdb-posts_FAKE WHERE post_status = 'publish'") );
{wpdb->print_error();
?
150
6.
s h o w _ e rro rs ()
. p r in t _ e r r o r ( )
. SQL
. {wpdb- > h id e _ e rro rs ( ) ,
MySQL, $wpdb- >f lu s h (),
.
,
WordPress. :
var_dump( $wpdb->num_queries
var_dump( $wpdb->num_rows );
); //
// ,
//
var_dump( $wpdb->last_result ); //
var_dump( $wpdb->last_query ); //
var_dump( $wpdb->col_info );
//
,
.
.
{ q u e r ie s .
, WordPress. ,
SAVEQUERIES t r u e w p - c o n fig .
php. WordPress ,
, { q u e r ie s .
w p - c o n fig . php:
define( 'SAVEQUERIES', true );
{ q u e rie s .
:
var_dump( {wpdb-queries ); // ,
//
, .
,
WordPress. SAVEQUERIES,
,
.
,
W ordPress .
, ,
.
xkcd- Little Bobby Tables (xkcd #327),
, , DROP
TABLES, SQL-,
151
W ordPress. ,
SQL, ,
. ,
,
.
, WordPress
. , ,
. ,
SQL MySQL. , API WordPress
WordPress
.
wp_,
, wp-config.php
WordPress.
WordPress
phpMyAdmin, . 6.3.
3, phpMyAdmin ,
MySQL
-.
MySQL,
SQL . . 6.3
phpMyAdmin.
g j M y S Q L w p h a ls te m
S i
EJ
w p h alatem \11)
SOL
w p h jc o m m e n ts
S'
*
g
Ql
w p h s o p t io n s
w p h s p o stm e ta
w p h s p o s ts
w p h ste rm s
91
g)
w p _ h s te r m _ r e la t io n s h ip s
w p _ h M e rm _ t a x o n o m y
w p h s u se rm e ta
w p h s u s e is
$5
M y iS A M
utf8_genefai_ci
4 .0 KB
M y iS A M
ut_generai_Cf
. 3 KB
M y iS A M
utf8_genef8l_ci
1 .0 KS
i s s . M y iS A M
u tfB jje n e ra Q c i
35.3.2 KB
1 0 .1
X
X
X
X
*
X
X
X
: 11
X___
S
S
w p h e c o m m e n tm e ta
w p h e lin k s
w p h a ls t e in (11)
X
X
M y iS A M
u if8_general_ci
M y iS A M
u tf8_generai_ci
1 3 .1
utf8_generai_ci
1 1 .1 KS
M y iS A M
M y iS A M
utf8 _ _
S 0
M y iS A M
u tf8_generai_ci
M y iS A M
u tf8_generai_ci
M y iS A M
u tf8_general_ci
MyiSAM
u tf8 _ g o n e ra l_ c i
t3
1 1 .S KB
4.-2 KB
4 S 7 .5 EE
......A
SQL phpMyAdmin,
SQL .
WordPress.
152
6.
phpMyAdmin, . ,
SQL phpMyAdmin,
WordPress.
, ,
.
SQL. ,
, WordPress.
wp posts. :
, , ,
. post_type. WordPress 2.9
, 7. ,
post_type.
, :
SELECT * FROM wp_posts
WHERE post_type = 'revision'
wp_posts, postjtype
. , ,
WordPress:
SELECT guid, wp_posts.* FROM wp_posts
WHERE post_type = 'attachment'
guid .
guid URL .
wp_options ,
WordPress. , , option_name
option_value. , ,
, , .
:
SELECT * FROM wp_options
WHERE option_name IN ( 'siteurl','home' )
, option_name home
option_name s ite u r l. ,
WordPress . ,
:
UPDATE wp_options
SET option_value = 'http://yournewdomain.com'
WHERE option_name IN ('siteurl',home')
.
, WordPress. URL
.
153
,
, .
.
, .
, (, http://
n e w . e x a m p l e . c o m ) -.
w p _ o p tio n s . ,
, a c t iv e _ p lu g in s option_nam e:
SELECT *
FROM wp_options
WHERE option_name = 'active_plugins'
, .
WordPress -
. w p_options,
. , Akismet
akism et_spam _count, -.
:
SELECT * FROM wp_options
WHERE option_name = 'akismet_spam_count'
w p_users ,
WordPress. -
,
. wp_users ,
, , , URL
. , .
, :
SELECT DISTINCT user_email
FROM wp_users
,
WordPress! , wp_users,
.
, WordPress,
. ,
u se r_ p a ss MySQL:
UPDATE wp_users
SET user_pass = MD5( 'Hall0w33n)
WHERE user_login ='admin'
LIMIT 1;
Hall0w33n. ,
M D5( ). MD5 hash.
WordPress^.S
154
6.
ID 1554.
wp_comments u s e r_ id . -
, ID. ,
, :
SELECT wc.* FROM wp_comments wc
INNER JOIN wp_users wu ON wc.user_id = wu.ID
WHERE wu.user_login = 'admin'
. 6.1
.
. ,
, :
SELECT * FROM wp_comments
INNER JOIN wp_posts ON wp_comments.comment_post_id = wp_posts.ID
WHERE wp_postS.ID = '1'
ID 1. ,
w p_com m ents.com m ent_post_ID w p _ p o s ts .ID .
JOIN SQL,
N:l. ,
.
. ,
, w p_users wp_usermeta:
SELECT * FROM wp_users
INNER JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id
WHERE wp_users.ID = '1'
, w p_users. ID
w p_userm eta. u s e r_ id .
, , ID 1,
. :
,
WordPress INNER JOIN
.
155
SQL, : http://
www.w3schools.com/sql/default.asp.
WordPress,
, WordPress
. , ,
, , WordPress.
, WordPress ,
.
WordPress,
. ,
, WordPress.
,
*
:
- WordPress . WordPress
,
, .
WordPress
^.
, ,
.
,
WordPress.
. , ,
.
WordPress
WordPress ,
. WordPress
:
WordPress
157
1. Post (). , .
2. Page (). .
3. Attachment (). , WordPress
, .
4. Revision (). , ,
.
5. Nav Menus ( ). ,
WordPress.
.
CMS,
.
?
WordPress ,
.
W ordPress,
, .
.
:
;
;
;
;
;
.
,
, . ,
,
.
.
register_post_ ty p e():
< ?php register_post_type( $post_type, $args ); ?>
7. ,
158
),
)
);
>
?>
WordPress. ,
(Comments)
Products (),
. 7.1. ,
.
, WordPress
.
,
WordPress. ,
,
WordPress.
Cg]
(1
#*>
U
[I
. 7.1.
-------------------------------------------
in it . , WordPress,
,
.
WordPress
159
.
, .
public
,
.
fa ls e , .
show_ui, exclude_from_search, publicly_queryable show_in_nav_menus
.
show__ui
,
WordPress .
public.
publicly_queryable
,
. fa lse ,
404, .
public.
show_in_nav_menus
,
WordPress. public.
supports
,
( t i t l e editor):
t i t l e .
e d ito r
.
author .
thumbnail .
excerpt .
160
7. ,
comments ,
.
trackbacks , .
cu sto m -field s
.
p ag e-attrib u tes .
h ie ra rc h ic a l true.
revisions .
post-form ats
.
labels
, .
. .
hierarchical
h ie ra rc h ic a l , ,
WordPress. h ie ra rch ica l
.
false.
has_archive
.
WordPress, .
,
.
can_export
,
WordPress ( ).
true.
taxonomies
. , category
post_tag,
.
.
WordPress
161
men imposition
,
.
.
menuJeon
.
.
showJn_menu
, .
: tru e , f a l s e .
, t o o l s . php, e d i t . php?post_type=page.
m enu_slug,
.
show_ui.
showJn_admin_bar
,
W ordPress.
show_in_menu.
capabilityJ y p e
.
p o st.
capabilities
, ,
, .
query_var
.
t r u e $ p o s t_ ty p e .
rewrite
r e w r it e .
URL.
tru e , f a l s e .
162
7. ,
slug .
$post_type.
with_f ront ,
. , /blog,
with_f ront true,
/blog.
pages ,
. true.
feeds ,
. has_archive.
true, a $post_type
.
.
.
<?php
add_action( 'init', 'prowp_register_my_post_types' );
function prowp_register_my_post_types() {
$args = array(
'public' => true,
'has_archive' => true,
'taxonomies => array( 'category' ),
'rewrite' => array( 'slug* => 'product' ),
'supports' => array( 'title', editor', 'author', 'thumbnail', 'comments' )
);
register_post_type( 'products, $args );
}
?>
, .
, ,
has_archive true. taxonomies,
Category Products.
. http://example.com/products/zombie-bait,
products ,
product. http://example.com/
product/zombie-bait. re w rite
.
supports. , , ,
.
re g iste r_ p o st_ ty p e ()
http://codex.wordpress.org/Function_
Reference/ register_post_ty .
WordPress
163
------------------------------------------------------------------------------
WordPress. , f lush_rew rite_
r u le s ( ) ,
. 404
.
WordPress
.
, .
,
.
,
,
Add New Post ( ).
, Product. ,
, . labels
()
, .
:
name , .
WordPress, .
singular_name .
WordPress, .
add_new Add New (
). : Add New.
add_new_item
. : Add New Post/Page (
/).
edit_item .
: Edit Post/Page ( /).
new_item . : New P o st/
Page ( /).
view_item . :
View Post/Page ( /).
search_items , .
: Search Posts/Pages ( /).
16 4
7. ,
n o t_ fo u n d , , .
: No posts/pages found (/ ).
n o t_ fo u n d _ in _ tra s h , ,
. : No posts/pages found in Trash (/
).
p a re n t_ ite m _ c o lo n , .
,
Parent Page ( ).
WordPress
.
Product:
<?php
add_action( 'init', 'prowp_registen_my_post_types' );
function prowp_register_my_post_types() {
{labels = array(
'name' => 'Products',
'singular_name' => 'Product',
add_new' => 'Add New Product,
'add_new_item' => Add New Product',
edit_item' => 'Edit Product',
'new_item' => 'New Product',
all_items' => 'All Products',
'view_item' => 'View Product',
'search_items => 'Search Products',
'not_found' => 'No products found',
'not_found_in_trash' => 'No products found in Trash',
'parent_item_colon' => ",
'menu_name' => 'Products'
);
{args = array(
'labels'
'public'
=>
=>
{labels,
true
);
register_post_type( 'products', {args );
>
?>
, , ,
, WordPress.
.
,
, . ,
.
,
WP_Query, 5. ,
WordPress
165
p o s t_ ty p e , ,
. Product
WordPress:
WP_Query
$args = array(
'posts_per_page' => '-1',
'post_type' => 'products',
);
JmyProducts = new WP_Query( $args );
//
while ( $myProducts->have_posts() ) : $myProducts->the_post();
?><a href="<?php the_permalink(); ?>"><?php the_title(); ?></axbr /><?php
endwhile;
I l $post
wp_reset_postdata();
, p o s t_ ty p e p ro d u c ts ,
$ p o s t_ ty p e
Products.
,
Specials:
$args = array(
'posts_per_page' => '-1',
'post_type' => 'products',
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'specials'
)
)
);
{myProducts = new WP_Query( $args );
ta x _ q u e ry WP_Query,
Product, Specials.
WP_Query,
5, .
WordPress,
.
h a s _ a r c h iv e .
,
.
a r c h iv e - { p o s t - t y p e } . p h p . ,
16 6
7. ,
P roduct a r c h iv e - p r o d u c t s .
php. .
, WordPress
. ,
.
sin g le -{ p o s tty p e } . php. ,
Product s ingle-prod uet s . php.
, http://example.com/products/zombie-bait,
s in g le -p ro d u c ts .php.
, ,
9.
W ordPress ,
.
,
.
WordPress,
get_post_types ( ).
<?php get_post_types( {args, {output, {operator ); ?>
:
1. {args , .
,
WordPress, get_post_types( ) :
{args = (
'public'
=> true,
'_builtin' => false
);
{post_types = get_post_types( {args, 'names', 'and' );
foreach ( {post_types as {post_type ) {
echo '<p>'. {post_type. '</p>';
>
, {args: p u b lic
_ b u iltin . p u b lic
, . _ b u ilt in
fa ls e , , ,
. {output
WordPress
16 7
{operator and ()
{args, .
, ,
get_post_type():
<?php get_post_type( {post ); ?>
{post ID .
, :
<?php echo 'The post type is: '.get_post_type( {post->ID ); ?>
, ,
. ,
. p o st_ typ e _ e xists().
<?php post_type_exists( {post_type ); ?>
{post_type
, .
, products,
:
if( post_type_exists( 'products' ) ) {
echo 'The Products post type exists';
>
add_post_type_support( ).
, .
<?php add_post_type_support( {postjtype, {supports ) ?>
,
. add_post_type_support()
:
1. {post_type , .
2. {supports .
, pro ducts
. ,
:
add_post_type_support( 'products', array( 'thumbnail', 'comments' ) );
,
, .
,
168
7. ,
a d d _ p o s t_ ty p e _ s u p p o rt() ,
.
WordPress . s e t_ p o s t_
ty p e Q .
<?php set_post_type( $post_id, $post_type ); ?>
:
1. $post_id ID , ( ).
2. $post_type , (
post).
WordPress
.
. W ordPress
. , .
( ), ,
.
WordPress :
1. (Category) .
2. (Tag) , .
3. (Link category) .
.
.
W ordPress.
WordPress .
.
, ,
.
WordPress.
,
,
WordPress .
-.
WordPress
169
WordPress ,
: wpjterms, wp_term_relationships wp_term_taxonomy.
, WordPress 2.3,
WordPress ,
.
wp_terms . ,
,
. wp_term_taxonomy ,
. , ID
post_tag. ,
. wp_term_relationships
. ,
, ID
ID .
,
. 7.2.
e o b je c tjd BIGINT(20)
f> term _ tax o n o m y Jd BIGINT(20)
term _order INT(11)
PRIMARY
term _ tax o n o m y Jd
te r m ja x o n o m y jd BIGINT(20)
te r m j d 8IGINT(20)
taxonom y VARCHAR(32)
description LONGTEXT
parent BIGINT(20)
count BIGINT(20)
PRIMARY
I te rm J d J a x o n o m y
taxonom y
te r m j d BIGINT(20)
nam e VARCHAR(200)
slug VARCHAR(200)
term _group BIGINT(10)
PRIMARY
slug
name
. 7.2.
1 70
7. ,
, ID.
:
SELECT wt.name, wp.post_title, wp.post_date FROM wp_terms wt
INNER DOIN wp_term_taxonomy wtt ON wt.term_id = wtt.term_id
INNER DOIN wp_term_relationships wtr ON wtt.
term_taxonomy_id = wtr.term_taxonomy_id
INNER DOIN wp_posts wp ON wtr.object_id = wp.ID
WHERE wp.post_type = 'post'
, , . 7.2.
: ,
.
WordPress, .
------------------------------------------------------------------------------ , WordPress
,
WordPress 6 .
. ,
- .
, ,
. .
WordPress
(CMS).
WordPress 2.3
. W ordPress
.
WordPress 2.8
. WordPress
.
!
product,
171
. ,
.
,
WordPress.
WordPress re g is te r_ ta x o n o m y ( ). ,
.
,
fu n c t io n s .p h p . f u n c t io n s .p h p :
< ?php
add_action( 'init', 'prowp_define_product_type_taxonomy' );
function prowp_define_product_type_taxonomy() {
register_taxonomy( 'type', 'products', array( 'hierarchical' => true,
'label' => 'Type', 'query_var' => true, 'rewrite' => true ) );
>
?>
i n i t ,
WordPress p ro w p _ d e fin e _ p ro d u ct_ ty p e _ ta xo n o m y()
. W ordPress r e g i s t e r _
taxonomy ( ).
.
, re g iste r_ ta x o n o m y ( ).
, typ e . ,
. .
p ro d u c ts,
. ,
.
. h ie r a r c h ic a l,
, ,
. tru e ,
WordPress, . l a b e l
WordPress. q u e ry _ v a r f a ls e ,
, t r u e (
) URL.
q u e ry _ v a r
. , query_var => ' s tre n g th ' URL example.
com /?strength= w eapons
.
r e w r it e , t ru e .
W ordPress,
. t ru e ,
7. ,
172
example.com/type/weapons, example.com/?type=weapons.
, type,
, WordPress. ,
, ()
(Products), . 7.3.
. 7.3.
, . 7.4.
, ,
, ,
.
,
.
:
:
surveillance
bait
weapon
supplies
* ,
, .
:G
* j :
. 7.4.
, ,
, . 7.5.
, (Add New Product).
173
.
.
,
:
p u b lic ,
.
true. show_ui show_in_nav_menus
.
show_ui ,
WordPress .
public.
| ;
[ |
:
:
Q
Q
saSsm t
. 7.5.
show_in_nav_menus ,
W ordPress.
public.
show_tagcloud ,
(Tag Cloud) .
show_ui.
h ie r a rc h ic a l ,
( ) ( ).
f aise.
u p d a te _ co u n t_ ca llb a ck , ,
. : .
174
7. ,
query_var var .
true, fa ls e
var.
re w rite re w rite
.
URL. true, fa ls e
. :
slug .
name .
w ith _ f ront ,
. ,
/blog, w ith _ fro n t true,
/blog.
h ie r a r c h ic a l U R L . :
fa lse .
true, a {taxonomy
.
register_taxonom y()
http://codex.wordpress.org/Function_
Reference/register_taxonomy.
W ordPress,
,
.
, .
(Tag)
, (Category) .
:
name , .
singular_name .
search_items .
popular_iterns .
a ll_ ite m s .
parent_item .
.
parent_item _colon , parent_item, .
edit_ item .
175
update_item
.
add_new_item .
new_item_name .
separate_items_with_commas ,
. .
add_or_remove_items ,
JavaScript. .
choose_from_most_used ,
. .
menu_name . name.
.
:
<?php
add_action( 'init', 'prowp_define_product_type_taxonomy' );
function prowp_define_product_type_taxonomy() {
{labels = array(
'name' => 'Type',
'singular_name => 'Types',
'seanch_items' => 'Search Types',
'all_items' => 'All Types',
'parent_item' => 'Parent Type',
'parent_item_colon' => 'Parent Type:,
'edit_item' => 'Edit Type',
'update_item' => 'Update Type,
'add_new_item' => 'Add New Type',
'new_item_name' => 'New Type Name',
'menu_name' => 'Type'
);
{args = array(
'labels' => {labels,
'hierarchical' => true,
'query_var' => true,
'rewrite' => true
);
register_taxonomy( 'type', 'products', {args );
>
?>
, , ,
. , WordPress
.
176
7. ,
, ,
:
<?php wp_tag_cloud( ( 'taxonomy' => 'type', 'number' => 5 ) ); ?>
wp_tag_cloud ( ) ,
: taxonomy number. type
, WordPress ,
. , ,
5.
,
( ).
, WP_Query
. ,
weapon:
<?php
$args = array(
'post_type' =>
'tax_query' =>
array(
'taxonomy'
'field' =>
'terms' =>
'products',
array(
=> 'type',
'slug',
'weapon'
)
)
)J
{products = new WP_Query( {args );
while ( {products->have_posts() ) : {products->the_post();
echo '<p>' .get_the_title(). </p>';
endwhile;
wp_reset_postdata();
?>
! WP_Query, , post_ty ,
products, tax_query, , .
, . ,
get_th e _ te rm _ list ( ). g e t_ th e _ ta g _ list( ),
.
<?php echo get_the_term_list( {post->ID, 'type', 'Product Type: ',
' *
" ); ?>
,
.
, . ID
, ,
. ,
177
, : http://codex.
word press.org/ Function_Reference/get_the_term_list.
get_terms ()
.
type ,
:
?php
$terms = get_terms( 'type' );
foreach ( {terms as {term ) {
echo '<p>' .{term->name. '</p>';
>
?>
, , ,
.
- , ,
register_taxonomy (),
.
WordPress
-.
WordPress.
,
, WordPress,
, .
.
?
WordPress
, . ,
products ,
.
.
WordPress (
) (Custom Fields). ,
. W ordPress
,
. 7.6. cu sto m -fie ld s,
supports, .
17 8
7. ,
, 8
. 7.6.
wp_postmeta WordPress.
WordPress
add_post_meta().
:
<?php a d d _ p o s t_ m e ta ( { p o s t _ id ,
{ m e ta _ k e y , { m e ta _ v a lu e , { u n iq u e ) ;
?>
:
{post_id ID , .
{meta_key .
{meta_value .
{unique , , .
fa ls e .
, add_post_meta(),
.
a d d _ p o s t_ m e ta ( 4 2 0 ,
' p r o w p _ p r ic e ',
'3 4 . 9 9 ',
tru e
);
prowp_price
34.99 ID 420. {unique true, ,
prowp_price .
, WordPress, prowp_price
.
------------------------------------------------------------------------------
,
_prowp_price. ,
.
179
, ,
, 11_51_1().
, , .
, .
<? ^_5-1^( {^!, $1_, $!_1, $_1 ); ?>
:
$1:_:11 , .
$4_ .
$^_1 .
$_1 .
,
.
, :
^_51_^( 420, 'prowp_pri.ee', '6.99' );
, , ,
. ,
1]^_51:_! ( )
.
:
{-^! , .
$!_ .
$1^_ 1 .
, .
, :
1]^_51:_^( 420, 'prowp_pri.ee' );
180
7. ,
, , .
, . WordPress
.
,
.
, get_post_meta():
<?php $meta_values = get_post_meta( {post_id, {key, {single ); ?>
:
{post_id ID , .
$meta_key .
{single , , (tru e)
(false). false.
, :
{product_price = get_post_meta( 420, prowp_price', true );
echo 'Price {' .{product_price;
ID 420. ,
.
:
<?php
add_post_meta( 420, 'prowp_colors', 'orange', false );
add_post_meta( 420, 'prowp_colors', 'black', false );
{product_colors = get_post_meta( 420, 'prowp_colors', false );
echo '<ul class="product-colors">';
foreach ( {product_colors as {color ) {
echo '<li>' .{color .'</li>'j
}
echo </ul>';
?>
.
add_post_meta().
{unique fa lse ,
.
get_post_meta()
. , {single false,
prowp_colors ID 420 .
, .
181
get_post_
customQ.
.
<?php get_post_custom( $post_id ); ?>
$post_id ID ,
.
:
<?php
{product_metadata = get_post_custom( 420 );
foreach( $product_metadata as {name => {value ) {
echo 'strong' .{name .'/strong =>
foreach( {value as {nameAr => {valueAr ) {
echo <br />' .{nameAr." => "j
echo var_dump( {valueAr );
>
echo '<br />';
}
?
ID 420.
,
.
, ,
.
.
, ,
WordPress
. WordPress
,
.
WordPress.
WordPress, ,
, ,
WordPress.org.
:
WordPress -
API
Wrox.com
w w w . w r o x . c o m / r e m t i t l e .
c g i ? i s b n = 9 7 8 1 1 1 8 4 4 2 2 7 2 ( D o w n l o a d C o d e ) .
8 ,
.
WordPress
. ,
WordPress. ,
WordPress.
,
. , API,
WordPress, ,
,
WordPress. , , ,
. .
1 83
, ,
WordPress .
WordPress
,
, , WordPress.
,
, .
,
: , .
WordPress P H P -
. ,
plugins.
, WordPress .
,
, , , .
, ,
. ,
.
,
. , ,
/images ,
.
:
/unique-plugin-name ( )
unique-plugin-name.php ( PH P- )
u n in s ta ll. php ( )
/ j s ( JavaScript)
/c ss ( )
/includes ( )
/images ( )
.
184
8.
WordPress .
PH . , .
WordPress, WordPress
.
:
<?php
/*
Plugin Name: Halloween Plugin
Plugin URI: http ://example.com/wordpress-plugins/halloween-plugin
Description: This is a brief description of my plugin
Version: 1.0
Author: Michael Myers
Author URI: http://example.com
License: GPLv2
*/
?>
Plugin Name.
, .
, ,
WordPress. , , . 8.1.
Q
Halloween Plugin
|
1.01: Michael Myers |
. 8.1.
, ,
. ,
- URL .
, ,
.
,
. ,
. , -
, .
GPL, WordPress:
<?php
/* Copyright YEAR PLUGIN_AUTHOR_NAME (email : PLUGIN AUTHOR EMAIL)
This program is free software; you can redistribute it and/or modify
185
USA
*/
?>
,
, .
GPL.
WordPress
GPLv2. .
WordPress,
GPL . GPL
http://www.gnu.org/licenses/licenses.html.
. register_activation_hook().
WordPress.
:
.
, ,
prowp ,
. ,
.
prow p_install():
<?php
register_activation_hook(
FILE
function prowp_install() {
// ,
, prowp_install' );
}
?>
. , WordPress,
, .
.
, ,
WordPress .
186
8.
, , ,
, WordPress.
<?php
register_activation_hook(
FILE , prowp_install' );
function prowp_install() {
global $wp_version;
if ( version_compare( $wp_version, 3.5', '< ) ) {
wp_die( 'This plugin requires WordPress version 3.5 or higher.' );
}
}
?>
$wp_version,
WordPress
, 3.5.
version_compare(). WordPress 3.5,
.
, , .
register_deactivation_hook(). ,
W ordPress. ,
register_activation_hook. :
<?php
register_deactivation_hook(
FILE
function prowp_deactivate() {
// ,
, 'prowp_deactivate()' );
>
?>
------------------------------------------------------------------------------ , .
. ,
, .
.
, WordPress il8n,
. WordPress
, .
, , .
,
, .
.
WordPress ,
. ( ). :
, :
187
, .
, .
.
,
.
,
_ ():
<?php _( 'Howdy Neighbor!', 'prowp-plugin' ); ?>
,
.
(); ,
. , ,
:
Error Code 6980: Email is a required field
,
, :
<?php
$error_number = 6980;
$error_field = "Email";
{error = __( 'Error Code ', 'prowp-plugin' ) .{error_number. ': '
,{error_field .__( is a required field', 'prowp-plugin' );
echo {error;
?>
,
.
. , , . :
<?php
{error_number = 6980;
{error_field = "Email";
printf(
( 'Error Code %l{d: %2{s is a required field', 'prowp-plugin' ),
{error_number, {error_field );
?>
, p r in tf Q ,
. p r in tf Q
. ,
, Error
Code %l{d: %2{s is a required f ie ld ,
,
.
188
8.
.
s p r in tf (),
.
. , :
<?php
$count = 1;
printf( __( 'You have %d new message', 'prowp-plugin' ), $count );
?>
, . , ?
, WordPress ,
: _ (). :
<?php
$count = 34;
printf( _n( 'You have %d new message', 'You have %d new messages',
$count, 'prowp-plugin'), $count );
?>
: , ,
. _ ()
($coun.t ), ,
.
WordPress ,
. ,
,
. _():
<?php
echo _( 'Editor', 'user role', 'prowp-plugin' );
echo _x( 'Editor', 'rich-text editor', 'prowp-plugin' );
?>"
, .
. , , .
,
. .
,
. , load_plugin_
textdomainQ:
<?php
add_action( 'init', 'prowp_init' );
function prowp_init() {
load_plugin_textdomain( 'prowp-plugin', false,
plugin_basename( dirname(
FILE
) ./localization' ) );
}
?>
189
,
.
ABSPATH;
(deprecated), .
/ p lu g in s . ,
/ l o c a l i z a t i o n .
plugin_basenam e( ) d irn am e( ), .
WordPress
http://codex.wordpress.org/I18n_for_WordPress_Developers.
WordPress
WordPress. W ordPress 2.6
.
. WordPress
w p -co n te n t p lu g in s ,
.
, , , , ,
, .
,
p lu g in _ d ir _ p a t h ( ) .
.
< ?php echo plugin_dir_path(
FILE
); ?>
, P H P - F ILE p lu g in _ d ir _ p a t h ( ).
:
/public_html/wp-content/plugins/halloween-plugir/
,
. p lu g in _ d ir _ p a t h ( )
, :
< ?php echo plugin_dir_path(
FILE
.'js/script.js' ); ?>
:
/public_html/wp-content/plugins/halloween-plugin/js/script.js
URL
URL ,
p lu g in s _ u r l( ) :
190
8.
FILE
).
?>
, plugins_url( ) .
URL , ,
. - F ILE .
URL icon.png,
:
<img src="http://example.com/wp-content/plugins/halloween-plugin/images/icon.png">
plu g in s_ u rl()
URL :
/mu-plugins;
SSL. SSL , URL
h ttp s : / /;
,
/wp- content ;
Multisite.
WordPress URL:
admin_url() URL (http://example.com/wp-admin/).
s ite _ u rl( ) URL (http://example.com).
home_url() URL (http://example.com).
includes_url() URL Includes (http://example.com/wp-includes/).
content_url() URL Content ( http://example.com/wp-content/).
wp_upload_dir( )
.
WordPress,
.
. ,
WordPress . WordPress
,
, , ,
.
, ,
. ,
191
.
. ,
.
(Nonces)
Nonces, , ,
( , , Ajax, ),
.
(, ).
- . ,
.
:
form method="post">
<?php wp_nonce_field( 'prowp_settings_form_save', 'prowp_nonce_field' ); ?>
Enter your name: input type="text" name="text" /x br />
input type="submit" name="submit" value="Save Options" />
</form>
w p _ n o n c e _ fie ld ( )
<form>. ,
.
, { a c t io n , ,
. , {name.
_wpnonce,
.
w p _ n o n c e _ fie ld ( ) ,
.
,
, c h e c k _ a d m in _ re fe re r( ) ,
:
function prowp_update_options() {
if ( isset( {_POST['submit'] ) ) {
//
check_admin_referer( 'prowp_settings_form_save', 'prowp_nonce_field' );
// , ,
>
>
c h e c k _ a d m in _ re fe re r()
, .
, , WordPress
.
(CSRF, cross-site request forgery).
8.
192
,
. URL,
wp_nonce_url( ).
URL:
<?php
{link = 'my-url.php?action=delete&ID=15';
?>
<a href="<?php echo wp_nonce_url( {link, 'prowp_nonce_url_check' ); ?>">Delete</a>
wp_nonce_url( ) : URL,
, ,
. :
http ://example.com/wp-admin/my-url.php?action=delete&ID=15&_wpnonce=e9d6673015
, _wpnonce .
,
URL. URL , wp_nonce_url( )
, . URL
,
URL. ,
, check_admin_referer( ):
function prowp_update_options() {
if ( isset( {_GET['action'] ) ) {
//
check_admin_referer( 'prowp_nonce_url_check' );
// ,
>
}
,
.
. ,
,
.
, (, ),
, ,
.
.
SQL, , . .
WordPress ,
, ,
.
193
(. ), , . . 8.2
.
esc_ .
_.
esc_attr_e( )
1 2 3
. 8.2.
esc_html() , HTML.
HTML.
':
<?php esc_html( {text ); ?>
esc_attr() HTML.
, HTML:
<input type="text" name="first_name" value="<?php echo esc_attr( {text ); ?>">
W ordPress URL,
esc_url(). URL .
href HTML,
esc_url() :
< href="<?php echo esc_url( {url ); ?>">
esc_js( ) JavaScript:
<script>
var bwar='<?php echo esc_js( {text ); ?>';
</script>
194
8.
( _)
. _ , __
.
<?php
// ,
esc_html_e( $text, 'prowp-plugin' );
// , ,
{text = esc_html ( {text, 'prowp-plugin' );
?>
, , ,
P H P - in tv a l(). in tv a l()
. ,
0.
{variable = 12345;
{variable = intval( {variable );
absint (). ,
:
{variable = 12345;
{variable = absint( {variable );
WordPress .
. sanitize_
tex t_field (). UTF-8,
< HTML ,
.
<?php sanitize_text_field( {text ); ?>
, sanitize_email().
, .
:
<?php
{sanitized_email = sanitize_email( '
ric@loremipsum.com!' );
echo {sanitized email; // : ric@loremipsum.com
?>
, sanitize_email()
.
HTML wp_kses().
WordPress, ,
HTML. HTML,
(XSS)
. :
{allowedjtags = array(
'strong'
=>
array ,
'a'
=>
array(
'href*
'title'
=>
=>
19 5
array(),
array()
)
);
HTML.
<strong> <>. <>
h re f t i t l e . $html .
$html $allowed_tags wp_kses( ).
:
< href="#">link</a>.
, <bx/b> .
c la s s <>, .
. ,
HTML,
wp_kses( ) ,
HTML.
WordPress,
: http://codex.wordpress.org/Data_Validation.
------------------------------------------------------------------------------
.
WordPress.
:
W ordPress
(hook).
WordPress. ,
W ordPress , ,
WordPress .
WordPress.
,
-!
. ,
:
<?php add_action( $tag, $function_to_add, {priority, $accepted_args ); ?>
19 6
8.
: . -
WordPress. , -
. -
WordPress .
, - .
, ,
, .
-. , -
, , :
<?php add_filter( 'the_content', prowp_function' ); ?>
a d d _ f i lt e r ( ) -.
th e _ c o n te n t, .
WordPress,
p ro w p _ fu n ctio n ( ). add_f i l t e r ( )
:
1. f ilt e r _ a c t io n ( s t r in g ) : .
2. c u s t o m _ filt e r _ fu n c t io n ( s t r in g ) :
3. p r i o r i t y ( in t e g e r ) : .
p r i o r i t y
.
4. a cce p te d a rg s ( in t e g e r ) : , .
th e _ c o n te n t :
<?php
add_filter( 'the_content', ,prowp_profanity_filter' );
function prowp_profanity_filter( {content ) {
{profanities = array( 'sissy', 'dummy' );
{content= str_ireplace( {profanities, '[censored]', {content );
return {content;
>
?>
p r o w p _ p r o f a n i t y _ f i l t e r ( ) sissy
dummy [c e n so re d ] -.
, s t r _ ir e p la c e ( ) .
. s t r _ i r e p l a c e ( )
. -,
, th e _ p o s t ( ),
, .
, sissy dummy -
, ,
197
. - .
{con te n t, .
, { c o n te n t. ,
,
.
, - , - . - WordPress.
WordPress - , , .
- , -,
:
<?php add_action( 'hook_name', 'prowp_function' ); ?>
a d d _ a c t io n ( ) , a d d _ f i l t e r ( ).
, ,
, .
-:
<?php
add_action( 'comment_post', 'prowp_email_new_comment );
function prowp_email_new_comment() {
wp_mail( 'me@example.com', 'New blog comment',
'There is a new comment on your website: http://example.com' );
>
?>
, - comment_post.
WordPress .
, prowp_em ail_new_com m ent()
. ,
,
. - ,
.
-
W ordPress 1500 -,
. , .
WordPress.
-:
th e _ c o n te n t .
t h e _ c o n te n t_ r s s
RSS.
t h e _ t i t l e .
198
8.
comment_text .
w p_title < title > .
th e _ p e rm a lin k URL.
- W ordPress
, ,
- the_content.
. ,
, :
<?php
add_filter ( the_content', 'prowp_subscriber_footer' );
function prowp_subscriber_footer( {content ) {
if( is_single() ) {
{content.= <h3>Enjoyed this article?</h3>';
{content.= <p>Subscribe to my
<a href="http://example.com/feed">RSS feed</a>!</p>';
}
return {content;
}
?>
.
, i s _ s i n g l e ( )
,
. { c o n te n t , ,
, .
,
. , ,
, .
- th e _ title .
. :
<?php
add_filter( 'thejtitle', 'prowp_custom_title' );
function prowp_custom_title( {title ) {
{title .= ' - By Example.com';
return {title;
>
?>
- By E xam ple.com
. , ,
.
- d e f a u lt _ c o n t e n t
. ,
,
:
199
< ?php
add_filter( 'default_content', 'prowp_default_content' );
function pnowp_default_content( {content ) {
{content = 'For more great content please subscribe to my RSS feed;
return {content;
>
?>
-
.
WordPress -
WordPress.
-
-:
publish_post .
create_category .
. switch_theme .
admin_head <head> .
wp_head <head> .
wp_footer , </body>.
in it , WordPress ,
. HTML {_GET {_POST.
admin_init , in it,
.
user_register .
comment_post .
- wp_head.
wp_head, <head>
WordPress. :
< ?php
add_action( 'wp_head', prowp_custom_css' );
function prowp_custom_css() {
?>
style type="text/css">
a {
font-size: 14px;
color: #000000;
text-decoration: none;
>
a:hover {
font-size: 14px
200
8.
color: #FF0000;
text-decoration: underline;
}
</style>
<?php
}
?>
p ro w p _cu sto m _css()
WordPress, CSS.
w p _ f o o t e r -.
,
WordPress.
-:
<?php
add_action( 'wp_footer', 'prowp_site_analytics' );
function prowp_site_analytics() {
?>
<script type="text/javascript"
var gaDsHost = (("https:" == document.location.protocol) ?
"https://ssl." : "http://www.");
document.write(unescape("%3Cscript src=" + gaDsHost +
'google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript"
var pageTracker = _gat._getTracker("UA-XXXXXX-XX");
pageTracker._trackPageview();
</script
<?php
}
?
, Google
Analytics .
- admin_head wp_head,
, . ,
CSS
.
- u s e r _ r e g i s t e r W ordPress
.
. ,
-
, ,
.
, ,
WordPress.
. .
( http://codex.wordpress.org/Plugin_API/Filter_Reference)
201
( http://codex.wordpress.org/Plugin_API/Action_Reference),
.
(http://
wordpress.org/extend/plugins/) WordPress.org.
,
. ,
, . ,
WordPress , .
,
.
.
, ,
.
WordPress.
,
. WordPress
, .
: add_option() update_option(). ,
update_option() , .
:
<?php add_option( 'prowp_display_mode', 'Fright Night ); ?>
, a d d _ o p tio n ( ),
. ,
, WordPress,
. .
, , ,
.
update_option( ). , ,
. ,
, . update_option( )
, :
<?php update_option( 'prowp_display_mode, 'Fright Night' ); ?>
update_option( ). ,
202
8.
. ,
g e t_ o p tio n ( ):
<?php echo get_option( prowp_display_mode' ); ?>
g e t_ o p tio n ( ) ,
. , FALSE.
, .
, d e le t e _ o p t io n ( ).
:
<?php delete_option( 'prowp_display_mode' ); ?>
,
prowp_ . :
.
. ,
(. ).
, ,
. .
WordPress .
.
, , ,
, .
, WordPress,
w p _ o p tio n s .
,
u p d a te _ o p tio n ().
<?php
$prowp_options_arr = array(
,prowp_display_mode'
=>
'prowp_default_browser' =>
prowp_favorite_book
=>
Fright Night',
'Chrome',
'Professional WordPress',
);
update_option( 'prowp_plugin_options', $prowp_options_arr );
?>
. u p d a te _ o p tio n ( )
,
p ro w p _ p lu g in _ o p tio n s . ,
, 50 o p t io n s .
203
.
get_option(),
:
<?php
$prowp_options_arr = get_option( 'prowp_plugin_options' );
$prowp_display_mode = $prowp_options_arr['prowp_display_mode'];
$prowp_default_browser = $prowp_options_arr[prowp_default_browser'];
$prowp_favonite_book = $prowp_options_arr['prowp_favorite_book'];
?>
,
.
WordPress
. ,
.
( )
( ).
.
, ,
. ,
, .
, add_menu_page, :
< ?php add_menu_page( page_title, menu_title, capability,
menu_slug, function, icon_url, position ); ?>
:
p a g e jtitle , HTML ( < title>).
m enu_title , .
c ap a b ility , .
menu_slug - .
function .
icon_url ( im ages/generic.
png).
position .
.
204
8.
.
add_submenu_page():
add_submenu_page( parent, page_title, menu_title, capability,
menu_slug,[function] );
,
. 8.3.
<?php
//
add_action( 'admin_menu', 'prowp_create_menu' );
function prowp_create_menu() {
//
add_menu_page( 'Halloween Plugin Page', 'Halloween Plugin',
'manage_options', 'prowp_main_menu', 'prowp_main_plugin_page',
plugins_url( '/images/wordpress.png',
FILE
) );
// :
add_submenu_page( 'prowp_main_menu', 'Halloween Settings Page,
'Settings, 'manage_options', 'halloween_settings,
'prowp_settings_page' );
add_submenu_page( 'prowp_main_menu', 'Halloween Support Page',
'Support', 'manage_options', 'halloween_support', 'prowp_support_page' );
}
?>
- admin_menu.
.
prowp_create_menu()
.
, add_menu_
Senos
page ().
Support
__ __
. manage
. 8.3.
options, .
^ 0
propwp_main_menu,
.
, prowp_main_plugin_page. ,
,
. ,
WordPress.
.
: Settings () Support
(). , add_submenu_page().
,
. , prowp_main_menu,
. ,
. manage_options.
, .
205
, WordPress.
,
. ,
WordPress.
:
<?php
add_action( 'admin_menu', 'prowp_create_settings_submenu' );
function prowp_create_settings_submenu() {
add_options_page( 'Halloween Settings Page', 'Halloween Settings',
'manage_options', 'halloween_settings_menu, 'prowp_settings_page' );
>
?>
WordPress ,
. Halloween Settings,
add_options_page( ). ,
.
, manage_options,
.
halloween_settings_menu.
p ro w p _ se ttin g s_ p a g e( ) .
Halloween
Settings.
WordPress .
,
, :
add_dashboard_page() .
add_posts_page( ) .
add_media_page() .
add_links_page( ) .
add_pages_page() .
add_comments_page() .
add_plugins_page( ) .
add_theme_page() .
add_users_page( ) .
206
8.
add_management_page( ) .
add_options_page( ) .
, ,
.
WordPress 2.7 API ,
, . API
, WordPress .
API , WordPress
.
, ,
. ,
add_menu_page( ) add_submenu_page( )
.
,
. :
<?php
//
add_action( 'adminjnenu', 'pnowp_create_menu' );
function prowp_create_menu() {
//
add_menu_page( 'Halloween Plugin Page', 'Halloween Plugin',
'manage_options', 'prowp_main_menu', 'prowp_settings_page',
plugins_url( '/images/wordpress.png',
FILE
) );
//
add_action( admin_init, 'prowp_register_settings' );
}
?>
, - adm in _in it,
pro w p_register_settings( ), :
<?php
function prowp_register_settings() {
//
register_setting( 'prowp-settings-group', 'prowp_options',
'prowp_sanitize_options' );
}?>
A P I re g is te r_ s e ttin g () , ,
.
, ,
.
. ,
.
207
, .
. ,
, . ,
p ro w p _ s e ttin g s _ p a g e ( ) :
<?php
function prowp_settings_page() {
?>
<div class="wrap">
<h2>Halloween Plugin 0ptions</h2>
form method="post" action=options.php">
<?php settings_fields( 'prowp-settings-group ); ?>
<?php $prowp_options = get_option( prowp_options' ); ?>
table class="form-table"
<tr valign="top">
<th scope="row"Name/th>
tdxinput type="text" name="prowp_options[option_name]"
value="?php echo esc_attr( $prowp_options['option_name'] ); ?>" />
</td>
</tr>
<tr valign="top">
<th scope="row">Email/th>
tdxinput type="text" name="prowp_options[option_email]"
value="?php echo esc_attr( $prowp_options['option_email'] ); ?>'*
/></td>
</tr>
<tr valign="top"
<th scope^'row'^URK/th
tdxinput type="text" name="prowp_options[option_url]"
value="<?php echo esc_url( $prowp_options['option_url'] ); ?>" />
</td>
</tr>
/table
<p class="submit">
input type="submit" class="button-primary"
value="Save Changes" />
</p>
/form
</div>
<?php
>
?>
, .
form , o p t io n s .p h p .
, prowps e ttin g s -g r o u p .
. :
<?php settings_fields( 'prowp-settings-group' ); ?>
, ,
$ p ro w p_ o p tio ns g e t _ o p t io n ( ) .
, , .
208
8.
.
, option_name [ f ield_name],
.
input type="text" name="prowp_options[option_email]"
value="?php echo esc_attr( $prowp_options['option_email'] ); ?>" />
,
(Submit) .
p ro w p _ sa n itize _ o p tio n s( ).
, ,
. ,
.
<?php
function prowp_sanitize_options( {input ) {
{input['option_name'] = sanitize_text_field( {input['option_name'] );
{input['option_email'] = sanitize_email( {input['option_email'] );
{input['option_unl'] = esc_url( {input['option_url'] );
return {input;
}
?>
,
. WordPress s a n it iz e _ t e x t _ fie ld ( ),
HTML, XML .
W ordPress s a n itiz e _ e m a il( )
, a e s c _ u r l( ) URL.
! ,
API WordPress. 8.1
.
8.1. (prowp2-settings-api-plugin.zip)
<?php
//
add_action( 'admin_menu', prowp_create_menu' );
function prowp_create_menu() {
//
add_menu_page( 'Halloween Plugin Page', 'Halloween Plugin',
'manage_options', 'prowp_main_menu', 'prowp_settings_page,
plugins_url( /images/wordpress.png',
FILE
) );
//
add_action( 'admin_init', 'prowp_register_settings' );
>
function prowp_register_settings() {
//
register_setting( 'prowp-settings-group',
209
'prowp_options', 'prowp_sanitize_options' );
>
function pnowp_sanitize_options( {input ) {
{input['option_name'] =
sanitize_text_field( {input[option_name'] );
{input['option_email'] = sanitize_email( {input['option_email'] );
{input['option_url'] = esc_url( {input['option_url'] );
return {input;
>
function prowp_settings_page() {
?>
<div class="wrap">
<h2>Halloween Plugin 0ptions</h2>
<form method="post" action="options.php">
<?php settings_fields( 'prowp-settings-group' ); ?>
<?php {prowp_options = get_option( 'prowp_options' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Name</th>
<tdxinput type="text" name="prowp_options[option_name]"
value="<?php echo esc_attr( {prowp_options['option_name'] );?>
" /x/td>
</tr>
<tr valign="top">
<th scope="row">Email</th>
<tdxinput type="text" name="prowp_options[option_email]*
value="<?php echo esc_attr( {prowp_options['option_email'] ); ?>
" /x/td>
</tr>
<tr valign="top">
<th scope="row">URL</th>
<tdxinput type="text" name="prowp_options[option_url]"
value="<?php echo esc_url( {prowp_options['option_url'] ); ?>" />
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class=button-primary"
value="Save Changes" />
</p>
</form>
</div>
<?php
>
?>
WordPress, . 8.4.
API WordPress,
.
.
. .
210
8.
Iff]
RSS -
.( )
;10
::
(^
-
10
(-)
{*.'
t
Halloween
Halloween?
..... .!
.
'
. 8.4.
<?php
//
add_action( 'admin_init', 'prowp_settings_init' );
function prowp_settings_init() {
// >
add_settings_section( 'prowp_setting_section', 'Halloween Plugin Settings',
'prowp_setting_section', 'reading' );
//
add_settings_field( 'prowp_setting_enable_id', 'Enable Halloween Feature?',
'prowp_setting_enabled', 'reading', 'prowp_setting_section' );
add_settings_field( 'prowp_saved_setting_name_id', Your Name',
'prowp_setting_name'i 'reading', 'prowp_setting_section );
//
register_setting( 'reading', 'prowp_setting_values' );
}
?>
- a d m in _ in it
p r o w p _ s e t t in g s _ in it () .
a d d _ s e t t in g s _ s e c t io n ( ) :
<?php
add_settings_section( 'prowp_setting_section', 'Halloween Plugin Settings',
'prowp_setting_section', 'reading' );
?>
211
ID .
, .
.
. WordPress,
: general, w ritin g , reading, discussion, media, privacy
permalink.
<?php
//
add_settings_field( 'prowp_setting_enable_id', 'Enable Halloween Feature?',
prowp_setting_enabled', 'reading', 'prowp_setting_section' );
add_settings_field( 'prowp_saved_setting_name_id', 'YourName',
'prowp_setting_name', 'reading', 'prowp_setting_section );
?>
, ,
. ,
add_settings_f ie ld ( ). ID .
, .
,
. ,
. ,
, prowp_setting_section,
add_setting_section().
<?php
register_setting( 'reading', 'prowp_setting_values', 'prowp_sanitize_settings' );
?>
.
: / -
. ,
,
prowp_setting_values.
.
.
. .
.
, .
p ro w p _ sa n itize_ settin g s()
, .
<?php
function prowp_sanitize_settings( $input ) {
$input['enabled'] = ( $input['enabled'] == 'on' ) ? 'on' :
$input['name'] = sanitize_text_field( $input['name'] );
return $input;
>
?>
212
8.
, ,
. -
; .
Enabled ()
PH . - , ,
.
, , -
. , ,
. prowp_setting_
sectionQ , :
<?php
function prowp_setting_section() {
. echo <p>Configure the Halloween plugin options below</p>';
}
?>
.
, . .
:
<?php
function prowp_setting_enabled() {
//
$prowp_options = get_option( 'prowp_setting_values' );
//
echo '<input '.checked( $prowp_options['enabled'], 'on', false ).'
name="pnowp_setting_values[enabled]" type="checkbox" /> Enabled';
}
?>
,
a d d _ settin g s_ field (). ,
. -,
, .
WordPress checked(). .
. ,
checked="checked", .
, .
,
false.
,
. ,
. ,
. prowp_setting_
values [enabled]. API ,
. -
.
:
213
<?php
function prowp_setting_name() {
//
$prowp_options = get_option( 'prowp_setting_values' );
//
echo 'input type="text" name="prowp_setting_values[name]"
value="'.esc_attr( $prowp_options['name*]
/>';
}
?>
-
. ,
re g is te r_ s e ttin g (). ,
.
!
. 8.2 .
8.2. (prowp2-reading-settings-plugin.zip)
<?php
//
add_action( 'admin_init', 'pnowp_settings_init' );
function pnowp_settings_init() {
// >
add_settings_section( 'pnowp_setting_section',
'Halloween Plugin Settings', 'prowp_setting_section,
'reading' );
//
add_settings_field( prowp_setting_enable_id', 'Enable Halloween Feature?',
prowp_setting_enabled, 'reading', 'prowp_setting_section' );
add_settings_field( 'prowp_saved_setting_name_id', 'Your Name',
'prowp_setting_name', 'reading', 'prowp_setting_section' );
//
register_setting( 'reading', 'prowp_setting_values',
prowp_sanitize_settings' );
>
function prowp_sanitize_settings( $input ) {
$input[enabled'] = ( $input['enabled'] == 'on' ) ? 'on' :
$input['name'] = sanitize_text_field( $input['name'] );
return $input;
//
function prowp_setting_section() {
echo '<p>Configure the Halloween plugin options below/p>';
>
//
function prowp_setting_enabled() {
//
$prowp_options = get_option( 'prowp_setting_values' );
//
echo 'input '.checked( $prowp_options['enabled'], 'on', false )
.' name="prowp_setting_values[enabled]" type="checkbox" />
Enabled' ;
214
8.
//
function prowp_setting_name() {
//load the option value
$prowp_options = get_option( 'prowp_setting_values );
//display the text form field
echo input type="text" name="prowp_setting_values[name]
value="'.esc_attr( $prowp_options['name']
/>';
>
?>
WordPress
WordPress
. WordPress
, , ,
, .
WordPress
.
, !
, WordPress add_meta_box().
:
<?php add_meta_box( $id, $title, Jcallback, $page, $context, $priority, $callback_
args ); ?>
, .
$id ( ID CSS );
$ t i t l e ( , );
$callback (
);
$page (, , ' po s t ' ,
' page' );
$context ( , ,
normal, 'advanced' 'side');
$priority (
high', 'core', 'default' 'low');
$callback_args ( ).
, add_meta_box(),
WordPress:
WordPress
215
<?php
add_action( 'add_meta_boxes, 'prowp_meta_box_init' );
//
function prowp_meta_box_init() {
//
add_meta_box( 'prowp-meta', 'Product Information',
'prowp_meta_box', 'post', 'side', 'default' );
>
?>
add_meta_boxes prowp_meta_
box_init(). add_meta_box()
.
, .
: 4
: *
. 8.5.
ID CSS prowp-meta . ,
.
prowp_meta_box(), HTML .
. ,
default. prowp_
meta_box() :
function prowp_meta_box( {post, {box ) {
//
{prowp_featured = get_post_meta( {post->ID, '_prowp_type', true );
{prowp_price = get_post_meta( {post->ID, '_prowp_price', true );
//
wp_nonce_field( plugin_basename(
FILE
), 'prowp_save_foeta_box' );
//
echo '<p>Price: <input type="text" name="prowp_price"
value="'.esc_attr( {prowp_price ).'" size="5" /></p>;
216
8.
echo '<p>Type:
select name="prowp_product_type" id="prowp_product_type">
option value="0" '
.selected( $prowp_featured, 'normal', false ). 'Normal
/option
option value="special"
.selected( $prowp_featured, 'special', false ). 'Special
/option
option value="featured" '
.selected( $prowp_featured, 'featured', false ). Featured
/option
option value="clearance" '
.selected( $prowp_featured, 'clearance', false ). Clearance
/option
</selectx/p>';
>
. ,
. .
, form .
, wp_nonce_f i e l d ( )
.
,
. 8.5.
, ,
. , prowp_
save_meta_box(), - save_post:
< ?php
//
add_action( 'save_post', 'prowp_save_meta_box' );
function prowp_save_meta_box( $post_id ) {
// , $_POST
if( isset( $_POST['prowp_product_type'] ) ) {
// ,
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
//
check_admin_referer( plugin_basename(
FILE
), 'prowp_save_meta_box' );
// , ID
update_post_meta( $post_id, _prowp_type',
sanitize_text_field( $_POST['prowp_product_type'] ) );
update_post_meta( $post_id, '_prowp_price',
sanitize_text_field ( $_POST['prowp_price'] ) );
}
}
?>
WordPress
217
- save_post WordPress.
,
, $_POST[ ' prowp_product_type ' ].
, , .
, , ,
, . ,
. ,
, .
update_post_meta() .
, update_post_m eta( ) ID.
WordPress ,
. . ,
.
. UI
, .
, WordPress
s a n itiz e _ te x t_ fie ld ().
,
. 8.3
.
8.3. (prowp2-custom-meta-box.zip)
<?php
add_action( 'add_meta_boxes', 'prowp_meta_box_init' );
//
function prowp_meta_box_init() {
//
add_meta_box( 'prowp-meta', 'Product Information',
'prowp_meta_box', 'post', 'side', 'default' );
>
218
8.
coption value="specialM *
.selected( $prowp_featured, 'special', false )
. '>Special</option>
coption value="featured" '
.selected( $prowp_featured, 'featured', false )
. '>Featuredc/option>
coption value="clearance"
.selected( $prowp_featured, clearance', false )
. '>Clearancec/option>
c/select>c/p>';
>
//
add_action( save_post', 'prowp_save_meta_box' );
function prowp_save_meta_box( $post_id ) {
// , $_POST
if( lsset( $_POST['prowp_product_type'] ) ) {
// ,
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
//
check_admin_referer(
plugin_basename(
FILE
), 'prowp_save_meta_box' );
// , ID
update_post_meta( $post_id, '_prowp_type',
sanitize_text_field( $_POST['prowp_product_type'] ) );
update_post_meta( $post_id, '_prowp_price',
sanitize_text_field( $_POST['prowp_price'] ) );
}
}
?>
, , , , . ,
get_post_meta Loop:
c?php
$prowp_type = get_post_meta( $post->ID, _prowp_type', true );
$prowp_price = get_post_meta( $post->ID, _prowp_price', true );
echo 'cp>Price: .esc_html( $prowp_price ). c/p>;
echo 'cp>Type: ' ,esc_html( $prowp_type ). 'c/p>;
?>
, .
WordPress API ,
. ,
WordPress
219
, , ,
.
- .
API :
<?php
add_shortcode( 'mytwitter', prowp_twitter' );
function prowp_twitter() {
return '<a href = "http://twitter.com/williamsba">(3willianisba</a>';
>
?>
[ m y tw itte r]
HTML Twitter
. , WordPress,
,
JavaScript .
.
,
.
, :
<?php
add_shortcode( 'mytwitter', 'prowp_twitter' );
function prowp_twitter( $atts, $content = null ) {
extract( shortcode_atts( array(
'person' => 'brad' // set attribute default
), $atts ) );
if ( $person == 'brad' ) {
return '<a href="http://twitter.com/williamsba">@williamsba</a>';
}elseif ( $person == 'david' ) {
return '<a href="http://twitter.com/mirmillo">@mirmillo</a>';
}elseif ( $person == 'hal' ) {
return '<a href="http://twitter.com/freeholdhal">@freeholdhal</a>;
}
>
?>
, ,
person. ,
Twitter. URL Twitter
[m y tw itte r p erson = "d avid " ] .
URL Twitter URL : [m y tw itte r p e rs o n = "h a l"].
,
.
,
WordPress. ,
220
8.
.
, , WP_Widget
WordPress.
, , :
<?php
class My_Widget extends WP_Widget {
function My_Widget() {
//
function form($instance) {
//
>
}
>
?>
Bio.
WordPress.
. w idgets_init
WordPress:
add_action( 'widgets_init', 'prowp_register_widgets );
function prowp_register_widgets() {
register_widget( 'prowp_widget' );
}
- w i d g e t s _ i n i t p r o w p _ r e g is t e r _
.
p ro _ w id g e t.
.
w id g e t s ( ),
,
. (constructor):
function prowp_widget() {
$widget_ops = array(
WordPress
221
'classname'
=> 'prowp_widget_class',
'description' => 'Example widget that displays a user\'s bio.'-);
$this->WP_Widget( 'prowp_widget', 'Bio Widget', $widget_ops );
}
prow p_w idget () .
CSS, HTML,
. CSS <div>,
<aside>, < li> - HTML-. .
.
WP_Widget. ID CSS (p ro w p _ w id g e t_ c la s s )
(Bio Widget).
.
,
, .
, :
function form( {instance ) {
{defaults = array(
'title' => 'My Bio',
'name' => 'Michael Myers',
'bio'
=> ' );
{instance = wp_parse_args( (array) {instance, {defaults );
{title = {instance['title'];
{name = {instance['name'];
{bio = {instance['bio'];
?>
<p>Title:
<input class="widefat"
name="<?php echo {this->get_field_name( 'title' ); ?>"
type="text" value="<?php echo esc_attr( {title ); ?>" /></p>
<p>Name:
<input class="widefat"
name="<?php echo {this->get_field_name( 'name' ); ?>"
type="text" value="<?php echo esc_attr( {name ); ?>" /></p>
<p>Bio:
<textarea class="widefat"
name="<?php echo {this->get_field_name( 'bio' ); ?>" >
<?php echo esc_textarea( {bio ); ?></textareax/p>
<?php
}
, , .
, ,
.
My Bio, (Michael Myers).
, .
, ,
. , :
, .
, (bio) . ,
222
8.
<form> ; .
, e s c _ a t t r ( ) e s c _ t e x t a r e a ( )
. ,
u p d a te ():
function update( $new_instance, $old_instance ) {
{instance * $old_instance;
$instance['title'] - sanitize_text_field( $new_instance['title'] );
{instancef'name'] sanitize_text_field( $new_instance['name'] );
$instance['bio'] = sanitize_text_field( $new_instance['bio'] );
return {instance;
>
. , ,
. $ n e w _ in sta n ce
. s a n it iz e _ t e x t _ f i e l d () HTML, . HTML,
w p _ kse s(), ,
.
prow p_w idget :
function widget( {args, {instance ) {
extract( $args );
echo {before_widget;
{title = apply_fiIters( 'widget_title, {instance['title'] );
{name = ( empty( $instance['name'] )) ? ' : {instance['name'];
{bio = ( empty( {instance['bio'] ) ) ?
'Snbsp;':{instance['bio'];
if ( !empty( {title ) ) { echo {before_title . esc_html( {title )
. {after_title; };
echo '<p>Name: . esc_html( {name ) .
'</p> *;
echo '<p>Bio: . esc_html( {bio ) .'</p>';
echo {after_widget;
>
, , { a rg s .
, { b e fo re _ w id g e t { a ft e r _ w id g e t .
, , < div> .
{ a r g s { b e f o r e _ w id g e t .
{ b e f o r e _ t i t l e { a f t e r _ t i t l e .
HTML
.
.
{ b e f o r e _ t it le { a f t e r _ t it l e . .
.
, { a fte r _ w id g e t.
! ,
WordPress. , , ,
WordPress
2 23
. 8.4
.
8.4. (prowp2-custom-widget.zip)
<?php
// widgets_init,
add_action( 'widgets_init', 'prowp_register_widgets );
//
function prowp_register_widgets() {
register_widget( 'prowp_widget' );
//prowpwidget class
class prowp_widget extends WP_Widget {
//
function prowp_widget() {
$widget_ops = array(
'classname'
=> 'prowp_widget_class',
'description' => 'Example widget that
displays a user\'s bio. );
$this->WP_Widget( 'prowp_widget, 'Bio Widget',
$widget_ops );
//
function form( $instance ) {
{defaults = array(
'title' => 'My Bio',
'name' => 'Michael Myers',
'bio'
=> " );
{instance = wp_parse_args( (array) {instance, {defaults );
{title = $instance['title'];
{name = {instancef'name'];
{bio = {instance['bio'];
?>
<p>Title:
input class="widefat" name="?php
echo {this->get_field_name( 'title' );
?>" type="text"
value="?php echo esc_attr( {title ); ?>" /></p>
<p>Name:
input class="widefat" name="?php
echo {this->get_field_name( 'name' );
?>" type="text"
value="?php echo esc_attr( {name ); ?>" /></p>
<p>Bio:
textarea class="widefat"
name="?php echo {this->get_field_name( 'bio' ); ?>"
><?php echo esc_textarea( {bio ); ?x/textareax/p>
<?php
>
//
224
8.
>
//
function widget( {args, {instance ) {
extract( {args );
echo {before_widget;
{title * apply_fliters( 'widget_title', {instance['title'] );
{name = ( empty(
$instance['name']) )
? ' ' : {instance[name];
$bio = ( empty( {instance['bio'] ) )
? ' : $instance['bio'];
if ( !empty( {title ) ) { echo {before_title
. esc_html( {title ) . {after_title; };
echo '<p>Name: ' . esc_html( {name) . '</p>';
echo '<p>Bio: . esc_html( {bio ) . '</p>';
echo {after_widget;
}
}
?>
WordPress 2.7 (Dashboard Widgets),
, WordPress.
.
, wp_add_
dashboard_widget() :
<?php
add_action( 'wp_dashboard_setup', 'prowp_add_dashboard_widget' );
//
function prowp_add_dashboard_widget() {
wp_add_dashboard_widget( 'prowp_dashboard_widget',
'Pro WP Dashboard Widget', 'prowp_create_dashboard_widget' );
>
//
function prowp_create_dashboard_widget() {
echo '<p>Hello World! This is my Dashboard Widget</p>;
>
?>
WordPress
22 5
- wp_dashboard_setup
.
.
wp_add_dashboard_widget() .
ID . CSS
. .
.
.
, .
wp_add_dashboard_widget ()
.
. ,
. 8.6.
Pro WP
. )
. 8.6.
W ordPress .
. , , ,
, ,
,
SQL, ,
.
. ,
.
<?php
register_activation_hook(
function prowp_install() {
FILE
, 'prowp_install' );
}
?>
, ,
. ,
wp-config. php, , 10, WordPress Multisite
226
8.
,
.
, $ w p d b - p re fix:
global $wpdb;
//
$table_name = $wpdb->prefix .'pnowp_data;
wp_prowp_data $table_nam e,
WordPress wp_.
SQL- .
$sql .
u p g ra d e . php , :
$sql = "CREATE TABLE " .$table_name ." (
id mediumint(9) NOT NULL AUTO_INCREMENT,
time bigint(ll) DEFAULT *0' NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
url VARCHAR(55) NOT NULL,
UNIQUE KEY id (id)
);";
require_once( ABSPATH . wp-admin/includes/upgrade.php )j
//
dbDelta( $sql );
.
() , ,
.
.
.
,
, , :
d b D e lta
$prowp_db_version = '1.0';
add_option( 'prowp_db_version', $prowp_db_version );
:
register_activation_hook(
function prowp_install() {
global $wpdb;
FILE
, 'prowp_install' );
//
$table_name = $wpdb-prefix .'prowp_data';
//
$sql = "CREATE TABLE " .$table_name
(
id mediumint(9) NOT NULL AUTO_INCREMENT,
time bigint(ll) DEFAULT 0' NOT NULL,
name tinytext NOT NULL,
text text NOT NULL,
url VARCHAR(55) NOT NULL,
UNIQUE KEY id (id)
WordPress
227
>
,
:
$installed_ver = get_option( 'gmp_db_version' );
if( $installed_ver != $prowp_db_version ) {
//
//
update_option( 'gmp_db_version', $prowp_db_version );
}
,
. ,
. ,
WordPress, API .
wp_*meta , ,
.
.
,
WordPress, 6.
. W ordPress
: u n in s t a ll. p h p -. ,
WordPress.
, , u n in s t a ll. p h p .
.
u n i n s t a l l . php.
. .
<?php
// uninstall/delete WordPress,
if( !defined( ABSPATH' ) && !defined( 'WP_UNINSTALL_PLUGIN' ) )
exit();
//
delete_option( 'prowp_options_arr' );
// ,
228
8.
, u n i n s t a l l . php,
WP_UNINSTALL_PLUGIN, WordPress.
, , ,
.
, .
.
d e le t e _
o p t io n Q . ,
.
ABSPATH
-.
u n i n s t a l l , php , -
, . :
<?php
register_uninstall_hook(
FILE , 'prowp_uninstall_hook );
function prowp_uninstall_hook() {
delete_option( 1prowp_options_arr' );
//
>
?>
.
, ,
,
.
r e g is t e r _ d e a c t iv a t io n _ h o o k , n e g is t e r _
. r e g is t e r _
d e a c tiv a tio n _ h o o k , ,
- .
,
.
u n in s t a ll_ h o o k
, , WordPress
, .
, ,
. .
, ,
(Halloween Store).
WordPress Halloween Store.
:
229
API ;
Widget;
;
;
.
.
: halloween-store, php u n in s ta ll. php. ,
, halloweenstore. .
halloween-store.php.
:
<?php
/*
Plugin Name: Halloween Store
Plugin URI: http://webdevstudios.com/support/wordpress-plugins/
Description: Halloween Store
Version: 1.0
Author: Brad Williams
Author URI: http://webdevstudios.com
License: GPLv2
*/
/*
USA
*/
, .
, GPL
.
re g is te r_ a c tiv a tio n _ h o o k ()
. , ,
WordPress.
// ,
register_activation_hook(
FILE , 'halloween_store_install' );
function halloween_store_install() {
// no
230
8.
{hween_options_arr = (
'currency_sign' => '$
);
//
update_option( 'halloween_options, $hween_options_arr );
>
,
halloween_options. ,
currency_sign $.
i n i t
Products. Halloween Store
.
// -
add_action( 'init', 'halloween_store_init' );
// Halloween Store
function halloween_store_init() {
//register the products custom post type
{labels = array(
'name' => __( 'Products', 'halloween-plugin' ),
'singular_name' = > ( 'Product', 'halloween-plugin' ),
add_new' =>
( 'Add New', 'halloween-plugin' ),
'add_new_item' =>
( 'Add New Product',
'halloween-plugin' ),
edit_item = > __( 'Edit Product', 'halloween-plugin' ),
new_item' => __( 'New Product', 'halloween-plugin' ),
'all_items' = > ( 'All Products', 'halloween-plugin' ),
'view_item' =>
( 'View Product, 'halloween-plugin' ),
search_items' =>
( 'Search Products',
'halloween-plugin' ),
'not_found' =>
( 'No products found',
'halloween-plugin' ),
'not_found_in_trash' => __( 'No products found in Trash',
'halloween-plugin' ),
'menu_name' => __( 'Products', 'halloween-plugin' )
);
{args = array(
'labels => {labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' )
);
register_post_type( 'halloween-products', {args );
>
,
().
231
.
.
Halloween Store.
, add_
options_page():
// -,
add_action( 'admin_menu', 'halloween_store_menu' );
// Halloween Masks
function halloween_store_menu() {
add_options_page(
( 'Halloween Store Settings Page',
'halloween-plugin' ), __( 'Halloween Store Settings',
'halloween-plugin' ), 'manage_options', 'halloween-store-settings',
'halloween_store_settings_page' );
>
, . Halloween Store
Interface.
, .
.
, Halloween Store
hallow een_store_settings_page().
//
function halloween_store_settings_page() {
//
$hween_options_arr = get_option( 'halloween_options' );
//
$hs_inventory = ( ! empty( $hween_options_arr['show_inventory'] ) ) ?
$hween_options_arr['show_inventory'] : ';
$hs_currency_sign = $hween_options_arr['currency_sign'];
?>
<div class="wrap">
<h2x?php _e( 'Halloween Store Options', 'halloween-plugin' ) ?x/h2>
form method="post" action="options.php">
<?php settings_fields( 'halloween-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"x?php _e( 'Show Product Inventory',
'halloween-plugin' ) ?x/th>
tdxinput type="checkbox" name="halloween_options[show_inventory]"
<?php echo checked( $hs_inventory, 'on' ); ?> /x/td>
</tr>
<tr valign="top">
<th scope="row"x?php _e( 'Currency Sign', 'halloween-plugin' ) ?x/th>
tdxinput type="text" name="halloween_options[currency_sign]"
value="<?php echo esc_attr( $hs_currency_sign ); ?>"
size="l" maxlength="l" /x/td>
</tr>
</table>
<p class="submit">
232
8.
}
Halloween Store , ,
.
. .
Inventory. .
.
, s e t t in g s _ f i e l d s ()
, .
API .
WordPress API
. ,
:
// -,
add_action( 'admin_init', 'halloween_store_register_settings' );
function halloween_store_register_settings() {
//
register_setting( 'halloween-settings-group',
'halloween_options', 'halloween_sanitize_options' );
}
function halloween_sanitize_options( {options ) {
{options['show_inventory'] = ( ! empty( {options['show_inventory'] ) ) ?
sanitize_text_field( {options['show_inventory'] ) :
{options['currency_sign'] = ( ! empty( {options['currency_sign'] ) ) ?
sanitize_text_field( {options['currency_sign'] ) : '';
return {options;
>
r e g i s t e r _ s e t t i n g ( ), ,
h a llo w e e n -s e ttin g s -g ro u p , , h a llo w e e n -o p tio n s ,
. h a llo w e e n _ s a n itiz e _ o p tio n s ( )
WordPress. : ,
.
, ,
:
// -,
add_action( 'add_meta_boxes', halloween_store_register_meta_box' );
function halloween_store_register_meta_box() {
23 3
//
add_meta_box( 'halloween-product-meta',
( 'Product Information','halloween-plugin ),
'halloween_meta_box', 'halloween-products', 'side', 'default' );
}
- add_m eta_boxes,
. add_m eta_box( )
. , ,
:
//
function halloween_meta_box( {post ) {
//
{hween_sku = get_post_meta( {post->ID, '_halloween_pnoduct_sku', true );
{hween_price = get_post_meta( {post->ID, '_halloween_product_price', true );
{hween_weight = get_post_meta( {post->ID, '_halloween_product_weight', true );
{hween_color = get_post_meta( {post->ID, _halloween_product_color', true );
{hween_inventory = get_post_meta( {post->ID, '_halloween_product_inventory',
true );
//
wp_nonce_field( 'meta-box-save', 'halloween-plugin' );
//
echo 'table';
echo '<tr>';
echo '<td>' .__('Sku', 'halloween-plugin').':</td>
tdxinput type="text" name="halloween_product_sku"
value="'.esc_attr( {hween_sku ).'" size="10"x/td';
echo '/tr.xtr';
echo '<td>' . ('Price', 'halloween-plugin').':</td>
tdxinput type="text" name="halloween_product_price"
value=".esc_attr( {hween_price ).'" size="5"x/td>';
echo '/trxtr;
echo '<td>' . ('Weight', 'halloween-plugin').':</td>
tdxinput type="text" name="halloween_product_weight"
value="'.esc_attr( {hween_weight )." size="5"x/td>';
echo '/trxtr';
echo '<td>' . ('Color', 'halloween-plugin').:</td>
tdxinput type="text" name="halloween_product_color"
value="' .esc_attr( {hween_color ).'" size="5"x/td>';
echo '/trxtr;
echo '<td>Inventory:/td>
<tdxselect name="halloween_product_inventory"
id="halloween_product_inventory">
option value="In Stock"'
.selected( {hween_inventory, 'In Stock', false ). >'
.__( 'In Stock', 'halloween-plugin' ). '</option>
option value="Backordered"
.selected( {hween_inventory, 'Backordered', false ). '>'
.__( 'Backordered', 'halloween-plugin' ). '/option
option value="Out of Stock"'
,selected( {hween_inventory, 'Out of Stock', false ). ''
._( 'Out of Stock', 'halloween-plugin' ). '/option
option value="Discontinued"'
.selected( {hween_inventory, 'Discontinued', false ). ''
234
8.
>
Halloween Store :
, , , . ,
.
, .
, ,
.
, . 8.7.
: :
| :
]
!
in Stock
* j
1 : (hs show=sku]
:
(hs show=prtceJ
(hs show=weightl
(hs show=color)
: (hs show^inventory)
. 8.7.
, ,
:
// - ,
add_action( 'save_post','halloween_store_save_meta_box' );
//
function halloween_store_save_meta_box( $post_id ) {
235
// , Halloween Products
//
if ( get_post_type( $post_id ) == 'halloween-products'
&& isset( $_POST['halloween_product_sku'] ) ) {
// ,
if ( defined( 'DOING_AUTOSAVE ) && DOING_AUTOSAVE )
return;
//
check_admin_referer( 'meta-box-save', 'halloween-plugin' );
//
update_post_meta( $post_id, '_halloween_product_sku',
sanitize_text_field( $_POST['halloween_product_sku'] ) );
update_post_meta( $post_id, '_halloween_product_price',
sanitize_text_field( $_POST['halloween_product_price'] ) );
update_post_meta( $post_id, '_halloween_product_weight',
sanitize_text_field( $_POST['halloween_product_weight'] ) );
update_post_meta( $post_id, '_halloween_product_color,
sanitize_text_field( $_POST['halloween_product_color'] ) );
update_post_meta( $post_id, '_halloween_product_inventory',
sanitize_text_field( $_POST['halloween_product_inventory'] ) );
}
}
,
h a llo w e e n - p ro d u c ts . ,
$_POST [' h a llo w e e n _ p ro d u ct_ s k u ' ] .
; ,
. , ,
, .
c h e c k _ a d m in _ r e fe r e r ( ).
,
.
.
.
// -,
add_shortcode( 'hs', halloween_store_shortcode' );
//
function halloween_store_shortcode( $atts, {content = null ) {
global {post;
extract( shortcode_atts( array(
"show" => ''
), {atts ) );
//
$hween_options_arr = get_option( 'halloween_options );
if ( {show == 'sku') {
{hs_show = get_post_meta( {post->ID, '_halloween_product_sku, true );
236
8.
}
//
return {hs_show;
}
, , { p o s t.
{p o st-> ID , .
,
show. , ,
, .
[h s s h o w = p ric e ] .
, .
:
// -,
add_action( 'widgets_init', 'halloween_store_register_widgets' );
//
function halloween_store_register_widgets() {
register_widget( 'hs_widget' );
}
//hs_widget class
class hs_widget extends WP_Widget {
h s _ w id g e t,
r e g is t e r _ w id g e t (). W idget hs_w idget.
, :
//
function hs_widget() {
{widget_ops = array(
'classname'
=> 'hs-widget-class',
237
}
hs_widget (), .
, :
//
function form( {instance ) {
{defaults = array(
'title'
=>
( 'Products', 'halloween-plugin' ),
'number_products => '3' );
{instance = wp_parse_args( (array) {instance, {defaults );
{title = {instance['title'];
{number_products = {instance['number_products'];
?>
<px?php _e('Title', 'halloween-plugin') ?>:
cinput class="widefat"
name="<?php echo {this->get_field_name( 'title' ); ?>"
type="text" value="<?php echo esc_attr( {title ); ?>" /x/p>
<px?php _e( 'Number of Products', 'halloween-plugin' ) ?>:
<input name="
<?php echo {this->get_field_name( 'number_products' ); ?>"
type="text" value="<?php echo esc_attr( {number_products ); ?>"
size="2" maxlength="2" />
</p>
<?php
>
, , form().
: .
,
. .
, ,
.
//
function update( {new_instance, {old_instance ) {
{instance = {old_instance;
$instance[title'] = sanitize_text_field( {new_instance['title'] );
{instance[number_products'] = absint( $new_instance['number_products'] );
return {instance;
}
update (). .
, s a n itiz e _ te x t_ fie ld ()
. a b sin t(), ,
.
238
8.
//
function widget( {args, {instance ) {
global {post;
extract( {args );
echo {before_widget;
{title = apply_filters( 'widget_title', {instance['title'] );
{number_products = {instance['number_products'];
if ( ! empty( {title ) ) { echo {before_title . esc_html( {title )
. {after_title; };
// ,
{args = array(
'postjtype'
=>
'halloween-products',
'posts_per_page'
=>
absint( {number_products )
);
{dispProducts = new WP_Query();
{dispProducts->query( {args );
while ( {dispProducts->have_posts() ) : {dispProducts->the_post();
//
{hween_options_arr = get_option( 'halloween_options' );
//
{hs_price = get_post_meta( {post->ID,
'_halloween_product_price', true );
{hs_inventory = get_post_meta( {post->ID,
'_halloween_product_inventory', true );
?>
<P>
<a href="<?php the_permalink(); ?>"
rel="bookmark"
title="<?php the_title_attribute(); ?> Product Information"
<?php the_title(); ?>
</a>
</p>
<?php
echo '<p>' . ( 'Price', 'halloween-plugin' ). ': '
.{hween_options_arr[currency_sign'] .$hs_price .'</p>';
// ,
if ( {hween_options_arr['show_inventory'] ) {
//
echo '<>' .__( 'Stock', 'halloween-plugin' ). ': '
.{hs_inventory .'</>';
echo '<hr>';
endwhile;
wp_reset_postdata();
echo {after_widget;
>
}
w id g e t ().
.
239
{arg s . {b e fo re_ w id g e t.
.
. { t i t l e , , ,
.
{p o st
, WP_
Query, 5. , ,
WP_Query, q u e r y _ p o s ts ( ) .
, :
. (p o s t_ ty p e = h a llo w e e n -p ro d u c ts )
Halloween. , posts_ p er_ p ag e , ,
. ,
.
,
. ,
. ,
.
, . 8.8.
P in h e ad
: 199.99 $
le a th e r f a c e
: 69,99 $
;
. 8.8.
?>
, , ABSPATH WP_UNINSTALL_
, WordPress
.
, .
PLUGIN.
240
8.
,
, .
! ,
, . ,
, .
8.5 .
, https://github.com/williamsba/HalloweenStore.
8.5. (halloween-store.zip)
<?php
/*
Plugin Name: Halloween Store
Plugin URI: http://webdevstudios.com/support/wordpress-plugins/
Description: Halloween Store
Version: 1.0
Author: Brad Williams
Author URI: http://webdevstudios.com
License: GPLv2
*/
/*
*/
// ,
register_activation_hook(
FILE , 'halloween_store_install );
function halloween_store_install() {
//
$hween_options_arr = array(
'currency_sign' =>
)J
//
update_option( 'halloween_options', $hween_options_arr );
}
// -
add_action( 'init', 'halloween_store_init' );
// Halloween Store
function halloween_store_init() {
//
{labels = (
'name' => __( 'Products', 'halloween-plugin' ),
'singular_name' => __( 'Product', 'halloween-plugin' ),
'add_new' => __( 'Add New', 'halloween-plugin' ),
'add_new_item' =>
( 'Add New Product', 'halloween-plugin' ),
edit_item' =>
( 'Edit Product', 'halloween-plugin' ),
USA
241
);
$args = array(
'labels' => {labels,
'public' => true,
'publicly_queryable' => true,
show_ui => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt' )
);
register_post_type( 'halloween-products', {args );
// -,
add_action( 'admin_menu', 'halloween_store_menu' );
// Halloween Masks
function halloween_store_menu() {
add_options_page( __( 'Halloween Store Settings Page', 'halloween-plugin' ),
( 'Halloween Store Settings', 'halloween-plugin' ),
manage_options', 'halloween-store-settings',
'halloween_store_settings_page' );
>
//
function halloween_store_settings_page() {
//
{hween_options_arr = get_option( 'halloween_options' );
//
{hs_inventory = ( ! empty( {hween_options_arr['show_inventory'] ) )
? $hween_options_arr['show_inventory'] :
{hs_currency_sign = {hween_options_arr['currency_sign'];
?>
<div class="wrap">
<h2x?php _e( 'Halloween Store Options', 'halloween-plugin' ) ?x/h2>
<form method="post" action="options.php">
<?php settings_fields( 'halloween-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row"x?php _e( 'Show Product Inventory',
242
8.
'halloween-plugin' ) ?></th>
tdxinput type="checkbox" name="halloween_options[show_inventory]"
<?php echo checked( {hs_inventory, 'on' ); ?> /x/td>
</tr>
<tr valign="top">
<th scope="row"x?php _e( 'Currency Sign', 'halloween-plugin' ) ?x/th>
tdxinput type="text" name="halloween_options[currency_sign]"
value="?php echo esc_attr( $hs_currency_sign ); ?>"
size="l" maxlength="l" /x/td>
</tr>
/table
<p class="submit"
input type="submit" class="button-primary"
value="?php _e( 'Save Changes', 'halloween-plugin' ); ?>" />
</p>
/form
</div>
<?php
}
// -,
add_action( 'admin_init', halloween_store_register_settings' );
function halloween_store_register_settings() {
//
register_setting( 'halloween-settings-group,
'halloween_options', 'halloween_sanitize_options' );
>
function halloween_sanitize_options( {options ) {
{options['show_inventory'] = ( ! empty( {options['show_inventory']
) ) ? sanitize_text_field( {options['show_inventory'] ) :
{options[currency_sign'] = ( ! empty( {options['currency_sign']
) ) ? sanitize_text_field( {options['currency_sign] ) : '';
return {options;
>
// -,
add_action( 'add_meta_boxes', 'halloween_store_register_meta_box' );
function helloween_store_register_meta_box() {
//
add_meta_box( halloween-product-meta,
( 'Product Information', 'halloween-plugin' ),
'halloween_meta_box', 'halloween-products', 'side',
'default' );
//
function halloween_meta_box( {post ) {
//
{hween_sku = get_post_meta( {post-ID, '_halloween_product_sku', true );
{hween_price = get_post_meta( {post-ID, '_halloween_product_price', true );
{hween_weight = get_post_meta( {post-ID, '_halloween_product_weight', true );
{hween_color = get_post_meta( {post-ID, _halloween_product_color', true );
24 3
244
8.
[hs show=inventory]</tdx/tr>';
echo </table>';
}
// - ,
add_action( s a v e _ p o s t 'halloween_store_save_meta_box' );
//
function halloween_store_save_meta_box( $post_id ) {
// , Halloween Products
//
if ( get_post_type( $post_id ) == 'halloween-products'
&& isset( $_POST['halloween_product_sku'] ) ) {
// ,
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
//
check_admin_referer( 'meta-box-save', 'halloween-plugin' );
//
update_post_meta( $post_id, '_halloween_product_sku',
sanitize_text_field( $_POST['halloween_product_sku'] ) );
update_post_meta( $post_id, '_halloween_product_price',
sanitize_text_field( $_POST['halloween_product_price'] ) );
update_post_meta( $post_id, '_halloween_product_weight',
sanitize_text_field( $_POST[halloween_product_weight'] ) );
update_post_meta( $post_id, '_halloween_product_color',
sanitize_text_field( $_POST['halloween_product_color'] ) );
update_post_meta( $post_id, '_halloween_product_inventory',
sanitize_text_field( $_POST['halloween_product_inventory'] ) );
>
>
// -
add_shortcode( 'hs', 'halloween_store_shortcode' );
// .
function halloween_store_shortcode( $atts, {content = null ) {
global {post;
extract( shortcode_atts( array(
"show" => ''
), {atts ) );
//
$hween_options_arr = get_option( 'halloween_options );
if ( {show == 'sku') {
{hs_show = get_post_meta( {post->ID, '_halloween_product_sku', true );
}elseif ( {show == 'price' ) {
$hs_show = $hween_options_arr['currency_sign']. get_post_meta( {post->ID,
'_halloween_product_price', true );
Jelseif ( {show == 'weight' ) {
{hs_show = get_post_meta( {post->ID, '_halloween_product_weight', true );
}elseif ( {show == 'color' ) {
245
>
//
return {hs_show;
// -,
add_action( 'widgets_init', 'halloween_store_register_widgets' );
//
function halloween_store_register_widgets() {
register_widget( 'hs_widget' );
>
//hs_widget class
class hs_widget extends WP_Widget {
//
function hs_widget() {
{widget_ops = array(
'classname'
=> hs-widget-class',
'description' =>
( 'Display Halloween Products','halloween-plugin' ) );
{this->WP_Widget( 'hs_widget', __( 'Products Widget','halloween-plugin'),
{widget_ops );
>
//
function form( {instance ) {
{defaults = array(
'title'
=>___( 'Products', 'halloween-plugin' ),
'number_products' => '3' );
{instance = wp_parse_args( (array) {instance, {defaults );
{title = $instance['title' ];
{number_products = {instance['number_products'];
?>
<px?php _e('Title ', 'halloween-plugin') ?>:
input class="widefat" name="<?php echo {this->get_field_name(
'title' ); ?>"
type="text" value="?php echo esc_attr( {title ); ?>" /x/p>
<px?php _e( 'Number of Products', 'halloween-plugin' ) ?>:
input name="?php echo {this->get_field_name(
'number_products' ); ?>"
type="text" value="?php echo esc_attr( {number_products ); ?>"
size="2" maxlength="2" />
</p>
<?php
246
8.
//
function update( {new_instance, $old_instance ) {
{instance = {old_instance;
{instance['title'] =
sanitize_text_field( {new_instance['title'] );
{instance['number_products'] =
absint( {new_instance['number_pnoducts'] );
return {instance;
//
function widget( {args, {instance ) {
global {post;
extract( {args );
echo {before_widget;
{title = apply_filters( 'widget_title', $instance['title'] );
{number_products = {instance['number_products'];
if ( I empty( {title ) ) { echo {before_title . esc_html( {title )
. {after_title; };
//
{args = array(
'post_type'
=>
'halloween-products',
'posts_per_page'
=>
absint( {number_products )
);
{dispProducts = new WP_Query();
{dispProducts->query( {args );
while ( {dispProducts->have_posts() ) : {dispProducts->the_post();
//
{hween_options_arr = get_option( 'halloween_options' );
//
{hs_price = get_post_meta( {post-ID,
'_halloween_product_price', true );
{hs_inventory = get_post_meta( {post-ID,
'_halloween_product_inventory', true );
?>
<P>
<a href="<?php the_permalink(); ?>" rel="bookmark"
title="<?php the_title_attribute(); ?> Product Information"
<?php the_title(); ?>
</a>
</p>
<?php
echo '<p>' .__( 'Price', 'halloween-plugin'
'
.{hween_options_arr['currency_sign'] ,{hs_price .'</p>';
// ,
if ( {hween_options_arr['show_inventory'] ) {
//
echo '<>' .__( 'Stock', 'halloween-plugin' )
.
' .{hs_inventory .'</>';
echo '<hr>';
247
endwhile;
wp_reset_postdata();
echo $after_widget;
>
>
! W ordPress.org
,
. ,
WordPress.org
WordPress, , ,
WordPress, .
:
GPLv2 .
.
Subversion (SVN).
(,
powered by)
.
, ,
.
WordPress.org, .
http://wordpress.org/support/register.php. WordPress.org
, .
WordPress.org. ,
Add Your Plugin ( ) http://wordpress.org/
extend/plugins/add/.
(Plugin Name).
, . ,
248
8.
URL . ,
W P Brad, URL http://
wordpress.org/extend/plugins/wp-brad/. ,
.
(Plugin Description).
. ,
, ,
. ,
.
(Plugin URL). ,
.
, . :
, .
, Send Post (
), . : Within
some vaguely defined amount of time, someone will approve your request (
-
). ,
. , , , .
Subversion.
readme.txt
:
re a d m e .tx t.
. WordPress
readme, , re a d m e .tx t.
readm e. t x t :
=== Plugin Name ===
Contributors: williamsbal, messenlehner, ericlewis, jtsternberg
Donate link:
http://example.com/donate
Tags: admin, post, images, page, widget
Requires at least: 3.0
Tested up to: 3.5
Stable tag: 1.1.0.0
License: GPLv2
Short description of the plugin with 150 chars max. No markup here.
== Description ==
This is the long description. No limit, and you can use Markdown
Additional plugin features
*
Feature 1
*
Feature 2
*
Feature 3
For support visit the [Support Forum](http://example.com/forum/ " Support Forum")
== Installation ==
249
1.1
* New f e a t u r e d e t a i l s
* Bug f i x d e t a i l s
=
1.0
* F i r s t o f f i c i a l r e le a s e
== U p g ra d e N o t ic e ==
- 1.1 * S e c u r i t y bug f i x e d
r e a d m
e .t x t
h t t p : / / w
o rd p re s s .o rg /
e x t e n d / p lu g in s / a b o u t / r e a d m e .tx t.
WordPress.org r e a d m e . t x t ,
r e a d m e . t x t
Subversion. h t t p : / / w o r d p r e s s . o r g / e x t e n d / p l u g i n s / a b o u t /
v a l i d a t o r / . r e a d m e . t x t :
=== P l u g in Name ===
C o n t r ib u t o r s : w i l l i a m s b a l , m e s s e n le h n e r , e r i c l e w i s , j t s t e r n b e r g
D o n a te l i n k : h t t p : / / e x a m p le .c o m / d o n a t e
T a g s : a d m in , p o s t , im a g e s , p a g e , w id g e t
R e q u ir e s a t l e a s t : 3 .0
T e s t e d up t o : 3 .5
S t a b le ta g : 1 . 1 . 0 . 0
L i c e n s e : . G PLv2
S h o r t d e s c r i p t i o n o f t h e p lu g in w it h 150 c h a r s max.
No m arkup h e r e .
250
8.
) , .
WordPress. Stable ()
, .
, .
, 150
- .
== Description ==
This is the long description. No limit, and you can use Markdown
Additional plugin features
*
Feature 1
*
Feature 2
*
Feature 3
For support visit the [Support Forum](http://example.com/forum/ " Support Forum")
Description () .
,
. .
, ,
. .
==
1.
2.
3.
Installation ==
Upload 'plugin-directory' to the '/wp-content/plugins/ directory
Activate the plugin through the 'Plugins SubPanel in WordPress
Place '<?php prowp_custom_function(); ?> in your theme templates
Installation () ,
. , ,
.
, .
== Frequently Asked Questions ==
= A question that someone might have =
An answer to that question.
= Does this plugin work with WordPress Multisite? =
Absolutely! This plugin has been tested and
verified to work on the most current version of WordPress Multisite
FAQ .
. :
== Screenshots ==
1. Screenshot of plugin settings page
2. Screenshot of plugin in action
Screenshots ()
. .
.
( ).
251
. ,
scre e n sh o t-l. png.
screenshot-2.png. : png, jpg, jpeg g if.
== Changelog ==
= l.l =
* New feature details
* Bug fix details
=
1.0
Changelog ( ).
, .
, . ,
, , .
, .
== Upgrade Notice ==
=l. l =
* Security bug fixed
Upgrade Notice ( ).
WordPress.
.
readme. t x t .
,
. ,
.
SVN
Subversion (SVN) .
,
SVN. TortoiseSVN Windows.
TortoiseSVN - GUI SVN. SVN
: http://subversion.apache.org/.
http://
tortoisesvn.net/downloads.html. TortoiseSVN
.
.
: \projects\w ordpress-plugins. ,
WordPress.org.
w ordpress-plugins
. ,
252
8.
. TortoiseSVN: SVN
Checkout ToirtoiseSVN. SVN Checkout, ,
. 8.9.
\
Repository
yRi of repository:
http: //plugins, svn. wordpress. org/wp-brad|
Checkout ^rectory:
......... : ...............
C:V}ects\wordperss-piugins\wp-brad
Checkout Depth
|pu|y recursive
............:.)
0 Omit externals
Revision
tJEAD revision
; Revision
OK
J I, O ncd
Show tog
I I
,|
H*
URL ,
. URL , URL ,
URL http://plugins.svn.wordpress.org/wp-brad.
Checkout , .
: \ p r o je c t s \ w o r d p r e s s - p lu g in s \
wp-brad. , Checkout Depth Lully Recursive.
, Revision HEAD Revision. , .
TortoiseSVN SVN ,
, : bran ches, ta g s tru n k .
SVN:
1. Branches. branch.
,
tru n k .
2. Tags. .
3. Trunk. .
.
, SVN,
tru n k .
re a d m e .tx t, , . ,
.
WordPress.org .
, tru n k ,
!
253
.
, SVN trunk SVN.
.
15 , .
,
trunk SVN Commit.
trunk.
, W P-Brad 1.1, ,
. TortoiseSVN
, , , .
, WordPress.org.
. ,
trunk TortoiseSVN Branch/tag
.
. URL http://piugins.svn.wordpress.org/wp-brad/
tags/1.1.0.0/. readme. t x t
1.1.0.0. ,
tagging version 1.1.0.0, Create HEAD
revision in the repository. OK,
tags 1.1.0.0 .
! , 15
. , ,
. , ,
URL Subversion, http://plugins.svn.wordpress.org/wp-brad/.
, trunk tag .
15 ,
http://www.wordpcess.org/extend/plugins/wp-brad.
readm e.txt - ,
trunk, SVN Commit!
WordPress
. WordPress,
(, ),
, .
.
, ,
WordPress.
, ,
/trunk.
254
8.
.
, ,
trunk SVN Commit.
1.2. TortoiseSVN
, ,
, , .
. ,
trunk TortoiseSVN Branch/tag.
URL http://plugins.svn.wordpress.Org/wp-brad/tags/l.2.0.0/.
1.2 . !
15 .
WordPress.org.
WordPress
.
. , ,
, , , ,
WordPress.
WordPress,
, ,
, .
,
. ,
WordPress.
WordPress,
.
, , ,
WordPress ,
, WordPress ,
9.
:
,
Twenty Eleven
, ? .
.
,
, ,
.
. ,
. ,
, , , .
, -,
.
:
?
, , ,
.
?
, , -.
. ,
256
9.
, - ,
, , ,
. .
- . ,
. , .
,
. , . .
. ,
.
. , ,
. HTML,
.
-.
,
, .
2010 WordPress
. Twenty , , , 2010-, ,
Kubrick, 2005-. 2011-
Automattic Twenty Eleven, 2012- WordPress 3.5
Twenty Twelve. ,
, .
,
,
.
W ordPress ?
. W ordPress
. ,
,
.
-:
FTP W ordPress 2.8 .
,
WordPress WordPress.org. ,
, GPL
( ).
. ,
WordPress, , ,
. , FTP.
257
FTP
, FTP,
. ,
, SFTP SCP, ,
.
, ,
.
, ,
. FTP-, -. FTP
: /example. com/wp-content/themes/.
, WordPress.
, ,
. .
WordPress 2.8. .
. ,
WordPress.
( -
) -
WordPress .
.
GPL .
.
. ,
, . ,
WordPress,
HTML, ,
CSS. ,
, .
, Microsoft Windows 7 WAMP,
, . Webroot.
,
, ,
.
WordPress
Ubuntu Linux .
FTP,
.
, ,
. :
258
9.
FTP, . ,
WordPress. . 13 WordPress
.
,
, - ,
, .
.
?
? , ,
? ,
,
-.
. , CSS JavaScript.
WordPress , CSS,
, .
, . ,
.
. ,
, . WordPress ,
, .
.
. ,
, .
, ,
, , WordPress
.
, ,
,
, .
,
, WordPress.
css
WordPress .
,
.
25 9
.
sty le .css. ,
.
: Style.css . WordPress
, ,
WordPress, .
WordPress,
.
, .
CSS. .
CSS , , ,
. CSS,
Wrox CSS,
.
, ,
JavaScript, jQuery.
, - ,
. , .
, img/, images/,
asse ts/ js / . ,
, ,
CSS.
, ,
W ordPress, b lo g in fo ( 's ty le s h e e t_
directory ' ). .
8, .
,
-
.
. .
, ,
, .
, ,
.
260
9.
. , ,
, , ? ,
, ,
? ,
, .
. ,
, . ,
.
, .
, .
. () ,
.
, , ,
. , ,
. (bare-bones)
{naked) .
, ,
. , ,
. , ,
.
, .
. ,
,
. . ,
,
,
.
.
, , ,
. .
, ,
.
, , .
,
.
, , .
: , .
, ,
261
. , ,
. (
)
.
.
, .
.
, , ,
. .
, ' . :
wordpress.org GPL, .
,
:
;
;
;
.
, ,
,
. ,
, , ,
? , .
.
CSS?
(SEO) ?
, ,
? , ,
Photoshop, ? ,
, ?
.
, . ,
, ,
,
. ,
, , . ,
- ,
, .
262
9.
.
,
. ,
. ,
.
, ,
Twenty Eleven.
Twenty Eleven, WordPress,
, . ,
, ,
.
Twenty Eleven
.
-, Twenty Eleven .
, Twenty Eleven HTML5
HTML5 Shiv. HTML5 12,
, ,
, - -
.
: Style.css
s ty le .c s s WordPress , . ,
. ,
in d e x. php, .
, WordPress ,
. , ,
, .
------------------------------------------------------------------------------ s ty le .c s s , . .
.
s ty le s .c s s
. WordPress
.
(, ):
/*
THEME NAME: MyTheme
THEME URI: http://www.mirmillo.com/mytheme/
DESCRIPTION: Theme for my new site. Based on Twenty Eleven.
VERSION: 1.0
26 3
*/
.
, . ,
.
, , ,
.
, (,
),
.
WordPress, CSS
.
: Twenty Eleven,
. .
. ,
s t y l e . c s s
. ,
, ,
. , ,
, .
,
( ).
,
.
CSS,
,
.
. CSS s t y l e , css,
,
. Twenty Eleven,
, , .
CSS .
CSS- , . , Wrox
CSS.
264
9.
: Index.php
, .
, ,
WordPress .
, , ,
.
, , ,
, , , .
,
, .
3.
index.php . WordPress
, ,
, ,
. , in d e x. php
. WordPress
, index, php.
index.php .
, .
, Twenty Eleven:
<?php if ( have_posts() ) : ?>
<?php twentyeleven_content_nav( 'nav-above' ); ?>
<?php /* */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( content', get_post_format() ); ?>
<?php endwhile; ?>
<?php twentyeleven_content_nav( 'nav-below' ); ?>
<?php else : ?>
5, WordPress.
,
.
,
HTML.
. get_template_part ( ),
WordPress 3.0. WordPress, -
in elude () re q u ire (), , WordPress.
get_tem plate_part( )
.
W ordPress P H P -
HTML. ,
get_post_form at( )
26 5
. get_post_form at( ) ,
, .
. ,
, image,
,
fa ls e .
get_tem plate_part( )
, ,
, . ,
:
<?php get_template_part( 'content', 'index' ); ?>
:
index.php
index.php .
WordPress s t y le s . css,
WordPress , , index.php .
WordPress index .
, - .
WordPress,
, , , WordPress -
.
, , , WordPress
, , , .
index , . , WordPress
, -
(. ).
266
9.
, in d e x .p h p ,
. , ,
, ,
. in d e x , php ,
.
. in d e x
,
.
: D R Y
, . WordPress s t y l e .
;
in d e x .p h p . ,
WordPress.
css
, ;
. ( !) DRY
(D on't Repeat Yourself, ) .
, .
. ,
,
. ,
.
, .
header.php
, ,
, WordPress. h e a d e r.p h p
. ,
HTML
<head> .
h e a d e r. php HTML, HTML,
,
.
, .
, HTML,
, , nameplate,
.
header.php,
WordPress.
: DRY
267
?>
header.php
.
include,
include, .
hea
der, php includes. ,
,
.
,
.
---------------------------------------------------------------------- ------- -,
,
. ,
.
( ),
index.php, , ,
.
, ,
, 100-
, 10 000- .
- , , () ,
. , :
, , .
268
9.
footer.php
header.php,
. .
,
, .
, Twenty Eleven,
.
. , ,
,
.
, wp_foot ( ) .
W ordPress
, ,
</bodyx/htm l>.
, W ordPress
. :
<?php
get_footer()
?>
sidebar.php
, ,
. ,
,
.
Twenty Eleven ,
sidebar.php CSS.
.
.
, ,
, . , ,
HTML, CSS
. .
-.
, Twenty Eleven
, , , .
WordPress .
: DRY
269
,
s id e b a r. php:
<?php get_sidebar(); ?>
, , CSS. .
,
. :
<?php
get_sidebar('right');
?>
s id e b a r-rig h t. php, ,
. get_tem plate_part (),
.
,
,
.
, .
, W ordPress
.
, ,
, -
. ,
. , PH P - ,
WordPress . .
:
-. .
, , ,
,
.
, , header.php,
.
,
.
CSS body.
(. ), .
270
9.
,
.
: . W ordPress
,
, . W ordPress
,
, , .
, ,
,
.
, hea
der . php :
header id="branding" role="banner">
<hgroup>
<hl id="site-title"xspan>a
href="?php echo esc_url( home_url( '/' ) ); ?>"
title="?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>"
rel="home"x?php bloginfo( 'name' ); ?x/ax/span>
</hl>
<?php
if (is_category('Ponies)) { ?>
// 'Ponies',
<img id="raibow"
src="<?php bloginfo('template_directory');?>/img/rainbow.png"
alt="0MG! Ponies! " />
<?php } ?>
<h2 id="site-description"x?php bloginfo( 'description' ); ?x/h2>
</hgroup>
/header
,
<>, rainbow.png. -
PNG .
, .
:
. ,
.
. WordPress
, . ,
. ,
. .
271
:
front-page.php
- ?
1990-, ?
, URL. Apache ,
index- , index,
Microsoft IIS default. WordPress front page,
.
index.php, ,
, . , ,
, , , ?
index.php, ,
.
.
WordPress, ,
.
HTML,
.
front-page.php.
,
: front-page.php home.php.
home. php.
WordPress 3.0 front-page. php
. ,
, .
,
.
, ,
, .
.
:
.
-.
.
, .
.
. 9.1,
, -.
272
9.
.
.
j Query.
JavaScript toolkit
Adobe Flash, jQ uery W ordPress , , .
?
.
, .
.
.
,
, . ,
,
, , , ,
. W ordPress
.
(showcase loop), -
{slideshows), (
, 7):
<div id="showcase">
< ?php
global {post;
{args = array(
'post_type' =>'slides'j
'numberposts' => -1,
'orderby' => 'rand'
);
$slider_posts = get_posts({args);
// ,
if($slider_posts) {
foreach($slider_posts as {post) : setup_postdata({post);
//
{thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(),
'home-slide');
if ({thumbnail[l] == "600" && {thumbnail[2] == "160") {
// css ?>
<div id="feature-<?php echo $post->ID; ?>" class="slide">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
<img src="<?php echo {thumbnail[0]; ?>" title="<?php the_title(); ?>" />
</a>
</div>
<?php } ?>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php } ?>
</div>
HTML, . 9.1.
273
, .
<div> ID showcase. jQ uery
. .
, ,
fu n c t io n s .p h p , WordPress.
. <div>,
ID, - jQ uery CSS.
WordPress
.
, .
.
, : 600
160 . , jQuery,
-.
,
in d e x .p h p . Twenty Eleven
,
.
. WordPress 2.1,
, ,
,
.
, .
. : ,
,
.
: archive.php
,
. , , :
... ,
,
. ,
, -,
. ,
.
a r c h iv e .php.
. - WordPress,
.
274
9.
WordPress
,- W M P lW
Professional
D c s u jn a n d D e v e lo p m e n t
fo*r4(0
book
(1IfoM
r
FM
M
4A.to*,7012
tlovePVfetf664t
W o rd P ro
rnaVet making
WObtfbT#**?*V/
**.**? O M M fA ft
M f W o rd P ro t t o *
. 9.1.
, WordPress index
. Twenty Eleven a rc h iv e . php,
, Sandbox.
, .
arch ive, php Twenty Eleven:
<hl class="page-title">
<?php if ( is_day() ) : ?>
<?php printf( __( Daily Archives: %s', twentyeleven1 ), <span>' .
get_the_date() . '</span>' ); ?>
<?php elseif ( is_month() ) : ?>
<?php printf( __( 'Monthly Archives: %s', 'twentyeleven' ), '<span>' .
get_the_date( _x( 'F Y', 'monthly archives date format',
'twentyeleven' ) ) . '</span>' ); ?>
<?php elseif ( is_year() ) : ?>
<?php printf( __( 'Yearly Archives: %s', 'twentyeleven' ),
'<span>' . get_the_date( _x( 'Y', 'yearly archives date format',
'twentyeleven' ) ) . '</span>' ); ?>
<?php else : ?>
<?php _e( 'Blog Archives', 'twentyeleven' ); ?>
<?php endif; ?>
</hl>
,
, ,
.
275
, Twenty Eleven ,
.
.
, 2007-? ,
.
: category.php
. category.php
. ,
URL . : http://example.com/
category/zombies. category.php W ordPress ,
,
,
.
,
. Twenty Eleven. , Twenty Eleven
, ,
:
header class="page-header">
<hl class="page-title"x?php
printf(
( Category Archives: %s ' , 'twentyeleven' ), 'span' .
single_cat_title( " , false ) . '/span );
?
</hl>
<?php
$category_description = category_description( ) ;
if ( ! empty( $category_description ) )
echo apply_filters( 'category_archive_meta',
'div class="category-archive-meta"> . $category_description . '/div'
);
/header
,
, . , ,
, ?
,
Zombie. ,
. WordPress
, , URL.
: WordPress ,
. W ordPress ,
, ,
,
index.php. ,
.
276
9.
, , category- 3. php,
Zombies ID 3.
ID
, . 9.2.
,
. ,
, ID.
{}
1<I
* :
;
,
.
* ,
,
&
* I '
^
|
\ )
, , .
, *,
-.
.
.
6
,
.
i
texta9erKy.iu/vvp-adrnIn/edit-t3gs.pN3?adtona ecllt&tdxonom y^cafa^ofy&iag_ID^6&post-type^post
3 5
. 9.2. ID
, . WordPress 2.9
, .
WordPress ID.
, ,
zombies. ,
category-zombies.php .
,
, .
277
: WordPress , ,
, .
.
, , WordPress
- .
, ,
, , CSS,
CSS.
. , WordPress
, - .
: tag.php
ta g .php , category.php.
, . ,
. ,
,
,
- .
, ,
.
.
, 5.
.
, ID .
Zombies, ,
tag -zom b ies. php.
.
, , WordPress
.
WordPress.
, ,
,
-. .
.
,
, .
. ,
,
?
278
9.
WordPress
. , ,
.
,
.
,
, ,
.
.
a r c h iv e - s t ic / e s .p h p , sLides .
, ,
. WordPress
,
.
7.
: single.php
. -
. ,
. , .
s i n g le . php
. ,
,
index, .
, .
,
, , , .
.
s in g le .p h p . WordPress ,
, ,
th e _ p o s t () .
Twenty Eleven, , s in g le , php, ,
g e t_ c o n te n t_ p a rt (), ,
, .
, W ordPress
.
27 9
.
,
,
. ,
.
, ,
.
. ,
, .
. :
<h2>0ther posts in this category</h2>
<ul id="related">
<?php
$category = get_the_category();
$my_query = new WP_Query("category_name=".$category[0]->name."
&showposts=5&orderby=rand");
while ($my_query->have_posts()) : $my_query->the_post();
echo <lixa href='". $post->permalink.'
. $post->post_title .</a>
</li>;
endwhile;
?>
</ul>
. ,
.
:
<h2>0ther posts by this author</h2>
<ul id="related">
<?php
$author = get_the_author_meta('id');
$my_queny = new WP_Query("author=".$author&showposts=5&orderby=rand");
while ($my_query->have_posts()) : $my_queny->the_post();
echo '<lixa href="'. $post->permalink.'
. $post->post_title .'"</a>
</li>';
endwhile;
?>
</ul>
single.php , W ordPress
.
-,
single.php
single-slide.php,
.
280
9.
: page.php
WordPress ,
- , .
: , .
.
, ,
, . ,
, ,
, .
.
.
page, php , .
,
t h e _ p o s t ( ). , , s i n g l e . php.
WordPress , th e _ p o st ()
.
,
ID . , .
, ,
. .
: attachment.php
, (), , -
. WordPress 2.5, im age, php
?
.
,
MIME. . Twenty Eleven
im age.php, a ttach m e n t.p h p . ,
s i n g l e . php, , s i n g l e . php ,
.
im age.php.
. ,
.
, ,
.
,
. :
-
, .
281
,
. , .
,
,
.
WordPress , , ?
WordPress . URL WordPress
, . WordPress
,
, ,
. ,
index. php,
,
.
-,
. 9.3. WordPress,
.
, , .
. , ,
WordPress.
, tem piatelo a d e r. php, te m p la te _ re d ire ct
.
URL,
, ,
URL, ,
WordPress.
------------------- ---------------------------------------------------------- , , ,
. ,
,
. WordPress
.
: , ,
, ,
.htaccess. ,
WordPress , , , ,
.
282
9.
index.php
. 9.3. WordPress
:
,
, ,
. , ,
.
.
,
. , - , ,
, .
. , .
404: 404-php
404 . -
. -, W ordPress
283
,
. ,
, , 404
.
Twenty Eleven 404
, ,
. , , ,
, .
: , , , ,
- . , 404
. - ,
.
, -
URL, Twitter.
HTTP , . ,
, - , , .
, 404 . ,
, , ,
, . : ,
- . -
Twitter. Twitter
- , .
, - Twitter
.
,
, .
, , , (
) -.
WordPress 2.5 ,
, WordPress
d b - e r r o r .p h p w p-co n te n t.
------------------------------------------------------------------------------ . ,
WordPress , .
d b - e r r o r . php CSS,
WordPress,
. , - d b - e r r o r .p h p
284
9.
WordPress,
.
db-error. php:
<?php
//error_reporting('E_ERROR');
mail('developers@mysite.com','WP SQL Connection Issue on '.$_SERVER['HTTP_HOST'],
'This is an automated message from the wordpress custom db error message file.');
?>
<html>
<head>
<title>Temporarily Unavailable</title>
<style>
body { background-color: #000; }
#wrapper
width: 600px;
height: 300px;
margin: 2em auto 0;
border: 4px solid #666;
background-color: #fff;
padding: 0 2em;
p { font-Size: larger; }
</style>
</head>
<body>
<div id="wrapper">
<center>
<!-- /* This is the generic database error page that will be shown when a fatal
db connection issue arises */ -->
<hlx?php echo $_SERVER['HTTP_HOST']; ?> is Temporarily Unavailable</hl>
<p>The webmaster has been alerted. Please try again later.</p>
</center>
</div>
</body>
</html>
, WordPress MySQL,
,
, .
, ,
, -,
. , ,
.
author.php
.
author.php, ,
. ,
ID , . ,
285
WordPress
ID.
,
. ,
. au th o r.php ,
.
.
Twenty Eleven , ,
.
<?php
// ,
// ,
if ( get_the_author_meta( 'description' ) ) : ?>
<div id="author-info">
<div id="author-avatar">
<?php echo get_avatar( get_the_author_meta( 'user_email' ),
apply_filters( 'twentyeleven_author_bio_avatar_size', 60 ) ); ?>
</div><!-- #author-avatar -->
<div id="author-description">
<h2>
<?php printf(
( 'About %s', 'twentyeleven' ), get_the_author() ); ?>
</h2>
<?php the_author_meta( 'description' ); ?>
</div><!-- #author-description
-->
</div><!-- #author-info -->
<?php endif; ?>
- ,
. ,
, , -
.
, , , .
Rolodex.
comments.php
.
, ,
, , .
, i f . . . else,
. ,
WordPress ,
,
:
<?php comments_template()j ?>
286
9.
,
, , -
. , WordPress 2.7
.
w p _ list_ co m m e n ts() WordPress.
, WordPress 2.7 ,
. ,
,
, Twenty Eleven .
Twenty Eleven ,
.
com m ent_form ( ).
.
, , ,
. WordPress 3.0
, .
, -
, .
, h t t p : / / c o m m e n t b i t s .
/ . ,
.
.
:
functions.php
f u n c t io n s .p h p ,
, ,
, - .
f u n c t io n s . p h p ,
. , ,
.
, fu n c t io n s .p h p ,
. WordPress
, .
,
f u n c t io n s . php . :
-
, . -
, , f u n c t io n s . php.
.
, , .
f u n c t io n s . php
287
, fu n ctio n s.p h p .
,
.
, HTML
CSS.
fu n c tio n s. php ,
.
,
,
. ,
, ,
8. , ,
.
fu n c tio n s . php
WordPress . Twenty Eleven
twentyeleven_setup( ) . ,
, ,
, . WordPress,
Twenty Eleven; .
.
, . ,
:
// , /
add_theme_support( 'post-thumbnails' );
:
//
add_theme_support( post-formats', array( 'aside', 'link', 'gallery', 'status',
'quote', 'image' ) );
.
, .
, , .
,
WordPress.
, fu n c tio n s . php
. , .
,
. , .
fu n c tio n s . php
.
288
9.
, .
WordPress
, Twenty Eleven:
function twentyeleven_body_classes( $classes ) {
if ( function_exists( 'is_multi_author' ) && ! is_multi_author() )
$classes[] = 'single-author';
if ( is_singular() && ! is_home() && ! is_page_template( 'showcase.php' )
&& ! is_page_template( 'sidebar-page.php' ) )
$classes[] = 'singular';
return $classes;
>
body_class( ), CSS
HTML. body_class()
, CSS
, . Twenty Eleven
,
.
. ,
,
, , .
custom _functions.php
fu n c tio n s . php . , ,
fu n c tio n s .php ,
in clu d e , ,
, .
.
, ,
, - .
,
.
. fu n c tio n s . php.
, Thematic.
fu n c tio n s .php Thematic
.
.
.
,
WordPress. , HTML
fu n c tio n s . php. , ,
Thematic. HTML
.
.
289
,
,
. WordPress
. ,
WordPress 3.4 ,
. WordPress
WordPress,
, , , ,
,
.
search.php
. , ,
(search engine result page, SERP).
searchform.php
.
. ,
. 11
WordPress
- .
Twenty Eleven.
,
.
.
, .
, , .
.
- , ,
,
404 Twenty Eleven.
.
,
, .
- , ,
.
.
.
Twenty Eleven the_excerpt()
290
9.
.
.
in c lu d e () get_tem plate_part() ,
. Twenty Eleven g e t_ te m p la te _ p a rt()
.
con tent. php . con ten t. php
i f ( - 35- ), ,
.
, ,
.
<?php the_excerpt(); ?>
:
<?php
$excerpt = get_the_excerpt();
$keys = explode(" ",$s);
$excerpt = preg_replace('/('.implode('|', $keys) .')/iu',
'<span class="searchTerm">\0 </span>',$excerpt);
echo $excerpt;
?>
th e _excerpt() ,
API get_the_excerpt(),
. replace,
span ,
. CSS
span .
, , ,
, ,
.
- :
<h2>Not seeing what you're looking for?
<?php get_search_form(); ?>
Try again</h2>
Twenty Eleven . 12
.
searchform.php
WordPress
.
, searchform. php.
.
291
,
:
<?php get_search_form(); ?>
Twenty Eleven :
<form method="get" id="searchform"
action="<?php echo esc_url( home_url( '/' ) ); ?>">
<label for="s" class="assistive-text">
<?php _e( 'Search', 'twentyeleven' ); ?>
</label>
<input type="text" class="field" name="s" id=s"
placeholder="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
<input type="submit" class="submit" name="submit"
id="searchsubmit" value="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
</form>
,
, , ,
HTML , .
,
, PHP include
. , ,
, :
<?php include($bloginfo['teipplate_directory].'includeThis.php'); ?>
He b lo g in f [ ] , .
DRY (
), ,
. WordPress ,
DRY
. ,
PH .
.
, .
,
. , , 300 * 225
PNG. GIF JP G ,
. ,
.
s ty le .c s s .
. ,
292
9.
.
. , WordPress .
,
, .
- ,
. ,
QR-. , page. php
,
. , -
, , ,
Widget Logic. -
WordPress. .
,
. WordPress
. ,
, ,
.
,
page. php. ,
,
WordPress index. php.
. 9.4
,
, Twenty Eleven
,
, ,
: .
?
* .
. 9.4.
. ,
.
.
,
ID, ,
.
,
29 3
. WordPress,
, ,
, . .
,
HTML iframe -
. ( )
.
, iframes,
. , ,
, .
-
WordPress. ,
,
. WordPress
,
, WordPress .
. - ,
- ,
.
WordPress
.
,
- REST.
, -,
WordPress .
,
:
,
.
,
.
,
.
,
WordPress.
.
.
294
9.
, ,
, . page.php.
theme.
, t_templatename. php.
t_,
, , ,
.
,
:
<?php
/*
Template Name: Fancy Page Template
*/
?>
, WordPress
.
.
. ,
, WordPress
. WordPress.
,
, .
WordPress, get_header()
get_footer (), . , , ,
, .
, WordPress
HTML, ,
.
.
,
. , ,
-, WordPress.
.
Twenty Eleven
Twenty Eleven
. , .
, Twenty Eleven, sidebarpage. php. . ,
, .
295
. showcase.php.
,
WordPress. .
-, .
Twenty Eleven. ,
.
-, .
, -,
Twenty Eleven .
, . :
, ,
.
,
, .
. ,
,
,
, . *
WordPress.
, .
.
.
, W ordPress,
(CMS), .
.
,
.
, , ,
,
. ,
: .
WordPress 3.0 ,
w p_list_pages()
.
.
296
9.
. WordPress 3.0
. .
.
fu n ctio n s .php .
:
if (function_exists(add_theme_support')) {
add_theme_support('menus');
>
. ,
, HTML
. register_nav_menu( ). .
, , .
, WordPress. ,
:
register_nav_menu('primary', 'Global navigation menu');
, .
register_nav_menu() :
register_nav_menus( array(
'primary' =>
( 'Primary Navigation', 'twentyten' ),
'supernav' => __( 'Super Navigation', 'twentyten' ),
) )J
WordPress ,
, .
header.php.
, wp_nav_menu( ):
<?php wp_nav_menu( array( 'theme_location' => primary' ) ); ?>
, ,
HTML, ,
.
primary.
, ,
. , ,
HTML.
. ,
. ,
, .
,
, .
? , WordPress
.
297
w p_list_pages()
.
. ,
.
. ,
Page Links ,
, . ,
w p_ list_ pages( )
PageMash.
. , ,
, .
, .
w p_ list_ pages( ).
,
. ,
.
.
. .
,
. ,
. ,
.
.
. ,
.
. ,
, , . ,
,
.
, ,
. ,
, .
, , -
.
t_product_page.php. ,
,
,
.
.
. .
,
298
9.
- ,
.
, . fu n c t io n s .p h p
.
, .
, ,
. , Twenty Eleven,
, ,
. .
. ,
, .
,
.
, .
fu n c t io n s .p h p .
, ,
,
HTML . ,
,
- r e g is t e r _ s id e b a r ( ),
. Twenty Eleven:
register_sidebar( array(
'name' => __( 'Main Sidebar', 'twentyeleven'
'id' => 'sidebar-1',
'before_widget' => '<aside id="%l$s" class="widget %2$s">',
after_widget' => "</aside>",
'before_title' => '<h3 class="widget-title">',
'after_title' => </h3>',
) );
,
.
.
Twenty Eleven HTML5 a s id e ,
h3. WordPress ,
.
HTML
. s id e b a r .p h p Twenty Eleven, , ,
. :
<?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>
<aside id="archives" class="widget">
299
</ul >
</aside>
<aside id="meta" class="widget">
<h3 class="widget-title"x?php _e( 'Meta', 'twentyeleven' ); ?x/h3>
<ul>
<?php wp_register(); ?>
<lix?php wp_loginout(); ?x/li>
<?php wp_meta(); ?>
</ul >
</aside>
<?php endif; // ?>
. :
, sidebar-1.
, .
: ,
, .
, ,
.
, ,
. ,
.
, .
/ fu n ctio n s. php.
, .
.
WordPress .
HTML ,
.
, .
WordPress
. ,
, .
. WordPress
, .
, WordPress 3.1 .
, W ordPress
:
300
9.
Aside. . .
Audio. ,
.
Chat. .
HTML .
Gallery. -.
.
Image. ,
, URL .
Link. URL,
.
URL.
Quote. , .
.
Status. Tw itter Facebook.
.
Twitter.
Video.
.
URL.
, ,
, . ,
Twenty Eleven :
add_theme_support( 'post-formats', array( 'aside', 'link', gallery,
status', 'quote', 'image' ) );
,
.
.
. ,
, ,
,
.
,
. ,
, , .
301
,
WordPress.
. ,
, ,
.
WordPress . .
(Theme Customizer), WordPress 3.4.
. ,
.
.
.
,
,
. ,
. , ,
.
, , , , -
.
.
Twenty Eleven ,
, ,
.
API WordPress
.
fu n ctio n s. php WordPress
HTML.
Twenty Eleven fu n ctio n s. php
CSS HTML, .
.
, ,
.
,
, Twenty Eleven.
302
9.
Twenty Eleven .
, .
.
, , CSS,
. ,
. , , , .
WordPress 2.7
. ,
.
,
, ,
.
,
( ) .
WordPress.
. -,
.
, . , ,
, . , ,
CSS ,
, .
,
.
, .
, , .
.
,
.
, .
,
,
. .
. ,
, .
,
.
,
, ,
, -
. , ,
303
.
, .
.
, CSS.
CSS . , CSS
, .
, CSS ,
, . CSS
, , ,
.
WordPress,
, . ,
CSS ,
, . :
WordPress .
,
. , .
.
, :
.
.
Twenty Eleven,
.
,
, s ty le . es s.
WordPress .
.
, .
:
T e m p la te : t w e n t y e le v e n
:
/*
Theme Name: A T w enty E le v e n C h i l d Theme
Theme U R I: m ir m illo . c o m
D e s c r i p t i o n : A sa m p le c h i l d them e
A u t h o r : D a v id D a m stra
A u t h o r U R I: m ir m illo . c o m
T e m p la te : t w e n t y e le v e n
V e r s io n : 1 . 0
*/
304
9.
, s ty le .c s s
WordPress.
CSS ,
:
/ *
*/
@ im p o rt u r l ( ' . . / t w e n t y e l e v e n / s t y l e . c s s ' ) ;
WordPress.
Twenty Eleven. , Twenty Eleven,
.
CSS, CSS
, ,
, ,
.
: CSS ,
.
, ,
CSS.
. sty le , css :
/*
Theme Name: A T w en ty E le v e n C h i l d Theme
Theme U R I: m ir m illo . c o m
D e s c r i p t i o n : A sa m p le c h i l d them e
A u t h o r : D a v id D a m stra
A u t h o r U R I: m ir m illo . c o m
T e m p la te : t w e n t y e le v e n
V e r s io n : 1 . 0
*/
/ *
*/
@ im p o rt u r l ( ' . . / t w e n t y e l e v e n / s t y l e . c s s ' ) ;
body {
b a c k g ro u n d : #E0A3BD;
c o l o r : #333;
f o n t : 100%/1 . 5 c a l i b r i , a r i a l , v e r d a n a ,
s a n s - s e r if ;
}
.
, ,
, CSS- .
: CSS.
, .
,
, .
, , ,
.
305
. WordPress , ,
. ,
. WordPress
,
, .
,
. ,
.
,
, ,
.
, Twenty Eleven ,
, . :
, .
author. php Twenty Eleven
. ,
46- . :
<?php e c h o g e t _ a v a t a r ( g e t _ t h e _ a u t h o r _ m e t a ( 'u s e r _ e m a il' ) ,
a p p l y _ f i l t e r s ( ' t w e n t y e le v e n _ a u t h o r _ b io _ a v a t a r _ s iz e ', 120 ) ) ;
?>
60 120
. , , . 9.5.
, functions.php.
WordPress , , ,
.
. , ,
.
, :
, , .
,
,
. , functions. php
HTML ,
. , 8.
, , ,
,
, , ,
.
, WordPress.
, ,
, . ,
.
306
9.
WordPress
lust another W o rd Pro site
P Search
About David Oamstra
T his is my bto information i love WordPress
COWMt!
M r W ordP tes* on ( to w
P 'o tw lo r w t W ordP ress
MClM VH
. 9.5.
, .
,
.
, ,
,
CSS , ,
. ,
-, ,
.
Twenty Eleven
. , , ,
, .
307
, ,
fu n c tio n s .php.
WordPress.
,
, .
.
,
, . ,
, (
, ), WordPress 2.7
.
( ) . ,
.
, ,
. Magazine themes ( ) premium themes (
) . ,
, .
commercial ().
, .
, .
starter () .
,
, .
,
. ,
.
Bones
Bones , .
HTML5, , .
, , ,
.
Bones.
HTML5, Bones ,
, . -
12, ,
, ,
. Bones
LESS Sass CSS . Bones: http://
t h e m b le . c o m / b o n e s .
308
9.
Carrington
Carrington , Crowd Favorite .
,
. Carrington
.
. Carrington ,
, , .
Crowd Favorite W ordPress,
RAMP, 3, Carrington Build,
. Carrington : h t t p : / /
c a r r in g to n th e m e .c o m .
Genesis
Genesis, StudioPress , ,
, .
, StudioPress . Genesis
-
.
Genesis Revolution.
WordPress
. Revolution ,
, WordPress -
CMS-. WordPress
-.
, Revolution .
. StudioPress
Genesis .
Genesis :
h ttp : //s t u d io p r e s s .c o m .
Hybrid Core
Hybrid ,
, .
CSS. Hybrid .
CSS body.
.
,
, . Hybrid ,
,
.
Hybrid Core :
309
h ttp ://th e m e h y b r id .
/.
Roots
Roots, , .
Bones, HTML5 Twitter Bootstrap.
Twitter Bootstrap, .
Roots . ht accs s
- Apache. . htaccess URL ,
W ordPress , CSS,
JavaScript ,
URL. , .htaccess URL ,
, URL
. URL
WordPress .
Roots :
StartBox
StartBox ,
. Hybrid, ,
, .
StartBox
, -
.
,
. StartBox, ,
, Sandbox,
CSS, HTML.
StartBox
Thematic
Thematic , . ,
. ,
. Thematic
.
. -,
Sandbox. CSS ,
Sandbox, Thematic . -,
13 . Thematic
310
9.
.
: h t t p : / / t h e m e s h a p e r . c o m / t h e m a t i c / .
, ,
. .
, , .
, ,
.
,
WordPress
.
Multisite
:
WordPress Multisite
Multisite WordPress
Multisite
Multisite
Multisite
W rox.com
wrox.com www.wrox.com/remtitle.
cgi?isbn=9781118442272 Download Code.
10 .
WordPress Multisite WordPress.
, Multisite -
WordPress. WordPress.
Multisite ,
. WordPress Multisite
WordPress.com, , Multisite.
M u ltisite ?
WordPress 3.0 Multisite WordPress MU (
)
, . WordPress 3.0 MU
WordPress, WordPress Multisite.
312
10. Multisite
Multisite , ,
WordPress.
Multisite
, , WordPress
Multisite. Multisite ( network)w cam(site).
Multisite . .
WordPress Multisite .
(BlogID). ID
, , Multisite.
ID .
(site ID). , WordPress
,
. WordPress
- , .
------------------------------------------------------------------------------ . WordPress Multisite
. ID , ,
.
WordPress,
-, WordPress. W ordPress M ultisite
- WordPress.
Multisite , WordPress:
. :
http://sitel.exam ple.com /
http://site2.example.com/
, , .
( http://mywebsite.com), .
Multisite?
313
Multisite -.
, .
W ordPress M ultisite : Super Admin
(). -
Multisite. Multisite.
M ulti
site, ,
.
Multisite
WordPress Multisite WordPress.
WordPress .
WordPress, .
WordPress Multisite 50 ,
, .
50 WordPress,
50 .
.
Multisite. ,
50 ,
, .
Multisite ,
.
. ,
.
Multisite
Multisite WordPress .
: wp-config.php:
define( 'WP_ALLOW_MULTISITE', true );
:
/* , . ! */
/* Thats all, stop editing! Happy blogging. */
wp-config.php .
WordPress, ,
. 10.1.
314
10. Multisite
WordPress.
,
Multisite.
, . WordPress
, .
, , ,
Multisite WordPress.
^
lfl
. 10.1.
Multisite ;
, WordPress . :
b lo g s . d i r /w p -c o n te n t.
, Multisite. w p -co n te n t/
b lo g s . d ir/B L O G _ ID /f iles/YEAR/MONTH. ,
, : http://example.com/files/2013/10/Halloween.png.
w p -co n f i g . php.
Multisite
. Multisite
e x am p le. com.
define(
define(
$base =
define(
define(
define(
define(
'MULTISITE 1, true );
'SUBDOMAIN_INSTALL, false );
'/';
'DOMAIN_CURRENT_SITE', 'example.com' );
'PATH_CURRENT_SITE' , '/' );
'SITE_ID_CURRENT_SITE' , 1 );
'BLOG_ID_CURRENT_SITE' , 1 );
. h ta c c e s s :
RewriteEngine On
RewriteBase /
RewriteRule Aindex\.php$ - [L]
# uploaded files
RewriteRule A([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
# add a trailing slash to /wp-admin
RewriteRule A([_0-9a-zA-Z-]+/)?wp-admin$ $lwp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
315
RewriteCond %{REQUEST_FILENAME> -d
RewriteRule - [L]
RewriteRule A[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
RewriteRule A[_0-9a-zA-Z-]+/(.* \ . php)$ $1 [L]
RewriteRule . index.php [L]
M ultisite,
, ,
Multisite WordPress.
, WordPress.
M ultisite
W ordPress. .
, Multisite.
,
, . 10.2.
s
WordPress Multisite !
ffl} Koi
ptol
^
G$j
(3) I Ai
. 10.2. Multisite
, , Multisite WordPress, ,
. Multisite
WordPress .
WordPress Multisite
. WordPress
http://example.com/wp-admin/network/.
,
WordPress.
Multisite, .
, Multisite,
316
10. Multisite
. ,
, , ,
. ,
, .
. ,
. 10.3.
h t t p : / / t e x t a i . ru
2014-01-24 13:28:07
2014-01-24 09:41:54
Q
Q
. 10.3.
.
.
.
.
:
,
.
1. P u b lic
2. A rc h iv e d .
3. Spam
4. D e le te d .
5. M ature .
: P u b lic M ature.
,
. .
.
Multisite .
317
.
,
, ,
.
.
. , ,
.
Multisite , WordPress.
,
.
. ,
, X.
,
WordPress.
, () .
, : Halloween Christmas,
Halloween, Christmas. ,
Christmas .
Multisite,
. , ,
, ,
. ,
. ,
.
Multisite , WordPress.
. Multisite
WordPress.
, WordPress,
. ,
WordPress. ,
A ctivate Network Enable.
.
, ,
318
10. Multisite
WordPress.
, .
Multisite , .
, , .
, - .
.
, ,
. / WordPress.
.
,
.
------------------------------------------------------------------------------ , Multisite,
. Multisite ,
, .
M ultisite ,
.
.
.
, ,
. Multisite,
.
.
. ,
.
Multisite
. Multisite:
. , ,
? ! WordPress MU Domain
Multisite
319
Mapping (http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/)
.
. , . ,
http://example.com/brad http://example.com/myers
http://brad.com http://myers.com. URL
, .
M u ltisite
Multisite WordPress,
API .
Multisite.
Multisite .
(Blog ID). ,
Multisite, . WordPress
, .
,
. M ultisite
WordPress
. , , WordPress
wp_2_posts, wp_ ,
WordPress, 2_ .
$blog_id:
<?php
global $blog_id;
echo 'Current Blog ID: ' .$blog_id;
?>
Multisite $blog_id ID ,
. WordPress $blog_id 1.
Multisite .
Multisite is_m u ltisite():
<?php
if ( is_multisite() ) {
echo 'Multisite is enabled';
>
?>
320
10. Multisite
, Multisite,
true. , Multisite
WordPress, , Multisite . ,
, .
: get_blog_details( ).
<?php get_blog_details( $fields, $getall ); ?>
:
1. $f ie ld s Blog ID, .
2. $ g e ta ll .
, :
<?php print_r( get_blog_details( 1 ) ); ?>
:
stdclass Object
[blog_id] => 1
[site_id] => 1
[domain] => example.com
[path] => /
[registered] => 2012-10-31 19:01:47
[last_updated] => 2012-10-31 19:01:49
[public] => 1
[archived] => 0
[mature] => 0
[spam] => 0
[deleted] => 0
[lang_id] => 0
[blogname] => Halloween Site
[siteurl] => http://example.com
[post_count] => 420
WordPress Multisite
.
,
. switch_to_blog( ).
:
<?php switch_to_blog( $blog_id, $validate )j ?>
:
1. $blog_id ID , .
2. $ v alid ate , , .
false.
Multisite
321
re s to r e _ c u r r e n t_ b lo g ( ). ,
: s w it c h _ t o _
b lo g ( ). ,
:
add_shortcode( 'show_network_posts' ,
'prowp_get_network_posts );
}
//
return $site_posts;
>
, , Multisite ,
i s _ m u lt is it e ( ) . s w it c h _ t o _ b lo g ( ),
, Blog ID . Blog ID
, Blog ID 1.
, , ,
322
10. Multisite
WP_Query, .
WP_Query,
$ s ite _ p o s t s .
r e s t o r e _ c u r r e n t _ b lo g ( ) ,
, .
, WordPress Blog ID 10,
, , .
$ s ite _ p o s ts ,
Blog ID 10.
!
, : [sh o w _ n etw o rk_ p o sts b lo g _ id = " 1 0 " ] .
10.1 , .
10.1. (prowp2-multisite-shortcode.zip)
<?php
/*
Plugin Name: ProWP2 Multisite Shortcode Example
Plugin URI: http://strangework.com/wordpress-plugins
Description: A shortcode to display posts from any site in your network
Version: 1.0
Author: Brad Williams
Author URI: http://strangework.com
License: GPLv2
*/
add_shortcode( 'show_network_posts', 'prowp_get_network_posts' );
function prowp_get_network_posts( $atts ) {
extract( shortcode_atts( array(
'blog_id' => 1
), $atts ) );
// , Multisite
if ( is_multisite() ) {
// ID
switch_to_blog( absint( $blog_id ) );
//
$recent_posts = new WP_Query();
$recent_posts->query( 'posts_per_page=5' );
$site_posts =
//
while ( $recent_posts->have_posts() ) :
$recent_posts->the_post();
//
$site_posts .= '< href="'.get_permalink().'">'
.get_the_title(). '</ax/p>';
endwhile;
Multisite
323
//
restore_current_blog();
>
//
return $site_posts;
}
?>
sw itch_to_blog() ,
WordPress, , ,
. ,
(wp_blogid_tablename), sw itch_to_blog().
.
Multisite.
< ?php
switch_to_blog( 10 );
wp_nav_menu( 'Main Menu' );
restore_current_blog();
?>
sw itch_to_blog(), Blog ID 10.
WordPress wp_nav_menu ( ) WordPress,
Main Menu . , restore_current_blog( ),
, .
Main Menu ID 10 ,
.
, sw itch_to_blog( )
SQL,
WordPress. ,
, ,
. WordPress 11.
: sw itch_to_blog()
, ,
. ,
, ,
.
Multisite,
, . ,
wpmu_create_blog().
<?php wpmu_create_blog($domain, $path, $title, $user_id, $meta, $site_id); ?>
324
10. Multisite
:
1. $domain .
2. $path .
3. $ t i t l e .
4. $user_id ID , .
5. $meta .
6. $ s ite _ id ID .
,
. $ s ite _ id ,
WordPress.
, Blog ID.
, ,
wpmu_create_blog() Multisite:
add_action( 'admin_menu', 'prowp_multisite_create_menu' );
function prowp_multisite_create_menu() {
//
add_menu_page( 'Multisite Create Site Page, 'Multisite Create Site',
'manage_options', 'prowp-network-create', 'prowp_multisite_create_sites' );
>
M ultisite Create
Site. p ro w p _ m u ltisite_
c re a te _ s ite s ( ), .
:
function prowp_multisite_create_sites() {
// , Multisite
if ( is_multisite() ) {
, Multisite,
is _ m u ltis ite ( ) .
Multisite:
// ,
if ( isset( $_P0ST['create_site'] ) ) {
//
$domain = strip_tags( $_P0ST['domain'] );
$path = strip_tags( $_P0ST['path'] );
$title = strip_tags( $_P0ST['title'] );
$user_id = absint( $_P0ST['user_id'] );
// ,
if ( $domain && $path && $title && $user_id ) {
//
$new_site = wpmu_create_blog( $domain, $path, $title, $user_id );
//
if ( $new_site ) {
echo <div class="updated">New site .$new_site
Multisite
325
>
// ,
} else {
echo '<div class="error">New site could not be created.
Required fields are missing</div>';
}
}
, $_POST[ ' create_s i t ' ].
, .
, . ,
, ,
HTML . , user_id
, WordPress a b s in t( ).
, , , .
- ,
. , ,
wpmu_create_blog(), .
, $new_site Blog ID .
:
<div class="wrap">
<h2>Create New Site</h2>
<form method="post">
ctable class="form-table">
<tr valign="top">
<th scope="row"xlabel for="fname">Domain</labelx/th>
<tdxinput maxlength="45" size="25" name="domain"
value="<?php echo esc_attr( DOMAIN_CURRENT_SITE ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"xlabel for="fname">Path</labelx/th>
<tdxinput maxlength="45" size="10" name="path" /x/td>
</tr>
<tr valign="top">
<th scope="row"xlabel for="fname">Title</labelx/th>
<tdxinput maxlength="45" size="25" name="title" /x/td>
</tr>
<tr valign="top">
<th scope="row"xlabel for="fname">User ID</labelx/th>
<tdxinput maxlength="45" size="3" name="user_id" /x/td>
</tr>
<tr valign="top">
<td>
<input type="submit" name="create_site"
value="Create Site" class="button-primary" />
<input type="submit" name="reset" value="Reset" class="button-secondary" />
</td>
</tr>
</table>
</form>
</div>
326
10. Multisite
HTML
Multisite. ,
, 10.2.
10.2. Multisite (prowp2-multisite-create-site.zip)
<?php
/*
Plugin Name: ProWP2 Create Site Example Plugin
Plugin URI: http://strangework.com/wordpress-plugins
Description: , Multisite
Version: 1.0
Author: Brad Williams
Author URI: http://strangework.com
License: GPLv2
*/
add_action( 'admin_menu', 'prowp_multisite_create_menu' );
function prowp_multisite_create_menu() {
//
add_menu_page( 'Multisite Create Site Page',
'Multisite Create Site', 'manage_options',
prowp-network-create', 'prowp_multisite_create_sites' );
}
function prowp_multisite_create_sites() {
// , Multisite
if ( is_multisite() ) {
// ,
if ( isset( $_POST['create_site'] ) ) {
//
$domain = strip_tags( $_POST['domain'] );
$path = strip_tags( $_POST['path'] );
$title = strip_tags( $_POST['title'] );
$user_id = absint( $_POST[*user_id'] );
// ,
if ( $domain && $path && $title && $user_id ) {
//
$new_site = wpmu_create_blog( $domain, $path,
$title, $user_id );
//
if ( $new_site ) {
echo '<div class="updated">New site '
.$new_site. ' created successfully!</div>';
}
// ,
//
} else {
Multisite
327
>
>
?>
<div class="wrap">
<h2>Create New Site</h2>
form method="post">
table class="form-table">
<tr valign="top">
<th scope="row"xlabel for="fname">Domain</labelx/th>
tdxinput maxlength="45" size="25" name="domain"
value="?php echo esc_attr( DOMAIN_CURRENT_SITE ); ?>" /></td>
</tr>
<tr valign="top">
<th scope="row"xlabel for="fname">Path/labelx/th>
tdxinput maxlength="45" size="10" name="path" /x/td>
</tr>
<tr valign="top">
<th scope="row"xlabel for="fname">Title/labelx/th>
tdxinput maxlength="45" size="25" name="title" /x/td>
</tr>
<tr valign="top">
<th scope="row"xlabel for="fname">User ID/labelx/th>
tdxinput maxlength="45" size="3" name="user_id" /x/td>
</tr>
<tr valign="top">
<td>
input type="submit" name="create_site"
value="Create Site" class="button-primary" />
input type="submit" name="reset"
value="Reset" class="button-secondary" />
</td>
</tr>
</table>
</form>
</div>
<?php
} else {
echo <p>Multisite is not enabled/p>';
}
}
Multisite.
. WordPress,
328
10. Multisite
Network Admin .
network_admin_menu:
add_action( 'network_admin_menu', 'prowp_add_network_settings_menu' );
network_admin_menu ,
.
prowp_add_network_settings_menu( ), .
function prowp_add_network_settings_menu() {
//
add_menu_page( 'ProWP2 Options Page, 'ProWP2 Options',
'manage_options', 'prowp-network-settings', 'prowp_network_settings' );
>
, ,
WordPress.
add_menu_page(),
. 10.4.
, ,
.
add_submenu_page():
function prowp_add_network_settings_menu() {
//
add_submenu_page( 'settings.php, 'ProWP2 Options Page',
'PnoWP2 Options', manage_options', 'prowp-network-settings',
'prowp_network_settings' );
}
,
W ordPress. , s e t
tin g s , php, .
, .
Network Admin
ProWP2 Options.
:
in d e x. php ;
[1
*2
s it e s . php ;
u se rs . php ;
themes . php ;
p lu g in s . php ;
s e tt in g s . php ;
update-core . php .
. 10.4.
Network Admin
Multisite
329
,
.
, WordPress.
Multisite
M ultisite
. , :
?
,
.
, .
Multisite,
*_blog_option():
add_blog_option() .
Q update_blog_option() ,
.
get_blog_option() .
delete_blog_option() .
WordPress; , $blog_id:
<?php add_blog_option( $blog_id, $key, $value ); ?>
$key , , $value
.
. ,
g et_ b lo g _ o p tio n (), ,
Blog ID 10:
<?php
$blog_id = 10;
echo '<p>Site ID: ' .$blog_id .'</p>';
echo <p>Site Name: ' .get_blog_option( $blog_id, 'blogname' ) .</p>';
echo '<p>Site URL: ' .get_blog_option( $blog_id, 'siteurl' ) .'</p>';
?>
M ultisite
*_site_ o p tio n ():
330
10. Multisite
add_site_option() .
update_site_option() ,
.
g e t_ site _ o p tio n () .
d e le te _ site _ o p tio n () .
WordPress, wp_sitemeta Multisite.
Multisite,
.
<?php add_site_option( $key, $value ); ?>
,
Blog ID. , ,
Blog ID .
Multisite , * _ s ite _ o p tio n ( ),
WordPress *_opt ion ( ) ,
add_option().
, , ,
Multisite.
, .
, Multisite,
WordPress.
.
add_action( 'init', 'prowp_network_settings_menu' );
function prowp_network_settings_menu() {
if ( is_multisite() ) {
// Multisite , Network Admin
add_action( network_admin_menu', 'prowp_add_network_settings_menu' );
} else {
// Multisite ,
// WordPress
add_action( 'admin_menu', 'prowp_add_network_settings_menu' );
}
>
- in it . ,
is _ m u ltis it e ( ). Multisite,
Network Admin,
Multisite
331
WordPress. ,
, Multisite.
, - ,
.
function prowp_add_network_settings_menu() {
//
add_menu_page( 'Network Options Page', 'Network Options',
manage_options', 'prowp-network-settings', 'prowp_network_settings' );
>
add_menu_page( ),
, (Network Options). ,
, .
//
function prowp_network_settings() {
?>
<div class="wrap" >
<div id=icon-options-general" class="icon32"x/div>
<h2>Network Settings</h2>
<form method="post">
<?php
//
$network_settings = get_site_option( 'prowp_network_settings );
$api_key = $network_settings['api_key'];
$holiday = $network_settings['holiday'];
$rage_mode = ( ! empty( $network_settings['ragejnode'] ) )
? $network_settings['ragejnode'] : '';
//
wp_nonce_field( 'save-network-settings', 'prowp-network-plugin' );
?>
<table class="form-table">
<tr valign="top"xth scope="row">API Key:</th>
<tdxinput type="text" name="network_settings[api_key] "
value="<?php echo esc_attr( $api_key ); ?>" /x/td>
</tr>
<tr valign="top"xth scope="row">Network Holiday</th>
<td>
<select name="network_settings[holiday]">
<option value="halloween"
<?php selected( $holiday, 'halloween' ); ?> >
Halloween
</option>
<option value="christmas"
<?php selected( $holiday, 'christmas' ); ?> >
Christmas
</option>
<option value="april_fools"
<?php selected( $holiday, 'april_fools' ); ?> >
April Fools
</option>
</select>
332
10. Multisite
</td>
</tr>
<tr valign="top"xth scope="row">Rage Mode:</th>
<tdxinput type="checkbox" name="network_settings[rage_mode]"
<?php checked( $rage_mode, 'on' ); ?> /> Enabled
</td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary"
name="network_settings_save" value="Save Settings" />
</p>
</form>
</div>
<?php
>
HTML-.
, 8 .
.
g e t_ site _ o p tio n (), prowp_network_settings,
, .
.
, wp_nonce_field(),
.
. API,
. . ,
se le c te d () .
Rage Mode. checked (),
, . HTML-,
.
, ,
.
add_action( 'admin_init', 'prowp_save_network_settings' );
//
function prowp_save_network_settings() {
// ,
if ( isset( $_P0ST['network_settings'] ) ) {
//
check_admin_referer( 'save-network-settings', prowp-network-plugin' );
//
$network_settings = $_P0ST['network_settings'];
//
$network_settings = arnay_map( 'sanitize_text_field', $network_settings );
Multisite
/ /
u p d a t e _ s it e _ o p t io n ( p r o w p _ n e t w o r k _ s e t t in g s ' ,
$ n e t w o r k _ s e t t in g s
333
);
}
}
admin_init. , .
, . , ,
$_POST[ network_settings ' ] ,
is s e t ( ). , ,
check_admin_referer().
$network_settings.
, , .
- _( ),
,
san itize_text_f ie ld ( ). , ,
, update_site_option().
!
, WordPress.
Multisite, Network Admin,
wp_sitemeta. Multisite,
WordPress,
wp_options.
10.3 .
10.3. Multisite (prowp2-multisite-network-settings.zip)
<?php
/*
P lu g i n Name: ProWP2 N e tw o rk S e t t i n g s E xa m p le
P lu g i n U R I: h t t p : / / s t r a n g e w o r k . c o m / w o r d p r e s s - p lu g in s
D e s c r i p t i o n : T h is i s a p lu g in d e m o n s t r a t in g t h e M u l t i s i t e
S e t t in g s
V e r s io n : 1 .0
A u t h o r : B ra d W ill ia m s
A u t h o r U R I: h t t p : / / s t r a n g e w o r k . c o m
L ic e n s e : G PLv2
N e tw o rk W o rd P re s s
*/
a d d _ a c t io n ( ' i n i t ' , 'p r o w p _ n e t w o r k _ s e t t in g s _ m e n u '
f u n c t i o n p r o w p _ n e t w o r k _ s e t tin g s _ m e n u ( ) {
if
( is _ m u lt is it e ( )
);
) {
/ / M u l t i s i t e , N e tw o rk Adm in
a d d _ a c t io n ( 'n e tw o rk _ a d m in _ m e n u ', ' p r o w p _ a d d _ n e t w o r k _ s e tt in g s _ m e n u ' ) ;
} e ls e {
334
10. Multisite
// Multisite ,
// WordPress
add_action( 'adminjnenu', prowp_add_network_settings_menu );
>
>
function prowp_add_network_settings_menu() {
//
add_menu_page( 'Network Options Page',
'Network Options', 'manage_options',
'prowp-network-settings', prowp_network_settings' );
>
//
function prowp_network_settings() {
?>
<div class="wrap" >
<div id="icon-options-general" class="icon32"x/div>
<h2>Network Settings</h2>
<form method="post">
<?php
//
$network_settings = get_site_option( 'prowp_network_settings' );
$api_key = $network_settings[api_key'];
$holiday = $network_settings['holiday'];
$rage_mode = ( ! empty( $network_settings['rage_mode'] ) )
? $network_settings['rage_mode'] : '';
//
wp_nonce_field( 'save-network-settings', 'prowp-network-plugin' );
?>
<table class="form-table">
<tr valign="top"xth scope="row">API Key:</th>
<tdxinput type="text"
name="network_settings[api_key]"
value="<?php echo esc_attr( $api_key ); ?>"
/x/td>
</tr>
<tr valign="top"xth scope="row">Network Holiday</th>
<td>
<select name="network_settings[holiday]">
coption value="halloween"
<?php selected( $holiday, 'halloween' ); ?>
>Halloween</option>
<option value="christmas"
<?php selected( $holiday, 'christmas' ); ?>
>Christmas</option>
coption value="april_fools"
cPphp selected( $holiday, 'april_fools' ); ?>
>April Fools</option>
</select>
</td>
</tr>
<tr valign="top''xth scope="row">Rage Mode:</th>
ctdxinput type="checkbox"
name="network_settings[rage_mode]"
Multisite
335
>
>
}
Multisite ,
. ,
is_user_member_of_blog( ).
<?php is_user_member_of_blog( $user_id, $blog_id ); ?>
.
. ,
. . ,
.
<?php
if ( is_user_member_of_blog() ) {
//
>
?>
336
10. Multisite
,
.
, , , ,
add_user_to_blog( ):
<?php add_user_to_blog( $blog_id, $user_id, $role ); ?>
:
1. $blog_id ID , ;
2. $user_id ID ;
3. $nole .
,
, Multisite:
add_action( 'init', 'prowp_multisite_add_user_to_site' );
- i n i t ,
.
function prowp_multisite_add_user_to_site() {
// ,
if( !is_user_logged_in() )
return false;
// ID
global $current_user, $blog_id;
// ,
if( ! is_user_member_of_blog() ) {
//
add_user_to_blog( $blog_id," $current_user->ID, 'subscriber' );
>
>
, , ,
fa ls e . ^
$current_user $blog_id.
Blog ID . ,
, is_ u ser_
member_of_blog( ).
add_user_to_blog( ).
, .
! ,
, /mu-plugins.
.
10.4.
Multisite
337
10.4. Multisite
(prowp2-multisite-add-users.zip)
<?php
/*
Plugin Name: ProWP2 Multisite Auto-Add User to Site
Plugin URI: http://strangework.com/wordpress-plugins
Description: Plugin automatically adds the user to any site they visit
Version: 1.0
Author: Brad Williams
Author URI: http://strangework.com
License: GPLv2
*/
add_action( 'init', 'prowp_multisite_add_user_to_site );
function prowp_multisite_add_user_to_site() {
// ,
if( !is_user_logged_in() )
return false;
// ID
global $current_user, $blog_id;
// ,
if( ! is_user_member_of_blog() ) {
//
add_user_to_blog( $blog_id, $current_user->ID, 'subscriber' );
>
}
?>
, , ,
. remove_user_f rom_
blog():
<?php remove_user_from_blog( $user_id, $blog_id, $reassign ); ?>
:
1. $user_id ID ;
2. $blog_id ID , ;
3. $reassign ID , .
$user_id $blog_id . {reassign
. ID ,
.
-------------------------------------------------------------------------, Multisite ,
WordPress,
.
338
10. Multisite
, ,
get_blogs_of_user( ). ,
, . :
<?php
$user_id = 1;
$user_blogs = get_blogs_of_user( $user_id );
echo 'User '.$user_id.'\ 's blogs:<ul>';
foreach ( $user_blogs AS $user_blog ) {
echo '<li>' .$user_blog->blogname .'</li>';
>
echo '</ul>';
?>
,
ID 1. ,
blogname .
, Multisite,
. -
Multisite,
, .
Multisite,
get_super_adm ins().
. :
<?php
$all_admins = get_super_admins();
print_r( $all_admins );
?>
:
Array
(
[0] => admin
[1] => michael_myers
)
,
, .
is_super_admin():
< ?php
$user_id = 1;
if ( is_super_admin( $user_id ) ) {
echo 'User is a Super Admin';
>
Multisite
339
, ID 1
. $user_id . ID
, .
, , ,
.
grant_super_admin().
: ID , .
<?php
$user_id = 34;
grant_super_admin( $user_id );
?>
revoke_super_admin(). ,
: ID , :
<?php
$user_id = 34;
revoke_super_admin( $user_id );
?>
wp-admin/includes/ms.php,
.
Multisite .
get_blog_count () .
, get_user_count().
<?php
$site_count = get_blog_count();
$user_count = get_user_count();
echo '<p>Total sites: ' .$site_count .</p>;
echo '<p>Total users: ,$user_count .'</p>';
?>
g e t_ s ite s ta ts ( )
.
/
<?php
$network_stats = get_sitestats();
echo <p>Total sites: ' .$network_stats['blogs'] .'</p>';
echo '<p>Total users: ' .$network_stats['users'] .'</p>';
?>
Multisite
WordPress Multisite
WordPress. M ultisite W ordPress
Multisite.
340
10. Multisite
Multisite
WordPress Multisite .
, Multisite ,
wp_users wp_usermeta, WordPress.
wp_blogs , Multisite.
wp_blog_versions
.
wp_registration_log ,
WordPress.
wp_signups ,
WordPress.
wp_site .
wp_sitecategories . ,
WordPress.
wp_sitemeta ,
.
wp_users , WordPress.
wp_usermeta
WordPress.
, , , WordPress
. , Multisite, .
.
. ,
$table_prefix, wp-config. php,
$blog_id .
wp_2_commentmeta;
wp_2_comments;
wp_2_links;
wp_2_options;
wp_2_postmeta;
wp_2_posts;
wp_2_terms;
341
wp_2_term_relationships;
wp_2_term_taxonomy.
, Multisite, WordPress
. ,
.
WordPress Multisite , .
1000 , 9000 . ,
.
6
WordPress .
Multisite, Blog ID
.
$wpdb- >, ID , Multisite.
, $wpdb->posts wp_2_posts, ,
Blog ID 2 .
:
WordPress
,
,
, WordPress
, ,
. WordPress
, ,
,
1, : ,
. ,
.
, ,
, : Facebook
; Twitter ,
,
b i t . ly. Google, Bing nYahoo!
, -.
: W ordPress
, ,
.
(Personal W ebsite) (Business Website),
343
. W ordPress
,
.
, . ,
, , ,
, a Facebook Tw itter ,
,
WordPress.
, ,
. WordPress
?
,
, , ,
.
, YouTube, Twitter, Facebook ,
.
,
API, Google Maps, , API WordPress
.
, .
, :
, . ,
,
.
, ,
SEO (Search Engine Optimization ). SEO ,
, 12.
- .
,
.
.
.
344
11.
,
.
,
,
?
,
, .
:
, ;
12.
.
,
. ,
YouTube,
, ?
.
,
.
,
.
. , ,
( ,
)
, .
,
, .
Facebook, ,
.
,
.
, ,
, ,
, . Google
Maps ( Google) ,
;
Twitter ,
.
,
.
,
.
345
, - .
(, , ) , ,
,
. -,
. , ,
(Field o f Dreams), , , .
. ,
,
?
WordPress
,
: , , !.
;
. ,
. ,
?
ShareThis (http://wordpress.org/extend/plugins/share-this/) .
120 ,
.
. ,
, ,
. ,
,
.
, . 11.1.
Professional WordPress is my
Favorite Book on WordPress
T h is book is great You should order a copy for all your friends
HESS S 3
New
QB23SE33
lio
MtMMim
0
SL . E22E3
. 11.1. WordPress
346
11.
.
,
.
Pinterest.
Pinterest. !
, WordPress
, Facebook, Twitter
Pinterest .
,
,
.
Twitter
, .
, ,
Twitter ,
. , Twitter
, WordPress, ,
Tweetily (http://wordpress.org/extend/plugins/tweetily-tweet-wordpress-postsautomatically/),
.
Facebook, :
?
WordPress Facebook, Facebook
,
, .
, ,
. , Facebook
,
- , - ,
Facebook
. :
Facebook WordPress,
,
.
,
W ordPress Facebook
Facebook RSS Graffiti (h tt p :/ / a p p s .fa c e b o o k .c o m / r s s g r a ffiti/ ).
Facebook, , RSS-
example. com/feed/rss2. RSS Graffiti
RSS- , ,
347
.
.
WordPress Facebook, Facebook,
,
.
, ,
, .
, ?
, .
,
Facebook, Twitter Pinterest, .
, , Twitter
(Follow me on Twitter) Facebook (Find us on Facebook)
, , , WordPress
.
.
,
.
,
,
,
. , , ,
, ,
.
,
,
.
.
.
,
(Verified Accounts) Twitter,
@theReal David DamstraHonest.
,
HTML-.
, .
, .
, Social Media W idget (http://wordpress.org/extend/plugins/socialmedia-widget/) , .
348
11.
. ,
. . 11.2 .
,
.
.
, .
.
, - .
,
.
.
,
,
( , ). ,
, , .
, ,
Twitter Facebook.
, .
, , , '
. , , , Twitter ,
,
,
, Twitter.
WordPress.
, . :
, ,
349
,
. .
,
,
.
.
WordPress
. , ,
Twitter Facebook, ,
.
, ,
; ,
.
WordPress. , :
? ?
, , API
. , ,
,
.
API.
API
,
, WordPress, .
WordPress ,
P H P -,
.
8. , .
WordPress.
,
, ,
.
,
, .
2.9 WordPress oEmbed. oEmbed
,
. ,
350
11.
HTML <iframe>,
, , ,
YouTube WordPress. WordPress
, oEmbed.
YouTube
, ,
WordPress.
WordPress 2.9,
YouTube , YouTube,
Write
() WordPress. ,
, .
,
HTML, .
YouTube oEmbed,
WordPress, HTML-
URL- . URL
, , ,
,
(. 11.3).
;
1
|
1= 4 *
1
: ( / ?=23
1http://www.youtube.com/watch?v=LKHgC6ovq5E
:
: 3
15:48:35.
3 51
, WordPress
oEmbed YouTube
, . 11.4.
, *
f |#)
j Email!
New
''
. HTML,
, WordPress HTML- < if rame>
YouTube. ,
YouTube,
.
Twitter
oEmbed Twitter WordPress 3.4.
YouTube, Twitter
WordPress, URL WordPress
oEmbed . , WordPress, . 11.5,
, . 11.6.
352
11.
!
U
Brad Williame
; follow
@wllliams&a
2
1Jul 1
2
Rsply
^ ___
f Sharf
IQ j S
New
[ S Emailj
j < shareihis
so
1n u *
J I
& -
. 11.6. Twitter
oEmbed .
Twitter ,
. Tw itter API.
? API Tw itter
, . ,
.
Tw itter WordPress . ,
Twitter. ,
.
.
Tw itter WordPress
. Tw itter
353
, ,
Tw itter ,
.
Tw itter Tools ( h t t p : / / w o r d p r e s s . o r g / e x t e n d / p l u g i n s / t w i t t e r .
, ,
. , ,
, , Twitter API.
API Twitter ,
. API Twitter
, . Twitter ,
. ,
,
.
to o ls /)
, , Twitter
,
. WordPress
. Tw itter Tools
Tw itter
. Twitter (), ,
. ,
. ,
Twitter.
, .
: , .
.
Twitter,
.
T w itter Tools Tw itter
. , Twitter,
. , Twitter
, WordPress
Twitter
WordPress.
(aside). , ,
. , ,
.
, Twitter,
, ,
. Tw itter
354
11.
.
,
,
. Tw itter
, Twenty Eleven,
9, CSS ,
.
Twitter
, Twitter Tools
. ,
- .
Twitter , , , ,
.
.
. WordPress
.
, ,
, Twitter,
.
Twitter Tools
, Twitter ,
.
Twitter Tools.
Tw itter Tools ,
,
.
RSS, .
Google Maps
Google Maps ( Google), , , ,
. - ,
,
, .
, Google Maps, .
, , ,
.
, . Google
.
Google Maps.
WordPress. .
355
Facebook
Facebook .
Facebook, .
WordPress Facebook .
Automattic Facebook
WordPress Facebook;
h ttp ://w o r d p r e s s . o r g /e x te n d /p lu g in s /fa c e b o o k /.
Facebook
WordPress. Twitter, Facebook
App Facebook , .
. Facebook
CAPTCHAS, , ,
CAPTCHAS API . ,
WordPress, .
,
,
. ,
.
Facebook.
Facebook .
,
, .
Facebook
Facebook.
XML
,
,
356
11.
XML WordPress.
, .
XML, JSON
.
XML- , P H P -.
, WordPress
.
, WordPress
,
. ,
,
XML. WordPress XML-
. ,
.
.
,
. :
WordPress
? , ,
,
. ,
.
, .
,
, . , ,
, .
. ,
.
, ,
. ,
, ,
, REST API.
: ,
REST API, ,
,
WordPress. ,
, ,
.
.
functions. php, API,
.
header. php.
357
. (
, .)
functions. php get_color_of_
the_week(), :
function get_color_of_the_week() {
$feed = file_get_contents('whatever URL');
if ($feed) {
$xml = simplexml_object($feed);
$color = $xml->color;
} else {
$color="white";
>
echo $color;
>
- file_get_contents()
XML API . XML, J SON
.
XML. .
HTML-
<body>. header.php :
<body <?php body_class(); ?> style="background-color: <?php echo
get_color_of_the_week();?>" >
,
CSS. ,
XML-.
, (Theme Customizer) WordPress,
9.
, ,
HTML-, , # ff f f f,
, Papaya Whip ( ). ,
.
, .
,
, .
,
, , ,
.
, .
REST API
.
,
358
11.
.
, 12. ,
,
? ?
WordPress.
WordPress W ordPress Options
( WordPress), , , 8.
, .
,
,
.
? ,
.
, API
.
,
. ,
, ,
MultiSite.
, WordPress
.
? :
.
, ,
, : . ,
.
, , WordPress
.
13.
, .
API .
,
HTML .
-
. , ,
.
, ,
.
359
? -.
,
, .
, API ,
,
, A PI-.
,
.
, , ,
,
. ,
. ,
, ,
, .
, ,
.
, , fu n ctio n s.p h p .
,
. ,
g e t_ tra n s ie n t() fa ls e .
if (($color = get_transient('color_of_the_week')) === false) {
fa lse , ,
API . ,
HTML- P H P -,
. .
, :
$feed = file_get_contents('whatever URL');
if ($feed) {
$xml = simplexml_object($feed);
$color = $xml->color;
,
. ,
WordPress Options API (API WordPress)
.
set_transient('color_of_the_week', $color, 60*60*24*7);
.
W ordPress .
, ,
: 60 60 24 7 , .
604 800 ,
.
360
11.
,
:
function get_color_of_the_week() {
if (($color = get_transient('color_of_the_week')) === false) {
$feed = file_get_contents('whatever URL');
if ($feed) {
$xml = simplexml_object($feed);
$color = $xml->color;
} else {
$color="white";
>
set_transient('color_of_the_week', $colorj 60*60*24*7);
>
echo $color;
>
HTML,
, .
. header.php
:
<body <?php body_class(); ?> style="background-color: <?php echo
get_color_of_the_week();?>" >
,
, ,
(
) .
, .
,
WordPress
. ,
,
.
:
.
, ,
, ,
.
,
.
,
361
WordPress:
- , Google,
, Amazon,
, ,
. ,
.
. , , ,
. , ,
, , ,
, .
,
, ,
,
. ,
,
,
,
.
: (pay-per-click),
,
,
.
Google AdSense ,
Google ,
,
Google
. Project Wonderful ( )
,
, a Project Wonderful
.
, - ,
.
.
,
362
11.
,
.
,
. ,
, Amazon Associates ( Amazon),
, .
, ,
,
. ,
, - .
,
, , ,
, Facebook
. RSS, ,
RSS.
, ,
, ,
.
, ,
, ,
.
,
, .
, , ,
.
( ).
Google AdSense, ,
, ,
.
,
, ,
.
WordPress
.
363
. ,
.
, ,
. , , .
,
:
,
.
,
, ,
, .
, , WordPress
. , -
,
,
, ,
.
,
,
. ,
8,
JavaScript,
.
,
,
.
,
, 9.
, <div>
, .
,
HTML- <li> </li>.
Facebook Twitter ,
, .
, Google AdSense,
AdSense (
364
11.
), .
JavaScript, WordPress.
Google ,
.
Google (
), , Google
,
:
<script type="text/javascript"><!-google_ad_client = "ca-pub-7723xxxxxxxxxxxxxxx";
/* adsense */
google_ad_slot = "747xxxxxxxxx";
google_ad_width = 125;
google_ad_height = 125;
//-->
</script>
script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
, , JavaScript,
, AdSense.
, ,
Google, Google, , ,
, .
, ,
Google
.
. JavaScript Project Wonderful
.
, .
,
, , ,
,
.
.
, : ,
,
,
. Project Wonderful
,
,
.
365
, ,
, .
:
, .
,
. ,
:
,
. , , , , ,
, ,
. ,
: ,
, 12,
.
,
,
, .
,
, ,
(, ,
).
Google AdSense,
, ,
Google. Google
AdSense ,
, ,
, , .
,
, ,
. AdSense ,
,
, .
. , ,
,
.
, ,
WordPress
366
11.
.
, ,
.
, , .
,
, .
. ,
, .
.
,
. Google , , Internet Archive (
). , , -
, , , .
: ?, , .
Usenet:
.
. ,
, , . ,
?
- , ,
- , ,
. , -
, ,
. , , . ,
, ,
Twitter, Facebook .
, , .
.
, - Facebook, ,
,
. Flickr
.
. ,
. .
, WordPress
,
. ,
367
, ,
WordPress ,
.
, ,
.
,
. ,
.
,
.
:
WordPress
.
, , ,
, , , .
. ?
.
,
. ,
()
, . ,
. ,
.
- ,
, - .
, ,
RSS-, .
,
.
369
,
-. .
.
, , ,
. , .
, ,
.
:
?
?
?
?
( )?
.
, ,
. .
. ,
WordPress. ,
,
, , ? ,
,
.
, ,
.
, ,
.
, ,
, .
,
. , .
.' ,
. ,
, .
370
12.
,
. ,
,
.
,
. WordPress
; current_menu_item
, . HTML:
<li id="menu-item-44" class="menu-item menu-item-type-post_type
menu-item-object-page current-menu-item page_item
page-item-42 current_page_item menu-item-44">
<a title="Register Me" bref="/register-me/">
Register Me
</a>
</li>
WordPress is_page(),
( ):
<li class="benefits
<?php if(is_page('benefits')){ echo "current_menu_item";}?>">
<a title="benefits" href="/benefits/>
Benefits
</a>
</li>
current_menu_item
CSS. () ,
. ,
.
, . -,
, ,
, .
,
,
. CSS,
Twenty Eleven, :
#access li:hover > ,
#access ul ul :hover > a,
#access a:focus {
background: #5B84BA;
>
#access .current-menu-item > a,
#access .current-menu-ancestor > a,
#access .current_page_item > a,
#access .current_page_ancestor > a {
font-weight: bold;
PS
.
File
Ed't
\
Image
lay*
Type
Select
Rate* Wndorn to H
Fitter
3D
Zoom At Window
View
Window
/ Scrubby Zoom
373
Help
A rtud Prsefc
((
a-.
,
V.
h.
AdfoefjwBfi
Add *n adjiKlm wiI
>.
40
S3 E 13
.
,
'
pod
lock; I?
f! ;
Normal
f
C-p*c*r:
**'
91 *~a
Jp logo
- >
<*\
',
100% 4
100%
effort?
* S j j j j j i /Sriur...
9 H 'i
void mast
feature
Effects
M.6*.
Color Overlay
Doc: i.2SM/Zi,*t
.M ini Bridge
. n
. 12.2. , Photoshop
.
.
.
, .
,
. ,
, . ,
.
, , ,
- . ,
,
( ) .
WordPress . -,
,
. WordPress ,
372
12.
,
?
? ,
.
,
, ,
.
, - - , ,
, , ,
.
,
,
.
,
.
. ,
. '
.
, ,
,
.
. ,
. , ,
, ,
, , .
, ,
. , :
.
, ,
. ,
. ,
, . .
, , .
, , , ,
. 12.2. ,
.
,
, . ,
,
. ,
373
. 12.2. , Photoshop
.
.
. , .
,
. ,
, . ,
.
, , ,
- . ,
,
( ) .
WordPress . -,
,
. WordPress ,
374
12.
.
-, W ordPress .
, ,
.
.
-, WordPress :
,
, (. 9
). WordPress
, ,
.
. ,
,
, .
-, .
,
.
, .
,
,
.
,
,
.
. CSS ,
. AJAX JavaScript (
JavaScript-)
. iFrames, ,
, HTML- -
.
.
, CSS,
,
. , .
? ,
. , ,
375
, .
.
.
,
.
.
, , -,
.
:
, . , ,
, ,
JavaScript , .
,
Facebook,
, ,
. ,
, , ?
- -,
? , ,
. ,
, .
Firebug
.
Google Chrome ,
. , Yahoo! Google Firebug
Chrome Developer Tools ( Chrome)
: YSlow (http://developer.yahoo.com/yslow/) . Page
Speed (http://code.google.com/speed/page-speed/) .
YSlow Page Speed ,
. ,
. , ,
, . YSlow
(CDN, Content Delivery Network). ,
CDN ,
,
? ?
, , ,
Yahoo! Google.
.
, :
, ,
.
Apple .
376
12.
JavaS cript .
JavaScript CSS.
,
.
Facebook
. ,
11.
MySQL
.
, , . ,
, ,
, .
.
, 13 , ,
.
,
.
JavaScript
JavaScript :
(
) jQuery. JavaScript
,
. jQuery
. ,
, JavaScript
. ,
. , JavaScript
, ,
. ,
.
, , JavaScript
. .
JavaScript
, .
, - JavaScript ,
, ,
.
,
.
377
. ,
, .
, ,
(),
. - , ,
, . , ,
, .
, ,
, , ,
, , . .
,
, .
, .
, , , ,
, . ,
.
------------------------------- -------------------------------------------
,
, 300
http://www.uie.com/articles/three_hund_million_button/.
? /- , .
.
.
,
.
, . ,
, Google
, .
/- WordPress,
, .
Content Experiments ( ) Google Analytics
.
378
12.
, BTwitter. .
, .
.
, ,
. , ,
, , .
,
, .
, , ,
,
. ,
.
,
.
.
,
. ,
.
,
WordPress. -,
.
,
..
.
, ,
.
,
.
. ,
, ,
$*
.
(
W ordPress).
,
. ,
^ , .
,
^ ,
379
-.
WordPress
. ,
.
WordPress, ,
,
.
WordPress, ,
QuickPress .
.
,
.
,
, , -
, ,
.
, ,
. WordPress .
,
. .
, ,
,
.
3000 . ,
,
. ,
,
, ,
.
()
.
- -:
. ,
.
, ,
.
, : . ,
380
12.
,
, .
, .
,
, - ,
. .
,
.
, ,
, ,
.
:
, , .
,
,
.
. -:
. 2006 , (http://
www.useit.com/alertbox/reading_pattern.html), ,
, ,
. 2006
,
.
-, . :
, .
,
?
. .
.
, HTML (
). -.
,
, , . ,
, , ,
.
38 1
,
? :
WordPress
:
WordPress
?
?
,
.
, .
.
,
? .
, .
, . ,
. , -,
, ?
(SEO)
.
WordPress.
, ,
,
. .
, WordPress (URL)
( http://example.com/?p=100).
382
12.
,
.
: http://example.com/?p=42 http://example.com/this-is-the-informationyou-want, ? .
, .
,
. ,
WordPress, ,
. 12.3. , ,
.
Studio ShWeb
sr
flfj
Ggj
&
. ,
http://txtetn<y.ri/jM 4/*i/j4/sapl-pM t/
httei//textagncy.ru/3Mpl#-jKJSt/
f$>
"fi
/Kpo&tnaceV
, URL- topic
http://exenple.art/toplC3/uncatetcr1/
Plugm Update
'*)
. 12.3.
, ,
.
Post ( ),
/%postname%/.
, ,
.
WordPress
. ,
.
W ordPress 3.3
383
,
.
,
. ,
,
: http://example.com/category/cool-stuff/. category
.
,
, ,
.
--------------------------------------------------------------------------- - (http://
shiflett.org/blog/2008/mar/urls-can-be-beautiful), ,
. OmniTI,
- , http://
omniti.com/is/hiring http://omniti.com/helps/national-geographic.
, , , ,
( SEO-)
,
. ,
.
WordPress .
,
.
, , .
, ,
.
,
, . , Google
crawler ( Google), ,
.
,
, , , .
:
, WordPress single.php;
384
12.
Google
-
HTML
23 2014 .
,
HTML
( title)
( title)
( title)
( title)
( title)
, . , Bing.com
Microsoft .
, robots.txt. robots.txt
, .
, . robots.txt
, . , ,
, ,
robots.txt:
S it e m a p : h t t p : //w w w .e x a m p le . c o m / s it e m a p . xm l
U se r-a g e n t: *
D is a llo w : / c g i - b i n /
D is a llo w : / w p -a d m in /
D is a llo w : / w p - in c lu d e s /
D i s a l l o w : / w p - c o n t e n t / p lu g in s /
385
Disallow: /wp-content/cache/
Disallow: /wp-content/themes/
Disallow: /trackback/
Disallow: /feed/
Disallow: /comments/
Disallow: /category/*/*
Disallow: */trackback/
Disallow: */feed/
Disallow: */comments/
Disallow: /*?
Allow: /wp-content/uploads/
, .
ro b o ts . t x t , .
Google ,
.
.
,
, : , ,
.
, .
WordPress ,
, ,
.
.
Twenty Eleven ,
twenty_eleven(), fu n c tio n s .php:
switch ( $comment->comment_type ):
case 'pingback' :
case trackback' :
?>
<li class="post pingback">
<px?php _e( 'Pingback:', 'twentyeleven' ); ?> <?php comment_author_link(); ?>
<?php edit_comment_link( __( 'Edit', 'twentyeleven' ),
'span class="edit-link">', '</span>' ); ?></p>
<?php
break;
default :
?>
<li <?php comment_class(); ?> id="li-comment-?php comment_ID(); ?>">
article id="comment-?php comment_ID(); ?>" class="comment">
,
,
. fu n c tio n s . php Twenty Eleven,
386
12.
.
-.
,
, ,
. , ,
.
, ,
. , WordPress ,
Ping-o-Matic, .
, WordPress,
. .
. ,
, ,
. ,
, , .
RSS-
, .
, Ping-o-Matic,
. http://pingomatic.com/, ,
. .
Technorati.com ,
. Technorati
www.Technorati.com. ,
, Technorati,
.
Technorati, , .
Technorati WordPress, -,
.
, Facebook,
Reddit Twitter. , 11
,
.
, , ,
.
.
, RSS-
387
, .
.
-
HTML . HTML
,
. HTML-
. ,
.
. , ,
. ,
, ,
.
.
. , , .
,
, CSS HTML.
HTML.
HTML
POSH HTM L (Plain old
semantic HTML).
HTM L .
CSS. , ,
CSS Zen Garden...
POSH?
. -, . ,
HTML,
.
-, .
HTML ,
. :
<div style="
background: #F0CCFA;
border: lpx solid # D894EB;
color: #f00;
font-size: 2em;
388
12.
margin: .25em 0;
padding: .5em;">
This is my subheading
</div>
:
<h2>This is my subheading</h2>
. CSS
<font> ,
HTM L-. HTML .
.
, : HTML
. ,
CSS-.
.
. HTML
,
.
, HTML
. . ,
,
. . .
HTML , .
. HTML-
. , HTML
.
. :
.
CSS ,
HTML-:
<div class="pagetitle">My Site Is About Something Important</div>
<hl> , ,
, .
<hl class=,,pagetitle">My Site Is About Something Important</hl>
,
. ,
<hl>
.
<hl> ,
389
. ,
, ,
<hl> .
<hl> ; <h2>
. ,
.
a lt.
, .
.
<div> , <> .
<> <strong
. HTML5
, <header>, <footer> article .
.
(<1>) (<ul>)
.
, ,
<br /> .
(dl),
, .
HTML- .
, HTML
.
W3C .
,
, , ,
.
HTML
HTML
CSS. . ,
. ,
, .
,
, . - ,
.
HTML .
,
.
, . ,
,
, . -
390
12.
. HTML
.
. :
. ,
,
. ,
HTML
.
.
HTML ,
, . HTML ,
,
.
, ,
.
HTML , ,
.
, . , Google
Webmaster Tools ( - Google) , ,
.
HTML ,
W3C, Markup Validation Service ( ),
http://validator.w3.org/. ,
W3C.
POSH.
HTML ,
HTML-. , ,
,
XML HTML.
HTML ,
. ,
, .
, .
, Technorati .
r e l Technorati.com , ,
, Technorati.
:
< href="http://technorati.com/tag/wordpress" rel="tag">WordPrss</a>
39 1
, WordPress,
XFN ( XTHML).
,
.
blogroll ( ).
,
, ,
, . , ,
. 12.5.
(XFN)
rel:
()
, .
.
. 12.5. XFN-
HTML :
< title="WondPness.org" rel="friend colleague muse"
href="http://WordPness.org"WordPress.org</a>
. . -
. Internet
Explorer r e l
C S S .
, ,
,
. XFN
http://gmpg.org/xfn/.
hCard. hCard
. ,
HTML,
, Microsoft Outlook Mac OS X Address Book.
392
12.
hCard:
<div id="hcard-David-Damstra" class="vcard">
<a class="url fn" href="http://mirmillo.com">David Damstra</a>
<div class="org">Professional WordPress</div>
<div class="adr">
<div class="street-address,>123 Main Street</div>
<span class="locality">Grand Rapids</span>,
<span class="region">MI</span>,
<span class="postal-code">49525</span>
</div>
</div>
, , .
hCard .
vCard,
.
hCard ,
.
, ,
.
, .
, ,
, .
GeoMark,
GEO, ,
RSS- .
- , .
, ,
.
, de facto
.
, ,
.
.
,
-
. ,
,
,
, . ,
.
39 3
HTML5
HTML,
HTML5. , WordPress,
.
HTML5? HTML,
- .
. ,
HTML. ,
,
, , Web 2.0 2000 . ,
- HTML5, ,
HTML5 , HTML5,
CSS3 Javascript.
HTML5. HTML5?
, ,
, ,
, ,
.
HTML5 , , ,
, . HTML5
HTML, .
.
WordPress , <div
id="header"> <div id="footer"> ,
. HTML5 <header> <f ooter> .
, WordPress,
<nav>, < article> <aside>.
, , , <a r ti c le
W ordPress. Twenty Eleven
. Twenty Eleven
HTML5 ,
,
.
HTML5
HTML5 Boilerplate , http://
html5boilerplate.com/. WordPress,
HTML5
. , WordPress,
HTML5 Boilerplate.
394
12.
- HTML5:
, Microsoft,
Internet Explorer 9. . JavaScript,
HTML5
. Twenty Eleven HTML5Shiv (http://
code.google.eom/p/html5shiv/) .
, HTML5 Boilerplate, modernizr. js http://
modernizr.com. Modernizr HTML5Shiv,
HTML5,
,
HTML5 CSS3. ,
.
, HTML5
JavaScript.
HTML5. , Twenty Eleven ,
Automattic.
, ,
.
HTML-, HTML5
. ,
,
, .
, , http://caniuse.com.
,
,
HTML5, CSS3 . ,
JavaScript, HTML5Shiv Modemizr.js.
.
, ,
.
HTML5 ,
, .
.
.
, ,
, .
.
HTML5 , : http://
www. html5 rocks, com.
395
CSS3
3, CSS3.
.
CSS3
. ,
, CSS- 3 -4
.
, http://caniuse.com ,
CSS3, .
, ,
. .
, ,
,
. .
.
-,
. CSS3
, ,
, JavaScript. CSS3
border-radius.
. border-radius www.caniuse.com, ,
Internet Explorer 7 8 ,
, .
.
Internet Explorer, .
, , , .
: ( )
, ( )
. ,
, , ,
, , .
CSS3
.
. .
HTML5 ,
,
. CSS3
.
396
12.
,
.
,
,
, , .
,
? ?
: , . SEO, ,
. ,
. WordPress.
W ordPres, ,
. , W ordPress ,
.
W ordPress ,
. , ,
.
, . WordPress
.
W ordPress. ,
. .
, ,
. .
.
,
, ,
.
.
.
, , ,
, , - .
, ,
-
, ,
, .
397
,
. ,
. ,
.
. , ,
, . WordPress ,
.
, WordPress. WordPress
.
, W ordPress
keywordl AND keyHord2.
, . ,
WordPress AND ,
, AND. ,
.
WordPress 0R.
keywordl OR keyword2 keywordl OR keyword2.
, WordPress 0R .
.
, 0R
,
. , , WordPress
.
, WordPress
. ,
. ,
. ,
, CSS.
WordPress ,
, MySQL LullText,
, Lucene Sphinx. , WordPress ,
,
.
,
, ?
,
. .
,
WordPress ,
.
398
12.
, ,
.
,
.
, .
, ,
.
WordPress.
Search Everything (http://wordpress.org/extend/plugins/search-everything/)
Sprout Venture WordPress search,
, ,
. Search Everything
,
.
Relevanssi (http://wordpress.org/extend/plugins/relevanssi/)
, . ,
-, .
,
, , .
, ,
Google.
AND OR. , ,
. , ,
.
Google Custom Search Engine ( http://www.google.
com/cse/). Google Custom Search Engine (CSE) , Google
. Google
Custom Search Engine .
, Google
Ads. $100
Google, .
WordPress .
Google CSE .
, Google.
9, , .
Google Custom Search Engine
. ,
. .
399
. .
, ,
Google Custom Search Engine.
WordPress,
, .
, , , :
< ?php
/*
* Template Name: Google Search Results
*/
get_header(); ?>
<div id="primary">
<div id="content" role="main">
<!-- google search engine results -->
</div><!-- #content -->
</div><!-- #primary -->
<?php get_footer(); ?>
, ,
, Google.
WordPress .
, ,
. .
, ;
Google.
, WordPress. ,
. ,
Google, .
, .
, , ,
Google .
Google Custom Search
Engine, , Google Analytics
Google Webmaster Tools. ,
Google Custom Search Engine, Refinements ()
Promotions () .
-
,
400
12.
,
. Forrester, ,
,
(http://blogs.forrester.com/susan_huynh/12-02-21-mobilejnternet_users_will_
soon_surpass_pcJnternet_users_globally). Google ,
Google+ ,
( http://www.engadget.com/2012/06/27/google-has-250-million-users-more-mobile-thandesktop/). ,
(http://mashable.com/2010/04/13/mobile-web-stats/).
,
. ,
.
?
? API
. , .
, ,
. ,
. ,
.
,
.
, ,
, .
, .
, .
, , ,
,
, ,
.
. ,
, .
.
.
401
WordPress.
,
.
. ,
,
, .
W PTouch , iPhone.
WPTouch Brave New Code,
http://wordpress.org/extend/plugins/wptouch/.
, ,
.
AJAX ,
. , WPTouch ,
.
WPTouch
.
, .
iPhone W PTouch CSS
, . WPTouch
.
: -, ,
,
,
WPTouch
. -,
-. iPad
, ?
Amazon Kindle, ?
- WiFi
?
.
. -
A List Apart 2010 (http://www.
alistapart.com/articles/responsive-web-design). , -
CSS3, ,
402
12.
,
. ,
.
,
CSS. .
. CSS3.
, ,
. , CSS3, ,
.
CSS,
.
- WordPress
, ,
.
WordPress
.
, .
.
, , ,
. , ,
,
. ,
.
, .
,
. , ,
. ,
WordPress, Twenty Eleven, ,
.
-
, .
, .
, . -
, Netscape Navigator Internet
Explorer? ,
,
, , . ,
.
,
, .
,
, .
403
.
,
. ,
,
.
, .
, ,
, .
HTML5 CSS,
.
, ,
.
,
,
:
-
\!88
, ,
,
WordPress. ,
?
, .
,
; ,
, ,
.
,
, ,
. , ,
. ,
,
. ,
, ,
405
,
.
,
.
.
.
-. -
, - ,
.
.
, JavaScript,
, ,
.
, , .
WordPress. ,
. ,
, : ,
,
. ,
, .
Google,
,
,
.
,
, ,
( ), ,
.
AWStats
AWStats
. ,
,
AWStats.
AWStats -.
, -
,
,
406
13. , ,
Number of visits
3047472
(4.6 visits/visitor)
407
Bandwidth
49737034
(16.32 Pages/Visit)
50678792
(16.62 Hits/Visit)
32151728
32174101
4 6 2 .0 7 GB
(158.98 KB/Visit)
Not viewed traffic indudes traffic generated by robots, worms, or replies with special HTTP status codes.
Monthly history
Jan Feb Mar Apr May Jun Jul Aug S e p Oct Nov Dec
2012 2012 2012 2012 2012 2012 2012 2012 2 0 1 2 2012 2012 2012
Month
Unique
Jan 2012
Feb 2012
Mar 2012
Apr 2012
May 2012
Jun 2012
Jul 2012
Aug 2012
Sep 2012
Oct 2012
Nov 2012
Dec 2012
Total
648310
650534
662955
654564
649417'
638883
654160
662395
145041
0
0
0
5366259
Number of
visits
2949878
3031258
3028353
2929149
2966247
2875241
2940042
3047472
225150
0
0
0
23992790
50304631
50810947
50504129
47242966
47158628
45941287
47478869
49737034
3354225
0
0
0
392532716
Hits
Bandwidth
50992102
51548116
51415205
48579448
47871343
46852571
48183809
50678792
3420926
0
0
0
399542312
486.11 GB
488.82 GB
480.83 GB
432.83 GB
434.60 GB
425.76 GB
441.58 GB
462.07 GB
31.07 GB
0
0
0
3683.67 GB
Days of month
01 02 03 04 OS 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Aug A u; Aug A t; A t; Aug Aug Aug Aug Aug Aug Aug Aug Aug Aug Aug Aug Aug Aug A uj Aug Aug Aug Aug Aug Aug Aug Aug Aug Aug Aug
Day
01 Aug 2012
02 Aug 2012
03 Aug 2012
121850
122613
118483
2008393
2021480
1963140
Hits
Bandwidth
2190589
2085840
1984421
18.22 GB
18.36 GB
18.05 GB
Average
. 13.1. \/5115
://\/5115.
sourceforge.net/.
\511
,
.
, 11,
,
- .
408
13. , ,
JavaScript,
,
, JavaScript, AWStats
.
Google Analytics
Google Analytics ,
. ,
, ,
.
JavaScript ,
Google .
- ,
,
Google. Google
, ,
-, -
, ,
. Google,
. ,
Google;
Ad Sense
, . Google
AdWords AdSense ,
Google Analytics.
, -
, .
.
Google Analytics, , .
,
,
. , Google Analytics
pdf- ,
email- ,
. Google
Analytics .
, jQuery,
Google Analytics.
http://css.dzone.com/news/update-trackingoutbound-click.
409
/ * j q u e r y ,
* h ttp ://cs s.d z o n e ..co m /n e w s /u p d a te -tra ck in g -o u tb o u n d -clic k
*/
$ ( " a " ) .c lic k ( fu n c tio n ( ) {
v a r $a = $ ( t h i s ) ;
van h r e f = $ a . a t t r ( " h r e f " ) ;
/ / ,
i f ( ( h r e f . m a t c h ( / Ah t t p / ) ) && ( ! h r e f . m a t c h ( d o c u m e n t . d o m a in ) )
/ / ,
var c a te g o ry = "o u tg o in g ";
/ /
v ar event = " c lic k " ;
/ /
var la b e l = h ref;
/ /
_g a q .p u sh ([ '_ tra c k E v e n t' ] , c a te g o ry , event, h r e f) ;
) {
>
;
v a r f i l e T y p e s = [ " d o c " , " d o c x " , " x l s " , " p d f ,,, " p p t " j " p p t x " , " r t f " , " t x t " ] ;
$ ( " a " ).c lic k (fu n c tio n () {
v a r $a = $ ( t h i s ) ;
var href = $ a .a ttr("h re f");
var hrefA rray = h r e f . s p lit ( " . " ) ;
v a r e x te n s io n = h r e f A r r a y [ h r e f A r r a y . le n g t h - 1];
i f ( $ . i n A r r a y ( e x t e n s i o n , f i l e T y p e s ) != - 1 ) {
_ g a q . p u s h ( [ ' _ t r a c k E v e n t ' ] , "d o w n lo a d " , e x t e n s io n , h r e f ) ;
>
,
-
, ,
. ,
, , .
, ,
OpenOffice, PhotoShop
.
Google Analytics WordPress,
.
,
JavaScript .
. . 13.2
Google Analytics.
http://google.
com/analytics/.
Google Analytics
.
.
Google, . http://statcounter.com/,
- StatCounter,
http://haveamint.com/, Mint. ,
13. , ,
410
I Google Analytics
Settings
Home
Standard Uepoiiinrj
Custom Repotting
Ad m in
Sign out
H elp '/
Visitors Overview
A d vanced S e g m e n t*
My Account
Export
A dd to D ash b o ard
S h o r tc u t
A ud ie n ce
% ofvlsits: 100.00%
O v e r v ie w
O v e r v ie w
Demographics
V e ts *
Behavior
Technology
V isits
Mobile
200.000
v s.
Select a metric
Hourly
Day
W ee k
M onth
* Custom
Visitors Flow
Advertising
Traffic Sources
Aug 8
H I Content
j Conversions
w -W
v - v -v -v - Unique Visitors:
1,002,801
Pageviewt: 6,801,938
Pages /Visit: 2.00
Avg. Visit Duration:
00:03:28
8 0 .8 6 % Returning Visitor
2.762,060 V sl.
1 9 .1 4 % New Visitor
651,523 Veto
WordPress JetPack
JetPack,
WordPrss.com. ,
, ,
WordPress.
, ,
, ,
, ,
.
) JetPack Google Analytics:
JavaScript HTML,
411
WordPress.com .
^ WordPress,
.
, , ^ ,
. ,
1, ^
. , ^
.
, . 13.3.
Stats for September 4, 2012, 9:44 am
At A Glance
Days
W eeks
M o n th s
H u m a n iz e
200
ISO
100
111II
. 1 1
..... _
. .1 M l l l l l M . _ _ i l l l i - . _ B _
1 6 ,0 6 0
169
views all-time
yimtrtw
Summary Tables
2012
Referrers
Clicks
Subscriptions
JetPack ,
48 ,
. http://
jetpack.me/.
(
, , -
) , ,
WordPress.
412
13. , ,
WordPress ,
. ,
.
,
, ,
HTML-,
.
WordPress, ,
.
:
, , ,
.
,
MySQL.
, ,
,
, ,
.
WordPress :
.
CSS,
JavaScript.
, 12, ,
.
-. WordPress ,
,
-. -
WordPress.
WordPress. , WordPress,
,
MySQL, ,
Facebook.
(HTML) ,
. ,
11,
, .
413
MySQL.
,
.
WordPress, .
,
, -,
, - ,
,
WordPress.
WordPress
-, W ordPress , .
W ordPress
, .
, ,
.
,
. , W ebGrind
KCacheGrind,
,
-. , ,
W ordPress , .
,
, ,
860 (. 13.4).
w e b g r in d - 0
Show
profiling in a ie browser
percent
u p d a te
C:\www\wordpress\index.php
cacheorind.out1346763864.4252
Fu n c tio n
in v o c a tio n C o u n t
TotJ Se Cost
T o ta l In clu s iv e C o a t
5 2 .7 5
7 9 .0 3
6 .5 7
33
4 .5 7
4 .3 0
5 .6 1
i loacMemplete
3 .1 9
1 6 .0 6
2. a i
2 .8 1
r twentyeleven_setup
2 .2 0
2 .6 1
9 9 .9 5
php: mysql_query
1 .5 9
appiyjiers
2442
1. 46
3 .6 0
get_option
325
1 .4 6
4 .9 0
1 .3 0
1 .3 1
1. 15
so. 16
, WP_Object_Cache->get
772
0.85
1 .5 4
. 13.4.
\/
414
13. , ,
WordPress ,
. WordPress
,
.
,
,
, , ,
, .
. W ordPress ,
. , WordPress,
, ,
.
, W ordPress
.
WordPress,
.
, - , - .
.
WordPress Twitter (,
2, ),
30 . ,
, ,
,
- MySQL.
-
WordPress -
, -.
-.
MySQL ,
WordPress
HTML-.
, .
. ,
.
415
.
. (
) ,
.
WordPress ,
.
.
,
WordPress.
.
,
. http://us3.
php.net/manual/en/book.apc.php. , ,
/ -
.
-
,
. -
.
, ;
, -.
- http://us3.php.net/manual/en/
book.memcache.php http://memcached.org/.
WordPress MySQL. 6, WordPress
, SQL,
MySQL,
,
,
,
. WordPress
, -,
,
SQL.
, ,
. ,
.
WordPress
( ) php. ini.
,
416
13. , ,
. , .
ph p .in i .
, .
. .
:
; H i d e f o r s e c u r i t y
expose_php = O f f
;T urn o f f f o r pe rform a nce
re g is te r_ g lo b a ls = O ff
re g is te r_ lo n g _ a rra y s = O ff
re g is te r_ a rg c _ a rg v = O ff
m ag ic_ q u o tes_ g p c = O f f
m a g ic_ q u o te s_ ru n tim e = O f f
m a g ic _ q u o te s _ s y b a s e = O f f
,
-. -,
,
. , ,
. , , Apache
,
. , .
, Apache.
Apache
(,
) Apache PreFork.
,
. ,
Apache2 ( ,
Apache2):
<I f M o d u l e m pm _prefork_ m o d ule >
StartServers 3
M in S p a re S e rv e rs 3
M axSpareServers 3
S e r v e r L i m i t 50
M a x C l i e n t s 50
M a x R e q u e s t s P e r C h i l d 1000
< / I fM o d u le >
, .
417
,
,
- WordPress.
,
.
, LAMP
,
. ,
. ,
.
LAMP
. WordPress, LAMP
.
LAMP
. -
,
.
WordPress
-
.
WordPress
, ,
, - WordPress
.
.
, 11,
,
WordPress.
, ,
. -
-, , ;
WordPress -
. ,
- -
WordPress, , .
,
418
13. , ,
, , ,
Reddit Slashdot. , ,
HTML,
. , ,
-.
, W PSuper Cache, . WP-Super Cache
W P-Cache . ( , .) WP-Super Cache ,
HTML.
HTML- mod_rewrite,
Apache.
W P-Super Cache ,
.
.
, W3 Total Cache.
,
HTML-
URL, .
,
WordPress.
, -
, MySQL ,
WordPress , ,
,
.
11 ,
. ,
, .
,
.
11 .
. , fu n c tio n s. php
, WordPress,
, .
,
.
419
,
SQL.
,
.
MySQL
,
WordPress ,
Twenty Eleven. ,
.
WordPress 20 MySQL. ,
fo o te r, php:
<?php e c h o g e t _ n u m _ q u e r i e s ( ) ; ?> q u e r i e s .
<?php t i m e r _ s t o p ( l ) ; ?> s e c o n d s .
,
, .
, , , ,
, ,
. URL
MySQL 5, 6
, ,
, .
WordPress ,
MySQL. MySQL
WordPress,
MySQL. MySQL
se le c t ()
,
.
, ;
.
MySQL,
MySQL>Ha , , ,
.
MySQL , :
# e n a b l e 16 MB c a c h e
q u e ry _ c a c h e _ size
= 16M
.
MySQL
420
13. , ,
.
.
MySQL, .
W o rd P re s s
- , ,
, .
WordPress,
.
,
, ,
. ,
, , .
, ,
.
.
DNS
HTTP
, cookie- .
,
.
, Pound (http://www.apsis.ch/pound/),
, F5 BIG-IP (http://www.f5.com/products/
big-ip/).
.
,
( ) . ,
,
, (
) ,
.
.
WordPress
WordPress. /wp-content/uploads/.
Settings () Media
Dashboard ( ).
URL.
, .
,
WordPress
421
. , NFS/Samba,
,
MySQL. rsync
.
,
. rsync (
) ,
.
.
,
. ,
.
.
- .
, ,
,
,
.
.
,
MySQL. MySQL
-.
,
,
. , MySQL,
.
,
.
, WordPress
. HyperDB ( http://codex.
wordpress.org/HyperDB) Automattic ,
WordPress.com
. HyberDB ,
WordPress, ,
,
. , ,
.
, , ,
.
422
13. , ,
,
. , ,
,
WordPress , .
, , ,
WordPress
.
,
.
,
, , .
. ,
(),
.
, ,
: ,
, URL -
.
,
.
, Google,
, .
,
.
:
,
.
, ( )
, ,
. ,
, ,
; ,
, - ,
.
,
wp-comments.php WordPress,
. ,
.
423
. ,
.
.
,
.
,
.
.
. ,
,
.
,
.
,
, .
IP -, ,
.
.htaccess. , -
, ,
IP -, ,
. , IP -
- ,
.
()
,
. ,
WordPress,
. Math Test,
:
,
,
.
,
, 20%, , ,
, - .
424
13. , ,
, ,
, ,
.
W P-Spam :
, .
JavaScript
,
,
.
.
Settings () Discussion ()
Comment Moderation ( ).
, , .
,
,
. -.
, ,
,
. ,
, watches ( watches
, ),
, , .
,
, .
, WordPress Akismet,
, .
http://akismet.com/, API (
) ;
Akismet , ,
WordPress Akismet.
Akismet
Automattic ,
. ,
akismet.com, 80% ;
,
55 .
, , Akismet
. Akismet
WordPress
425
. Akismet
0 50 .
WordPress
, Akismet,
.
WordPress Akismet
,
.
W o rd P re s s
, ,
. WordPress -,
. ,
, ,
. ,
WordPress ( , ) ,
,
.
,
WordPress.
, , ,
.
, ,
. :
. , ,
,
.
1 . WordPress
,
.
. ,
, ,
, .
, .
WordPress,
.
426
13. , ,
WordPress ,
.
WordPress . W ordPress
,
.
WordPress -.
WordPress,
.
WordPress FTP
. . ,
. , ,
-. , ,
, , -
, .
, ,
FTP. ,
FTP (
) - , .
,
WordPress wp-config,
FTP.
WordPress
.
.
WordPress, .
, ,
. ,
,
,
.
.
WordPress
WordPress.
. WordPress
, , ,
. , , ,
, .
WordPress
427
.
?
, WordPress
: - , -
WordPress, -
, ,
. - ?
- , WordPress,
;
.
WordPress
HTML , ,
. ,
, , .
fu n c tio n s.php, :
remove_action('wp_head', 'wp_generator');
:
, .
WordPress.
.
WordPress ,
,
.
Limit Login Attempts
.
IP-, ,
.
. Limit Login Attempts
h t t p : / / w o r d p r e s s . o r g / e x t e n d / p l u g i n s / l i m i t - l o g i n - a t t e m p t s / .
, ,
WordPress. ,
,
. WordPress
JavaScript,
428
13. , ,
. -,
, .
, .
, .
WordPress wp_.
, WordPress
,
.
- .
, ,
. W P-Security Scan
, ,
.
,
.
WordPress
-. ,
,
,
.
wp-config
, . WordPress
, .
-
.
. htaccess , wp-config.
.htaccess, ,
:
< F i l e s M a t c h Aw p - c o n f i g . p h p $ > d e n y f r o m a l l < / F i l e s M a t c h >
WordPress 2.6 wp-content.
WordPress
.
, , .
WordPress
429
wp-config:
d e f i n e ( ' WP_CONTENT_DIR' ,
$_SE RVER[ ' DOCUMENT_ROOT' ] . ' /mys i t e / w p - c o n t e n t ' ) ;
d e f i n e ( ' WP_CONTENT_URL' ,
' h ttp :// e x a m p le .c o m / m y s ite / w p -c o n te n t
');
.
wp-config,
:
d e fin e ('W P _ P L U G IN _ D IR ',
$ _ S E R V E R [ ' DOCUMENT_ROOT ] . ' / m y s i t e / w p - c o n t e n t / p l u g i n s '
d e f i n e ( ' WP_PLUGIN_URL
h t t p : / / e x a m p l e . c o m / m y s i t e / w p - c o n t e n t / p l u g i n s ' );
'
1,
);
,
.
,
W ordPress , ,
.
, , ,
.
conf ig WordPress
. WordPress 2.6
, , , WordPress
,
. ,
,
.
, . ,
WordPress.
, . ,
https://api.wordpress.Org/secret-key/l.l/salt
.
, ,
, .
d e f i n e ( ' AUTH_KEY' ,
' C?m92_K%B[ 7 , , O n l ( & W G , o o d C 9 u e l y ; a U K [ e , . E+([Y?0D + / ] i * ! PkF ? I : U+CA6 ' ) ;
d e f i n e ( ' S E CUR E_AU TH_KEY',
1o e s V ) E . Z<y@o. o l e M | c @ 7 ) t AS L : 0 6 W j D E N o ; t _ j . e 4 ( @ 8 ~ g y l S & R * G f ! k l 9 + 1) ;
430
13. , ,
d e f i n e ( LOGGED_IN_KEY' ,
'Y?fgU+EleuDKE3n-A~cF%IbgTR,ep+UZE={>8,j,E0+7a-u|]EH;|G@|4ZS#a+-');
define( 'NONCE_KEY',
' g6f<q6QBI l u 5 9 Q ] ~ ( r l B @ < d l2 f ] r k Q V g 7 H M x } ! B # O z P P y G [ . N { R V < y A 2 l+ = . r 7 # ' ) ;
d e f i n e ( 'AU T H _S A LT',
)e@Vd [W0d}? u&Ps> M yOlN ZT> tU [Kg4QW% + y-fyRU|d-PW AV7az+ a0K6qx-{iw Sv)
d e f i n e ( 1SECURE _AUTH_ SALT' ,
'9 N b t g _ v lD } ? f / r j * / p ; a [ ) } j q - y & Y V x q A 6 . K S k ; a m : s j H > - ! u N 6 n 5 ] i? N I u W & 9 < l');
d e f i n e ( ' LOGG ED_IN_SALT ,
' pQ;TXDxRN' T m D l $ + g U 0 E g G - l O M Y M * [ p 6 R } 0 7 ) 7 F s * / % Y e c ] t I E + p i q L f l . t 2 k L T c 1);
d e f i n e ( 1NONCE_SALT1,
~ < A 7 * 5 I S & N : G y !: y Y M 'L u g g B 0 Al R I j S y : Q E O P @ . T Z s ! D q - 7 3 i 3 K Q Y a : 3 j l W Y I e U g ' );
He , .
SSL
SSL , .
conf ig WordPress, :
d e f i n e ( 1F 0 R C E _ S S L _ L 0 G I N ' , t r u e ) ;
W ordPress HTTPS.
, , conf ig,
:
d e f i n e ( ' FORCE_SSL_ADMIN
',
tru e );
, .
,
. , WordPress
URL, .
, SSL
, URL
, .
. -
.
Apache
,
644, 755.
, .
, -,
, :
drw xr-xr-x
drw xr-xr-x
8 d d a m s t r a www-data
8 ddam stra r o o t
40 96 2 0 1 2 - 0 9 - 0 2 1 6 : 3 4
40 96 2 0 1 0 - 1 2 - 1 8 2 0 : 3 9
.
..
WordPress
--TW- - - - 1 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
-rw xrw xr-x
1 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
-rw xrw xr-x
1 d d a m s t r a www-data
-rw xrw xr-x
1 d d a m s t r a www-data
drw xr-xr-x
6 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
d r w x r - x r - x 10 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
drw xr-xr-x
7 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
drw xr-xr-x
9 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
- r w - - - -- 1 d d a m s t r a www-data
- rw - - - - 1 d d a m s t r a www-data
1 d d a m s t r a www-data
- r w - - - - 1 d d a m s t r a www-data
- r w - - - - - r w - - - - - 1 d d a m s t r a www-data
- r w - - - - - 1 d d a m s t r a www-data
9835
41 662
34 56
395
91 77
1137
514
40 9 6
4264
40 9 6
13 54
271
3522
3177
40 96
2726
40 9 6
1997
2341
29084
7712
99 16
18 299
37 00
27 88
2011-03-15
2010-12-07
2010-12-07
2012-09-02
2012-09-02
2011-07-13
2011-07-13
2012-09-02
2012-09-02
2012-09-02
2012-09-02
2012-09-02
2012-09-02
2011-02-24
2010-11-30
2012-09-02
2012-09-02
2011-02-24
2012-09-02
2012-09-02
2012-09-02
2012-09-02
2012-09-02
2012-09-02
2012-09-02
13
15
14
16
16
09
09
16
16
16
16
16
16
09
15
16
16
09
16
16
16
16
16
16
16
17
04
51
34
34
07
07
35
34
34
34
34
34
15
57
34
34
15
34
34
34
34
34
34
34
431
a p p le -to u c h -ic o n .p n g
fa v ic o n .ic o
.h ta cc e ss
in d e x .p h p
readm e.htm l
site m a p .x m l
site m a p .x m l.g z
. sv n
w p - a c t i v a t e . php
w p-a dm in
w p-app.php
w p - b l o g - h e a d e r . php
w p-com m e nts-post.php
w p -c o n fig -sa m p le .p h p
w p-content
w p-cron.php
w p -in c lu d e s
w p -lin k s -o p m l.p h p
w p -lo a d .p h p
w p -lo g in .p h p
w p -m a il.p h p
w p - s e t t i n g s . php
w p -sig n u p .p h p
w p-trackback.php
xm lrp c.p h p
,
, ,
, .
WordPress FTP
.
.
MySQL
MySQL .
WordPress
MySQL. WordPress
. ,
. ,
WordPress
.
. , -,
, .
WordPress.
432
13. , ,
WP-Security Scan
WP-Security Scan, , . 13.5,
WordPress.
,
WordPress, .
,
, . WP-Security
Scan
. ,
.
W P-Security Scan http://
wordpress.org/extend/plugins/wp-security-scan/.
(jfSl WP-Security Admin tools by Website Defender
About Website Defender
Initial Scan
W o rd P re s s versio n : 3.4.1
tou h ave the latest stable
version of W ordPress.
Your table prefix IS not wo
______ . . ....
.. . . J r . ___ ___,__
rour W ordPress version u successfully hidden.
W ordPress OS Errors turned oft.
WP
META tag removed form W ordPress c o r e
No user "admin".
The file .htaccess does not exist in wp-adrnin/.
I"-'
ID
'
IVP S e c a n t. >
Scan p lu g in m u s t t e m a i n
features re pers.-sr1'
,s
L o g in h e re if y o u a lr e a d y h a v e a W S D a cco u n t.
a c t h e for security
Email:
Passw ord:
Login
R e g is te r h e re to u se a ll th e W e b s ite D e f e n d e r .c o m a d v a n c e d
fe a tu r e s
Server Apache
A
A
A
A
A
Email
Name
WordPress
433
Help T
fgf Dashboard
QuickPress
Right Now
Content
D iscu ssion
Comments
Posts
1 Page
Approved
X Category
Pending
Title
Upload/Insert
Sparn
Tags
Tags
Theme Mir Simple with 3 Widgets
Save Draft
Reset
Gravity Forms
your site
F orm N am e
U nread E ntries
L a s t E n try
August 16,2012 at 9 47
am
Site Stats
Recent Drafts
WordPress Blog
Other WordPress News
Aug 2 8
A ug 2 7
Aug 2 9
Aug 31
S*p 2
S*p *
434
13. , ,
WordPress. ,
. ,
, .
WordPress,
. ,
,
. , ,
, ,
.
WordPress File Monitor
http://wordpress.org/extend/plugins/wordpress-file-monitor/.
, -
.
WordFence Security
WordFence Security
.
,
WordPress. . ,
WordPress . WordPress File Monitor
, ,
, WordFence
Security
.
WordFence
, ,
. 13.7. ,
,
.
W ordFence
,
.
, IP-
.
. ,
WordFence ,
IP -,
.
WordFence Security http://
wordpress.org/extend/plugins/fence/.
WordPress
435
Wordfence Scan
You can start the tour again or visit our support forums for help. Love Wordfence? You can help by
doing two simple things SoJoAYorilFLess^rji Dow_and m e this plugin a 5 * rating Blog about
Wordfence and link to the bluoin baoe Spreading the word helps us keep the best features free
S ca n S u m m a ry
--jnrenrp.Secure.
Secure.
Secure.
Secure.
(Sep 041014:15] Scanning for old themes, plugins and core files
Problems found
(Sep 0410:14.15] Scan complete. You have 1023 new issues to fix. See below for details.
Scan Complete
How to upgrade: If you would like to control how often your site is checked for security vulnerabilities and infections, and you would like to be able
to block countries, visit www.wordfence.com and sign up for our paid option Then go to the Wordfence options page on this site and replace your
free API key with your new premium key You will then be able to activate the premium scanning options on the Wordfence options page
S c a n D e t a ile d A c t iv it y
T m K T v e v r a r o rr r tr rrrtn n rx trt r r -
(Sep
[Sep
(Sep
(Sep
(Sep
(Sep
(Sep
Tools: Cleaning a hacked system? See a list of files that are not in the WordPress core. Plugin or theme repositories after your first scan
New Issues :
Ignored Issues
New Issues
The list below shows new problems or warnings that Wordfence found with your site If you have fixed
all the issues below, you can fi)j.QLh,g,,to
You can also imoLe all new
issues which will exclude all issues listed below from future scans
W o rd P re s s
,
. WordPress
.
WordPress
.
.
, , ,
.
.
,
.
436
13. , ,
,
.
.
,
,
.
,
.
:
, , ,
, . ,
, ,
, ?
. -,
, .
,
. -,
,
, . ,
.
:
,
.
,
,
.
, -
. ,
,
.
.
, .
:
.
, , ,
,
WordPress
437
.
.
,
, ,
.
:
.
,
. ,
.
, ,
.
WordPress.
, ,
.
,
, ,
.
:
.
, , ,
- .
, , .
,
, . ,
,
.
:
.
WordPress,
, .
. 13.1 ,
.
438
13. , ,
WordPress, http://codex.
wordpress.org/Roles_and_Capabilities.
13.1. , WordPress
439
, , ,
,
.
Role Scoper (http://wordpress.org/extend/plugins/rolescoper/)
, .
, ,
,
, .
,
.
,
,
.
, ,
. .
WordPress.
.
Role Scoper ,
,
, ,
, WordPress.
,
WordPress ,
,
.
,
WordPress.
, ,
,
WordPress ,
.
.
WordPress
:
,
WordPress
WordPress
, ,
WordPress {. content
management system, CMS), , .
, ,
, . , W ordPress
, , ,
.
.
WordPress ,
.
WordPress, ,
CMS, , WordPress, , ,
, , ,
WordPress .
, , -
441
. W iki
,
,
.
, ,
, ,
.
-
,
. ,
, -,
- .
WordPress?
CMS,
( )
. W ordPress
, ,
, , ,
. ,
;
,
. ,
W ordPress ,
CMS.
CMS, :
. CMS
, .
WordPress
.
.
,
.
. , ,
,
WordPress.
442
14. WordPress
.
, WordPress
, ,
Drupal. ,
WordPress .
, ,
, ,
WordPress
.
, WordPress
:
. , ,
WordPress
.
. WordPress ,
(. http://injersey.com)
,
, ,
(. http://baja.com).
.
,
,
, HTML.
W ordPress CMS
, ,
. , ,
W ordPress ,
,
.
,
,
.
CMS ,
. ,
,
, CMS.
443
CMS
,
.
,
.
, WordPress
.
Role Scoper 13
.
,
. CMS
.
,
.
,
,
. WordPress :
, ,
( )
. , ,
CMS WordPress:
.
root sudo. .
-
. , .
.
.
, ,
WordPress.
.
,
, (
) ( ,
). ,
, ,
.
444
14. WordPress
,
, . ,
, (
)
.
W ordPress
;
,
, .
WordPress
W ordPress M ultisite, 10. W ordPress
M ultisite WordPress.com,
,
.
, ,
WordPress,
( )
.
.
, ,
,
CMS. WordPress
: .
,
.
,
,
, ,
,
.
,
MySQL WordPress.
, ,
.
.
W P-CM S Post Control (http://wp-cms.com/ourwordpress-plugins/wp-cms-post-control-plugin/) .
445
,
W rite () ,
. 14.1.
P o rt Control 1Qe.C9.F_unSan*
Attnbutes
Administrator Editor
Administrator Editor
Custom Fields
Administrator Editor
Discussion
d Administrator
Featured Image
Administrator Editor
Slug
Administrator Editor
Revisions
0 Administrator Editor
Editor
D Administrator
Editor
Author
Contributor
,
.
, (
) ,
.
,
,
. , ,
- .
(Posts)
, ,
,
,
.
446
14. WordPress
WordPress , ,
MySQL,
. W ordPress
w p _ tra n sitio n _ p o st_ sta tu s() ,
,
.
Edit Flow
( http://wordpress.org/extend/plugins/edit-flow/).
WordPress.
,
.
,
. ,
,
. ,
, .
WordPress,
. WordPress,
.
, ,
, ,
. ,
, WordPress CMS
,
.
:
1. .
.
2. ,
.
, , ,
.
:
, , ,
, .
447
3.
.
,
,
, .
.
jQ uery API http://
api.jquery.com,
, .
WordPress
,
.
WordPress http://wordpress.org/showcase/tag/cms.
.
WordPress,
, ,
,
.
Thematic (http://wordpress.org/extend/themes/thematic)
. , 2 ( http://p2theme.com),
Automattic, ,
,
Twitter, , .
WordPress.
, ,
TinyMCE JavaScript
HTML- . Rich Text
Widgets
, .
Rich Text Widget, (http://wordpress.org/extend/plugins/
rich-text-widget/), . 14.2,
.
TinyMCE,
, .
448
14. WordPress
, ,
.
RSS
RSS Atom
.
, -
'.
*
,
,
WordPress
HTML-
1 : *
!:
* *
&
(|
0
'
:
:
449
. ,
, .
, ,
.
.
TinyMCE ,
, .
TinyMCE Advanced (http://wordpress.org/extend/plugins/tinymceadvanced/)
. , ,
. . 14.3
, .
,
? ,
,
. WordPress
, ,
,
.
.
9, .
WordPress
Reading Settings ( ),
. ,
. ( ) ,
.
WordPress ,
. WordPress
fro n t-p a g e . php, 9.
,
-, , ,
,
.
,
5,
, .
450
14. WordPress
.
, .
,
.
hero spot () .
.
jQuery
( JavaScript) . ,
,
, ,
. ,
,
W ordPress , ,
.
.
Features ( ) . , ,
, ,
, .
WordPress,
.
, 7 9,
. ,
; .
,
.
, ,
. ,
7. f u n c t i o n s . php .
:
/*
*
*
*/
a d d _ a c tio n ( ' i n i t ' , ' w p p ro _ c re a te _ p o s t_ ty p e s '
fu n c t io n w pp ro_ create_ post_ typ es() {
re g is te r_ p o s t_ ty p e ( ' s l i d e s j
array(
' l a b e l s ' => a r r a y (
);
451
),
h
' p u b l i c ' *> t r u e ,
' e x c l u d e _ f r o m _ s e a r c h ' => t r u e ,
' s u p p o r t s ' => a r r a y ( ' t i t l e ' , ' t h u m b n a i l ' , ' e d i t o r ' ) ,
)
);
>
front-page. php,
. .
.
WordPress get_posts():
g lo b a l $post;
$args = a rra y (
' p o s t _ t y p e ' = > 's l i d e s ' ,
' n u m b e r p o s t s ' => 3
' o r d e r b y ' => ' A S C '
);
$ s lid e r_ p o s ts = ge t_ p o sts($ arg s);
,
. numberposts -1 ,
.
HTML jQuery
:
< div id = " s lid e s h o w _ c o n ta in e r " >
< d iv i d = " s l i d e s h o w " >
<?php i f ( $ s l i d e r _ p o s t s ) {
f o r e a c h ( $ s l i d e r _ p o s t s as $ p o s t ) : s e t u p _ p o s t d a t a ( $ p o s t ) ;
/ /
$ th u m b n a il = w p _ g e t_ a tta c h m e n t_ im a g e _ s rc ( g e t_ p o s t_ th u m b n a il_ id ( ) ,
' h o m e - s lid e ');
i f ( $ t h u m b n a i l [ l ] == "6 0 0 " && $ t h u m b n a i l [ 2 ] == " 1 6 0 " ) {
/ / c s s ?>
< d iv i d = " f e a t u r e - < ? p h p e c h o $ p o s t - > I D ; ?>" c l a s s = " s l i d e " >
<a h r e f = " < ? p h p t h e _ p e r m a l i n k ( ) ; ?>" t i t l e = " < ? p h p t h e _ t i t l e ( ) ; ?>">
<img s r c = " < ? p h p e c h o $ t h u m b n a i l [ 0 ] ; ?>" t i t l e = " < ? p h p t h e _ t i t l e ( ) ;
?>" />
</a>
452
14. WordPress
< /d iv >
<?php } ?>
<?php e n d f o r e a c h ; ?>
<?php w p _ r e s e t _ p o s t d a t a ( ) ;
> ?>
< /d iv >
< /d iv >
, divs -,
.
,
, . ,
, ,
.
,
, . ,
.
,
, ,
JavaScript -.
jQuery Cycle (http://malsup.
com/jquery/cycle/). , jQuery,
WordPress.
.
HTML - .
JavaScript ,
JavaScript. jQuery :
$ ( ' # s l i d e s h o w ' ) . c y c l e ({
fx:
' s c r o l l H o r z 1,
speed:
5 0 0,
/ / ,
tim e o u t:
10 0 0 0 ,
/ /
pause:
1,
/ /
random: 0 ,
/ /
d e la y :
-1000,
/ /
next:
'# n e x t',
prev: . '# p re v io u s ',
pager:
" tts lid e n a v ",
p a g e rE v e n t: ' m ouseover ,
/ / ,
au to sto p : tru e ,
/ / t r u e - X
/ / ( X == , ,
/ / j a v a s c r i p t )
a u t o s t o p C o u n t : 10 0,
/ / (
453
/ / a u t o s t o p , X)
/ / , ,
/ /
p a g e rA n c h o rB u ild e r: f u n c t io n ( id x , s l i d e ) {
s lid e . id = "s lid e "+ id x ;
v a r desc = j Q u e r y ( '# '+ s lid e . id + ' i m g : f i r s t ) . a t t r ( " t i t l e " ) ;
r e t u r n <a h r e f = " # " t i t l e = " ' + d e s c + ' " > ' + ( l + i d x ) + ' < / a > ' ;
>
});
,
, .
.
-, ,
.
.
.
, , ,
.
,
.
.
. , ,
-
.
, 7,
.
.
, ,
WordPress,
.
. ,
, ,
, .
,
, ()
.
454
14. WordPress
: h#p .stextaflency.ru/7pafleJd=34 ;
?;
(!
,
'.
( /
: 12
17:33:26
Page L in k s
. 14.4. ,
Page Links
455
.
, 9.
, ,
.
WordPress.
,
.
, .
, ,
.
WordPress
.
,
. ,
.
,
, . 14.5.
|
( )
* :
I
*_______ I
. 14.5.
WordPress, Page re-Mash,
.
Page re-Mash W ordPress,
PageMash http://wordpress.org/extend/plugins/pagemash/,
pagemash.php http://binarym.com/2010/pagemash-trashauto-draft-and-wordpress-3-/.
14. WordPress
456
_1:_5 (),
.
p a g e M a sh
p a g e M a n a g e m e n t
Ju st drag the pages up or down to change the page order and left or right to change the p age's parent, then hit "update"
The Icon to the left of each page shows If It has child pages, double click on thal item to toggle expandlcollapse of it's children
EfliaQSL*l) 1Cs!lafiS*.8l!
I
I
Another Pag e
About US
Q
Q
.......I
C areers
Products
Product 1 : :
Product 2
Product 3
I
j
........ J
B e s t P ra ctice s
Update
Show Further info
version 3 4 2
. 14.6.
, :
,
Yet Another Related Post (http://wordpress.org/extend/plugins/yet-another-related-postsplugin/). ,
.
,
. ,
.
Pods Framework (http://wordpress.org/extend/plugins/pods/)
. Pods
,
.
.
Pods, Pods -. Pods
, .
457
,
12. ,
CMS, , .
.
, ,
.
, ,
, .
bbPress (http://bbpress.org),
WordPress Automattic. bbPress
WordPress,
.
, .
,
, , . ,
, ( )
WordPress.org: bbPress
WordPress.org.
,
.
,
, , .
cForms II ( http://www.deliciousdays.com/cforms-plugin)
, cforms
. ,
, , . cforms
- , .
CForms Gravity Forms, RocketGenius (http://
www.gravityforms.com/). , ,
. , , Gravity Forms
. WordPress
, , Gravity Forms. Gravity Forms
,
AJAX . , -
458
14. WordPress
, . ,
, .
, HTML
.
.
, HTML
CSS-. ,
, .
Gravity Forms ,
,
. CForms
, Gravity Forms .
,
, , , - .
, ,
.
WordPress.org,
.
, ,
:
?
,
, ?
?
, ,
,
.
?
, PayPal
,
PayPal
.
W P e-Commerce ( http://getshopped.org)
:
,
.
,
WordPress.
459
, WordPress ,
. ,
, ,
WordPress.
, ,
, bbPress, , BuddyPress,
CMS.
, ,
, WordPress
CMS. ,
WordPress ,
WordPress .
WordPress
, WordPress,
,
, , .
. ,
.
? RSS
RSS, 11,
, JSON,
?
URL,
oEmbed (http://oembed.com)? oEmbed
,
WordPress, , WordPress
.
?
( W ordPress MySQL ,
) , ,
,
?
WordPress
, , Drupal?
WordPress Drupal,
460
14. WordPress
,
Drupal.
WordPress
WordPress.
:
. ,
W ordPress,
EXIF-, , , CMS,
.
-.
.
, . WordPress HTML,
JSON , API.
WordPress ,
?
. ,
, ,
. , ,
, ,
, ( ) .
,
, ,
.
. ,
, ,
. WordPress
, , Drupal
Buddy Press . Buddy Press
, ,
,
.
.
WordPress, - ,
WordPress , .
WordPress ,
461
, ,
,
WordPress. 4, .
. ,
, .
. ,
.
,
.
WordPress ,
, ,
- 2000-.
,
WordPress ,
.
. , . , X.
WordPress
. ,
.
.
.
.
.
.
.
, 192102, -, . (. ), 3, , . 7.
005-93, 2; 95 3005 .
17.04.14. 70 100/16. . . . 37,410. 1500. 164.
. 180004, , . , 34.
www.piter.com
:
, ,
,
!
: , ,
, , .
-: . , . ., . 29
./: (812) 703-73-73, 703-73-72; e-mail: sales@piter.com
: . , ., . 2/1, . 1
./: (495) 234-38-15; e-mail: sales@msk.piter.com
: ., . 6, . 1, 33
./: (044) 490-35-69,490-35-68; e-mail: office@kiev.piter.com
: . , . 12, 10
./: (057) 7584145, +38 067 545-55-64; e-mail: piter@kharkov.piter.com
: . , . 163
./: (517) 208-80-01, 208-81-25; e-mail: minsk@piter.com
,
./: (812) 703-73-73; e-mail: spb@piter.com
./ : (812) 703-73-72, (495) 974-34-50
./: (812) 703-73-73, . 6250; e-mail: uchebnik@piter.com
: www.piter.com; .: (812) 703-73-74, . 6225
uuwuu.S R L D .ru
8 (812) 336-3739
, ,
WordPress. WordPress
CMS-,
WordPress, - .
WordPress ,
.
CMS, ,
. -,
,
, .
, .
: ,
WordPress, , .
: - WordPress
ISBN: 978-5-496-00948-5
&
9785496009485
:
-
9 785496
009485
www.piter.com -