-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwordpress.cmds.txt
732 lines (478 loc) · 15.9 KB
/
wordpress.cmds.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
>>> Wordpress Theme Development <<<<<<
----------------------------------------------------------------------------------------
Keys: short code, plugin, widget, Short Code in Custom Page,
----------------------------------------------------------------------------------------
Topics:
[Theme Functions: functions.php : Register Options to Admin: Examples](#theme-functions)
[What Is a WordPress Database Table?](#wp-database)
[Child Theme](#chile-theme)
[Child Theme](#chile-theme)
[Child Theme](#chile-theme)
[Child Theme](#chile-theme)
[Child Theme](#chile-theme)
[Child Theme](#chile-theme)
Making Theme:
-----
Default Page: page.php
Blog Page: index.php
Custom Design: template
For Admin: functions.php
-----
Insert HTMT to Wordpress Theme
User Wordpress Functions:
Calling:
<?php echo get_template_directory_uri(); ?>
<?php echo bloginfo(); ?>
<?php echo get_header(); ?>
<?php echo get_footer(); ?>
<?php echo the_title(); ?>
//Header file name: header.php
<?php echo get_header(''); ?>
//Header file name: header-inner.php
<?php echo get_header('inner'); ?>
//Header file name: footer.php
<?php echo get_footer()?>
//Header file name: footer-inner.php
<?php echo get_footer('inner'); ?>
<?php site_url(); ?>
<?php the_content(); ?>
<?php echo get_the_content(); ?>
<?php the_post(); ?>
<?php the_post_thumbnail(); ?>
<?php wp_get_attachment_image_src(get_post_thumbnail_id(), 'large'; ?>
----------------------------------------------------------------------
------------------------------------------------------------------------------
What is functions.php?
The functions.php file behaves like a WordPress plugin, adding features and functionality to a WordPress site.
You can use it to call WordPress functions and to define your own functions.
-------------------------------------------------------------------------------
---------------------------------------------------------------------
//Register a New Menu in Wordpress
<?php echo register_nav_menu(); ?>
<?php echo wp_nav_menu(); ?>
File: funtions.php
//Showing options in admin
functions.php
<?php
regiter_nav_menus(
array('primary-menu'=>'Top Menu'
)
add_theme_support('post-thumbnails');
//Admin mein image add hogi
<?php add_theme_support('custom-header'); ?>
?>
Calling:
<div class="menu-bar">
<?php wp_nav_menu(array('
theme_location'=>'primary-menu'
,'menu_class'=>'nav')) ?>
)) ?>
</div>
------------------------------------------------------------
How to call default page template in wordpress
File: page.php
------------------------------------------------------------
<?php
$logoimg = get_header_image();
?>
-----------------------------------------------------------------------------
Theme Functions
Automatic Feed Links.
Navigation Menus.
Load Text Domain.
Post Thumbnails.
Post Formats.
Theme support in block themes.
Initial Setup Example.
------------------------------------------------------------------------------
#
[Top](#top)
<a name="theme-functions"></a>
*Theme Functions: functions.php : Register Options to Admin
What is functions.php?
The functions.php file behaves like a WordPress plugin, adding features and functionality to a WordPress site.
You can use it to call WordPress functions and to define your own functions.
Examples:
<code>
function load_stylesheets()
{
wp_register_style('style_css', get_template_directory_uri() . '/style.css');
wp_enqueue_style('style_css');
}
add_action( 'wp_enqueue_scripts', 'load_stylesheets');
</code>
Theme Setup
A number of theme features should be included within a “setup” function that runs initially when your theme is activated. As shown below, each of these features can be added to your functions.php file to activate recommended WordPress features.
To create this initial function, start a new function entitled myfirsttheme_setup(), like so:
<code>
if ( ! function_exists( 'myfirsttheme_setup' ) ) :
/**
* Sets up theme defaults and registers support for various WordPress
* features.
*
* It is important to set up these functions before the init hook so
* that none of these features are lost.
*
* @since MyFirstTheme 1.0
*/
function myfirsttheme_setup() { ... }
</code>
Automatic Feed Links
Automatic feed links enables post and comment RSS feeds by default. These feeds will be displayed in <head> automatically. They can be called using add_theme_support() in classic themes. This feature is automatically enabled for block themes, and does not need to be included during theme setup.
add_theme_support( 'automatic-feed-links' );
Navigation Menus:
<code>
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'myfirsttheme' ),
'secondary' => __( 'Secondary Menu', 'myfirsttheme' )
) );
</code>
Load Text Domain:
<code>
load_theme_textdomain( 'myfirsttheme', get_template_directory() . '/languages' );
</code>
Post Thumbnails:
<code>
add_theme_support( 'post-thumbnails' );
</code>
Post Formats:
<code>
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'quote', 'image', 'video' ) );
</code>
Theme support in block themes:
<code>
add_theme_support( 'post-thumbnails' );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'editor-styles' );
add_theme_support( 'html5', array( 'style','script' ) );
add_theme_support( 'automatic-feed-links' );
</code>
Initial Setup Example:
<code>
if ( ! function_exists( 'myfirsttheme_setup' ) ) :
/**
* Sets up theme defaults and registers support for various
* WordPress features.
*
* Note that this function is hooked into the after_setup_theme
* hook, which runs before the init hook. The init hook is too late
* for some features, such as indicating support post thumbnails.
*/
function myfirsttheme_setup() {
/**
* Make theme available for translation.
* Translations can be placed in the /languages/ directory.
*/
load_theme_textdomain( 'myfirsttheme', get_template_directory() . '/languages' );
/**
* Add default posts and comments RSS feed links to <head>.
*/
add_theme_support( 'automatic-feed-links' );
/**
* Enable support for post thumbnails and featured images.
*/
add_theme_support( 'post-thumbnails' );
/**
* Add support for two custom navigation menus.
*/
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'myfirsttheme' ),
'secondary' => __( 'Secondary Menu', 'myfirsttheme' ),
) );
/**
* Enable support for the following post formats:
* aside, gallery, quote, image, and video
*/
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'quote', 'image', 'video' ) );
}
endif; // myfirsttheme_setup
add_action( 'after_setup_theme', 'myfirsttheme_setup' );
</code>
Content Width:
<code>
if ( ! isset ( $content_width) ) {
$content_width = 800;
}
</code>
Other Features:
Custom Headers -Classic themes
Sidebars (widget areas) -Classic themes
Custom Background -Classic themes
Title tag -Classic themes
Add Editor Styles
HTML5 -Classic themes
Your functions.php File:
<code>
/**
* MyFirstTheme's functions and definitions
*
* @package MyFirstTheme
* @since MyFirstTheme 1.0
*/
/**
* First, let's set the maximum content width based on the theme's
* design and stylesheet.
* This will limit the width of all uploaded images and embeds.
*/
if ( ! isset( $content_width ) ) {
$content_width = 800; /* pixels */
}
if ( ! function_exists( 'myfirsttheme_setup' ) ) :
/**
* Sets up theme defaults and registers support for various
* WordPress features.
*
* Note that this function is hooked into the after_setup_theme
* hook, which runs before the init hook. The init hook is too late
* for some features, such as indicating support post thumbnails.
*/
function myfirsttheme_setup() {
/**
* Make theme available for translation.
* Translations can be placed in the /languages/ directory.
*/
load_theme_textdomain( 'myfirsttheme', get_template_directory() . '/languages' );
/**
* Add default posts and comments RSS feed links to <head>.
*/
add_theme_support( 'automatic-feed-links' );
/**
* Enable support for post thumbnails and featured images.
*/
add_theme_support( 'post-thumbnails' );
/**
* Add support for two custom navigation menus.
*/
register_nav_menus( array(
'primary' => __( 'Primary Menu', 'myfirsttheme' ),
'secondary' => __( 'Secondary Menu', 'myfirsttheme' ),
) );
/**
* Enable support for the following post formats:
* aside, gallery, quote, image, and video
*/
add_theme_support( 'post-formats', array( 'aside', 'gallery', 'quote', 'image', 'video' ) );
}
endif; // myfirsttheme_setup
add_action( 'after_setup_theme', 'myfirsttheme_setup' );
</code>
#
[Top](#top)
<a name="child-theme"></a>
*Child Theme
Create a style.css in the child theme folder
style.css
<code>
/*
Theme Name: Twenty Seventeen Child
Theme URI: http://yourdomain.com
Description: Twenty Seventeen Child
Theme Author: Your Name
Author URI: http://yourdomain.com
Template: twentyseventeen
Version: 1.0.0
Text Domain: twentyseventeen-child
License: GNU General Public License or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
*/
</code>
Create a PHP file named functions.php in the child theme’s directory:
<code>
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_parent_styles' );
function enqueue_parent_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
}
?>
</code>
Change the background color:
<code>
.site-content-contain {
background-color: #DEF0F5;
position: relative;
}
</code>
Change Side Bar Color:
<code>
.widget {
background: #B9EBFA;
padding: 25px;
}
</code>
Changing Font Types, Sizes, and Colors:
<code>
p {
color: teal;
}
p {
font-family: Georgia;
font-size: 18px;
}
</code>
Entry Title:
<code>
.entry-title a {
color: #333;
text-decoration: none;
margin-left: -2px;
}
</code>
page.php:
<code>
get_template_part( 'template-parts/page/content', 'page' );
</code>
#
[Top](#top)
<a name="wp-database"></a>
*What Is a WordPress Database Table?
A database stores data in the form of tables. Each table consists of unique data displayed in columns and rows that contain more specific pieces of information or parameters.
By default, a WordPress database contains the following tables;
wp_commentmeta – keeps the metadata of each comment posted on the website.
wp_comments – stores data related to user comments, including the author name, URL, IP address, email, and comment content.
wp_links – it was used for holding information from the Links feature. Since the feature has been deprecated, this table is often empty.
wp_options – contains WordPress configuration settings, such as website URL, default category, and posts per page.
wp_postmeta – keeps metadata of each post on the site, such as custom fields.
wp_posts – stores data from articles, custom post types, pages, and navigation menu items.
wp_termmeta – stores metadata of the terms.
wp_terms – contains the WordPress terms for each post tag and category.
wp_term_relationships – maintains the association between posts and terms in the wp_terms table.
wp_term_taxonomy – describes the taxonomy for each category, link, and tag in the wp_terms table.
#
How to fetch data from database using MySqli or $wpdb (Code Not Tested)
<code>
$results = $wpdb->get_results( "SELECT * FROM $table_name"); // Query to fetch data from database table and storing in $results
if(!empty($results)) // Checking if $results have some values or not
{
echo "<table width='100%' border='0'>"; // Adding <table> and <tbody> tag outside foreach loop so that it wont create again and again
echo "<tbody>";
foreach($results as $row){
$userip = $row->user_ip; //putting the user_ip field value in variable to use it later in update query
echo "<tr>"; // Adding rows of table inside foreach loop
echo "<th>ID</th>" . "<td>" . $row->id . "</td>";
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
echo "<tr>";
echo "<th>User IP</th>" . "<td>" . $row->user_ip . "</td>"; //fetching data from user_ip field
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
echo "<tr>";
echo "<th>Post ID</th>" . "<td>" . $row->post_id . "</td>";
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
echo "<tr>";
echo "<th>Time</th>" . "<td>" . $row->time . "</td>";
echo "</tr>";
echo "<td colspan='2'><hr size='1'></td>";
}
echo "</tbody>";
echo "</table>";
}
</code>
#
To update time field on if condition:
if($userip==245.356.134.22){ //Checking if user_ip field have following value
$wpdb->update(
$table_name,
array(
'time' => 'YOUR NEW TIME' // Entring the new value for time field
),
array('%d') // Specify the datatype of time field
);
}
Update
If you want to check if the IP you are going to insert in database is already exist or not then check it like this
<code>
global $wpdb,$ip;
$results = $wpdb->get_results( "SELECT user_ip FROM $table_name"); //query to fetch record only from user_ip field
$new_ip = 245.356.134.22; //New Ip address storing in variable
if(!empty($results))
{
foreach($results as $row){
$old_ip = $row->user_ip; // putting the value of user_ip field in variable
if($new_ip==$old_ip){ // comparing new ip address with old ip addresses
$ip = 'Already Exist'; // if ip already exist in database then assigning some string to variable
}
}
}
if($ip = 'Already Exist'){ // Checking if variable have some string (It has some string only when if IP already exist in database as checked in if condition by comparing old ips with new ip)
//Insert query according to Ip already exist in database
}else{
//Insert query according to Ip doesn't exist in database
}
</code>
#
<code>
//For fetching data use
global $wpdb;
$results = $wpdb->get_results("SLECT * FROM table_name");
//and for update use below code
$wpdb->update(
$table_name,
array(
'time' => time(), // string
),
array( 'user_ip' => '245.356.134.22' ),
array('%s'),
array( '%d' )
);
</code>
#
<code>
$wpdb->update($table_name , array('user_ip' => $user_ip, 'post_id' =>$postID, 'time' => $visittime),array('%s','%d', '%d') );
$results = $wpdb->get_results("SELECT * FROM table_name");
</code>
#
*Database Application Programming Interface (API)
get_comments()
get_pages()
get_posts()
get_results()
get_row()
get_users()
get_var()
#
# Short Code in wordpress
In functions.php file:
function my_shortcode {
$message = "<h1>This short code</h1>";
return $message;
}
//Register Short Code, Using: [greeting]
add_shortcode('greeting', 'my_shortcode')
#
# Using Short Code In Custom Page in Wordpress (In Child Theme)
//Short Code in Custom Page
<?php
/* Template Name: Contact Us */
get_header();
?>
<h1>Contact Us</h1>
<?php echo do_shortcode("[greeting]"); ?>
<?php
get_footer();
?>
#
# Widged in Wordpress
In functions.php file
function header_widget() {
register_sidebar(array(
'name' => 'Header Widget',
'id' => 'header_widget',
'description' => 'will be displayed in the Header',
'before_widget' => '<div class="heade_widget">'
'after_widget' => '</div>',
'before_title' => '<h2 class="widget_title"></h2>',
'after_widget' => '</h2>',
));
}
//Wordpress hook
add_action('widget_init','header_widget');
//Put this code in any file example header.php
<?php if(is_active_sidebar('header_widget)) :?>
<div class="head_wrap">
<?php dynamic_sidebar('header_widget') ?>
</div>
<?php endif; ?>
#
:end: