#16 Wordpress theme from scratch | Nav walker class 2 | Quick programming beginner tutorial

Quick Programming
24 Sept 202112:45

Summary

TLDRこのビデオスクリプトでは、ウェブサイトのメニューを改善する方法が紹介されています。walkerクラスを使用してメニューを作成し、クラスの変更によりメニューの見た目を変更する方法を学びます。レベルや要素の開始と終了に関する関数を理解し、Bootstrapのドロップダウンメニューに合わせてwalkerクラスをカスタマイズします。メニューの階層構造を示すクラスの追加や、リンク属性の変更を行い、メニューの外観を改善します。最後に、ドロップダウンリストの欠如を次のビデオで解決する予定としています。

Takeaways

  • 😀 スクリプトは、メニューのデザインを変更し、特定のCSSクラスを変更することで実現する方法を示しています。
  • 🛠️ メニューの構造を変更するために、walkerクラスを編集し、クラス名を変更する必要があります。
  • 🔄 メニューの階層(レベル)を示すために、start_levelとend_levelの関数が使用されています。
  • 📁 階層の深さを設定することで、サブメニューやさらに深いメニュー構造を表示することができます。
  • 🔑 stat_element関数は、メニューのエレメント(例えば、アンカータグ)を開く場所を示します。
  • 🔍 メニューのエレメントを調査することで、walkerクラスで使用されるクラス名を特定できます。
  • 🔄 Bootstrapのドロップダウンメニューを使用するために、walkerクラスで'sub_menu'を'dropdown-menu'に変更する必要があります。
  • 🔑 各リストアイテムに'nav-item'クラスを追加することで、Bootstrapのナビゲーションスタイルを適用できます。
  • 🔗 'nav-link'クラスをアンカータグに追加することで、メニューアイテムに適切なスタイルを適用します。
  • 📝 メニューのエレメントの属性を編集することで、ドロップダウンメニューのような機能を追加できます。
  • 🛑 メニューの構造を変更する際には、不要なHTML要素を削除し、必要な構造のみを保持することが重要です。

Q & A

  • ビデオスクリプトで説明されているwalkerクラスとは何ですか?

    -walkerクラスは、メニューの表示を担当するクラスであり、メニューの見た目を変更するために使用されます。

  • walkerクラスを変更することによって何が変わりますか?

    -walkerクラスを変更することで、メニューの見た目や階層構造、サブメニューの表示などが変わります。

  • ビデオスクリプトで説明されている'start level'関数とは何を意味していますか?

    -'start level'関数は、メニューの階層の開始を示すもので、ホームページなどの最初のレベルを表します。

  • メニューの階層を表す'level'とはどのようなものですか?

    -メニューの階層は、ホームページを1階層、その下のページを2階層、さらに下のページを3階層としていくことで表されます。

  • 'end level'関数はどのような役割を持っていますか?

    -'end level'関数は、メニューの階層の終了を示すタグを挿入する役割を持っています。

  • ビデオスクリプトで紹介されている'stat element'関数は何をしますか?

    -'stat element'関数は、メニューの各要素の開始タグとクラス名、リストアイテムなどを追加する役割を持っています。

  • メニューの見た目をBootstrapに合わせるために何を変更する必要がありますか?

    -メニューの見た目をBootstrapに合わせるためには、'sub menu'クラスを'drop down menu'クラスに変更する必要があります。

  • リストアイテムに'nav item'クラスを追加する理由は何ですか?

    -'nav item'クラスを追加することで、Bootstrapのナビゲーションスタイルに合わせてメニューのスタイルを調整することができます。

  • ビデオスクリプトで説明されている'a'タグの'nav link'クラスは何のために必要なのですか?

    -'nav link'クラスは、アンカータグのスタイルをナビゲーションリンクに合わせるために必要なクラスです。

  • ドロップダウンメニューを作成するために必要な属性は何ですか?

    -ドロップダウンメニューを作成するためには、'drop down toggle'クラスや'href'属性の'#'値などが必要な属性です。

  • フォームをメニューの中に表示するためにwalkerクラスをどのように変更する必要がありますか?

    -フォームをメニューの中に表示するためには、walkerクラスの'container'オプションを空の文字列に設定し、フォームをメニューのDOM構造に直接挿入する必要があります。

Outlines

00:00

😀 メニューのクラス変更

この段落では、ウェブメニューのデザインを変更する方法について説明しています。walkerクラスを使っているメニューを、新しいデザインに変更するために必要なクラスを紹介します。walkerクラスの複雑さを避けつつ、具体的な変更点に焦点を当てています。メニューの階層(レベル)を示すstart level関数や、階層の終了を示すend level関数、要素の開始と終了を示すstart elementとend element関数について説明しています。また、メニューの深さを制御するdepthパラメータの重要性も触れられています。

05:03

🛠️ メニューアイテムのクラス変更

この段落では、walkerクラス内のメニューアイテムに適用されているクラスを変更する方法について説明しています。メニューアイテムのクラスを'menu-item'から'nav-item'に変更し、サブメニューを正しく表示するために必要な'drop-down-menu'クラスを追加します。また、'a'タグに'nav-link'クラスを適用し、メニューのリンクを正しく機能させる方法も紹介されています。この変更により、メニューの表示が改善され、Bootstrapのスタイルに合わせることができます。

10:05

🔧 ドロップダウンメニューの追加

最後の段落では、ドロップダウンメニューを実装するための手順について説明しています。walkerクラスをカスタマイズして、ドロップダウンメニューの機能を追加する必要があると指摘しています。また、ページの構造を整理し、不要な要素を削除することで、メニューの整合性を保ちながら、必要な形にメニューをカスタマイズする方法も提案されています。このセクションでは、メニューの改善が進行中であり、次のビデオでドロップダウンメニューの実装が完了すると示唆しています。

Mindmap

Keywords

💡walkerクラス

walkerクラスとは、WordPressのテーマ開発において、メニューの表示方法をカスタマイズするためのクラスです。このビデオでは、walkerクラスを変更することで、メニューのデザインを変更するプロセスが説明されています。walkerクラスは、メニューの階層構造を制御する重要な役割を果たしており、ビデオのテーマに密接に関連しています。

💡クラス名

クラス名は、HTMLやCSSで要素を特定するために使用される識別子です。ビデオでは、walkerクラス内のクラス名を変更することで、メニューの外観を調整する方法が紹介されています。例えば、「sub-menu」クラスを「dropdown-menu」に変更することで、ブートストラップスタイルのドロップダウンメニューを実現しています。

💡メニュー階層

メニュー階層とは、ウェブサイトのメニューが持つ階層的な構造のことです。ビデオでは、「start_level」と「end_level」という関数が、メニューの階層を開始したり終了したりするプロセスを制御していることが説明されています。これは、ウェブサイトのメニューがサブメニューやサブサブメニューを持つことができる機能です。

💡ブートストラップ

ブートストラップは、ウェブサイトやアプリケーションの開発を支援する人気のあるCSSフレームワークです。ビデオでは、ブートストラップのクラスを使用して、メニューのスタイルを変更する方法が紹介されています。ブートストラップは、レスポンシブデザインやユーザーインターフェースの作成に役立ちます。

💡ドロップダウンメニュー

ドロップダウンメニューは、ウェブサイトのメニューアイテムを展開して複数のオプションを表示する機能です。ビデオでは、walkerクラスを編集してドロップダウンメニューを作成する方法が説明されています。これは、ユーザーがウェブサイトをナビゲートする際に、より多くの情報にアクセスできるようにするのに役立ちます。

💡メニューアイテム

メニューアイテムは、ウェブサイトのメニューに表示される個々のリンクやオプションです。ビデオでは、「menu_item」クラスを使用してメニューアイテムを特定し、それらに新しいクラスを追加することでスタイルを変更しています。メニューアイテムは、ウェブサイトのナビゲーションの基本的な要素です。

💡属性

属性は、HTML要素に追加の情報を提供するために使用されます。ビデオでは、「a」タグの属性を編集して、メニューのリンクをブートストラップの「nav-link」クラスに合わせる方法が紹介されています。属性は、ウェブサイトの機能性やスタイルをカスタマイズするために不可欠です。

💡リストアイテム

リストアイテムは、HTMLのリスト構造における個々の要素です。ビデオでは、「start_element」関数内でリストアイテムに「nav-item」クラスを追加することで、ブートストラップのナビゲーションスタイルを実装しています。リストアイテムは、メニューの視覚的な並びを形成する要素です。

💡メニューのカスタマイズ

メニューのカスタマイズとは、ウェブサイトのメニューを個々のニーズやスタイルに合わせて変更するプロセスです。ビデオでは、walkerクラスを変更することでメニューの外観をカスタマイズする方法が詳細に説明されています。これは、ウェブサイトのデザインの一貫性を保ち、ユーザー体験を向上させるために重要なステップです。

💡HTML

HTMLは、ウェブページの構造と内容を定義するためのマークアップ言語です。ビデオでは、HTMLの要素と属性を編集して、メニューのデザインを変更する方法が紹介されています。HTMLは、ウェブサイトのビジュアルレイアウトと機能を構築する基盤です。

💡CSS

CSSは、ウェブページのスタイルとデザインを制御するためのスタイルシート言語です。ビデオでは、CSSフレームワークであるブートストラップを使用して、メニューのスタイルを変更しています。CSSは、ウェブサイトの外観をカスタマイズし、視覚的に魅力的にするために使用されます。

Highlights

Walker class is running the menu, and changes are needed to adapt it.

Explanation of the 'start level' function, its role, and the concept of levels in the menu.

Description of the 'end level' function and its purpose in the menu structure.

Details on how the 'start element' function works and how class names and indentations are added.

Identifying the 'sub menu' class in the current structure and the need to replace it with 'drop down menu' from Bootstrap.

Modification of the list items to use the 'nav item' class instead of the default 'menu item' class.

Explanation of how to find and modify the attributes of the 'a' tag to include the 'nav link' class.

Practical steps to add the 'nav link' class to the 'a' tag within the menu structure.

Verification of changes in the browser and ensuring that the class modifications are reflected correctly.

Discussion on the need to remove unnecessary classes and IDs to clean up the code.

Introduction of the 'drop down toggle' class for better drop-down menu functionality.

Steps to handle the form within the menu, ensuring it is correctly positioned and functional.

Ensuring that the 'container' class is appropriately used or removed to maintain structural integrity.

Testing the changes by adding more menus in the admin panel and verifying their appearance.

Closing remarks on the progress made and the next steps for improving the drop-down menu functionality.

Transcripts

play00:09

hey welcome back guys

play00:12

so

play00:13

we have a walker class that is running

play00:15

the menu right now but we want this menu

play00:18

to look something like this

play00:20

and all we want to do to do that what we

play00:22

need to do to do that is to change the

play00:24

classes that are here into those

play00:28

so now the worker class is quite

play00:30

complicated

play00:32

and

play00:33

we don't want to start

play00:35

learning details of this thing i just

play00:37

want to show you what to change and

play00:39

that's it

play00:40

so here

play00:42

there are several functions if you can

play00:44

see here this public function this one

play00:46

is called stat level so this lvl is

play00:50

level so start level

play00:53

now

play00:54

keep in mind that this is a loop it's a

play00:57

looping mechanism

play00:58

so it's a level

play01:01

let me come back here to show you what

play01:03

levels are so here this is level one

play01:06

like the home page and then this is a

play01:08

child of this and that's level two and

play01:12

then if this had a child of its own that

play01:15

would be level three so that's what

play01:16

those levels are

play01:19

so that's for starting a level and then

play01:21

if you scroll down you will see there's

play01:24

a end level right there okay so this

play01:27

puts the ending

play01:28

uh tag so you can see the here it's the

play01:31

unordered list tag closing part

play01:35

and then if you look at start level

play01:37

uh this is where the

play01:39

ordered list

play01:40

starting starts from here so this is

play01:43

where it starts from and then it puts

play01:44

some class names and then some

play01:47

indentation here so depending on the

play01:49

level it will put a depth there so this

play01:52

depth of zero so this is where you tell

play01:55

it how deep you want the levels to go if

play01:57

you wanted to show sub menus and sub sub

play02:00

sub menus etc that's where the depth

play02:03

thing comes in

play02:05

and then from the levels here there's

play02:07

another function which is stat element

play02:09

so this is where the element opening

play02:11

elements are

play02:13

added so you can see here there are

play02:15

class names being added

play02:17

and list items there of course etc etc

play02:21

so the hrefs and so on and then of

play02:25

course these end um

play02:28

where is this this end element

play02:30

so the only four functions in here is

play02:33

stat level and level start element end

play02:35

element so this is the ending list item

play02:39

okay so just keep that in mind

play02:42

and then

play02:43

uh

play02:44

to begin our thing we just have to look

play02:46

at what's familiar here and what's

play02:48

familiar on the menu

play02:50

so let's go back to the menu and inspect

play02:53

this menu okay

play02:55

and i'm going to go to the another list

play02:58

the beginning of the unordered list and

play03:00

just copy

play03:01

the outer html i'm going to close that

play03:04

just for the sake of comparison

play03:08

okay

play03:09

so we have this we have that class which

play03:12

we added and then now we have this

play03:14

anoded list and then we have

play03:17

this class called sub menu right

play03:21

let me put this here like so

play03:27

maybe i should put word wrap here

play03:31

okay like this

play03:33

so there's an ordered list and there's a

play03:35

there's a list item then there's a sub

play03:37

menu so you see here immediately we see

play03:39

sub menu we know where this sub menu is

play03:42

being created from because if we go to

play03:43

the walker you will see it right here so

play03:47

instead of sub menu bootstrap uses

play03:49

something else so let's go to bootstrap

play03:51

here for a second

play03:53

and

play03:55

or if you not

play03:57

uh you don't have that bootstrap thing

play03:58

open you can simply go back to your nav

play04:01

page and you have the same code here

play04:04

which you already copied

play04:06

so if you look here instead of sub menu

play04:08

we have drop down menu okay so i'm going

play04:12

to copy this

play04:14

drop down menu on the unordered list

play04:17

right

play04:18

because this is where it is on the anode

play04:20

list class sub menu so there

play04:23

bootstrap uses drop down menu instead so

play04:26

let's paste that so what else can we add

play04:29

on this same situation

play04:32

so if you want you can even add all that

play04:35

but for now we don't need that so

play04:37

there's just the drop down menu that's

play04:39

it

play04:40

and then there's also something else

play04:41

here where every list item has a class

play04:44

of nav item instead so if you look at

play04:48

this everything is now item so let me

play04:51

copy all of that

play04:53

let's come back to the walker

play04:54

and let's look for

play04:56

let's see here what classes do the list

play04:59

items have they have this is an id they

play05:02

have menu item right

play05:07

so that's menu items so this is what we

play05:09

should be looking for menu item in the

play05:12

walker so you can use a search instead

play05:15

to figure these things out a little bit

play05:17

quicker

play05:18

so let's look for it here it should be

play05:21

somewhere and you see right here it says

play05:23

menu item

play05:25

and then there's a class name so you see

play05:28

here this is where the classes are

play05:30

created right

play05:31

and it adds all that and then finally it

play05:35

adds to the class this menu item with an

play05:37

id

play05:38

but we don't need all this so instead of

play05:40

deleting all this what we can just do is

play05:42

create our own let's just add

play05:46

enough item instead let's remove that id

play05:48

we don't need it

play05:49

but then i want these classes clean so

play05:52

i'm just going to say classes here

play05:55

here sorry is equal to an empty array

play05:58

like so

play06:01

so i empty the array here and then i add

play06:04

just enough item there okay so this is

play06:07

inside the stat element function

play06:10

so all i did is i just negated whatever

play06:13

is happening here and just added one

play06:15

class there

play06:16

so let's see if that makes a difference

play06:18

in our system so refresh

play06:22

okay good so you see now there's a

play06:25

slight difference here with the way it

play06:28

was at least the sub menu has

play06:30

disappeared as it should and then these

play06:33

in the same line now

play06:35

so let's keep going now let me refresh

play06:37

inspect and just to see that

play06:40

what i have done actually

play06:42

made a difference

play06:44

i will see this

play06:46

a list item here

play06:49

and the class is nav item for every list

play06:52

item so

play06:54

that is good

play06:55

so let's add something else to see how

play06:58

that will work

play07:00

now let's come back to then

play07:04

let's go to the nav dot php and then the

play07:07

a tag itself has this thing called nav

play07:10

link okay so let me copy that class it's

play07:13

nav link in the a tag so all i have to

play07:17

do is find where the a tag is being

play07:19

created right so let me look around here

play07:23

okay so this list item which we've

play07:25

already covered

play07:26

and let's keep going yeah usually

play07:30

uh

play07:31

blank and all of this usually is

play07:35

for the a tag

play07:37

so it must be somewhere around here

play07:40

where can it be

play07:42

ah look at there a tag right

play07:45

so opening and closing and then right

play07:47

here we have attributes so there's an

play07:50

opening um bracket for the a tag and

play07:52

then there's attributes and then there's

play07:54

this so all we need to do is deal with

play07:56

these attributes here and put our own

play07:59

attributes there right

play08:01

so

play08:02

we already know that uh

play08:04

those classes are nav link but we can't

play08:08

see them here

play08:10

so what to do what to do

play08:15

hmm

play08:18

okay let me go up here a little bit

play08:21

let's see here let's see

play08:23

what we have

play08:25

okay so

play08:28

the attributes start from here

play08:31

so there's an attribute here called

play08:33

title there's an attribute called target

play08:36

and that and another attribute called

play08:38

href

play08:39

and this other attribute so

play08:41

looks easy enough i think what we need

play08:44

to do is just duplicate this and add our

play08:47

own

play08:49

our own uh

play08:51

attribute called

play08:53

class

play08:54

right

play08:55

because i don't see it here so that

play08:57

attribute will have

play08:59

the content that we have that we want so

play09:03

let's put another link there like so

play09:07

okay so let's see if that helps refresh

play09:13

now we are looking more like that aren't

play09:15

we and just like that we had done with

play09:18

this

play09:19

okay

play09:20

the only problem we have is we don't

play09:22

have the drop down list here

play09:25

okay

play09:27

but otherwise this is looking more like

play09:29

that

play09:30

and it's clickable as well already

play09:33

because the links are correct so you see

play09:35

that

play09:36

things are working out

play09:38

as planned

play09:40

okay

play09:41

cool

play09:42

so the only remaining part here is for

play09:45

us to

play09:48

design this you see because there's drop

play09:50

down here and then there's also a tag

play09:55

you see this a tag here that has nav

play09:57

link

play09:58

however if

play10:00

um

play10:02

if this is a drop down list drop down

play10:04

menu it has drop down toggle as well

play10:09

and then it has this href

play10:11

hash as well

play10:13

and all of these things here

play10:15

okay

play10:16

so we need to add those for the drop

play10:18

down list now in order to fix what we

play10:22

have so far let me move this nav menu

play10:25

so we practically don't need any of this

play10:27

this div here since we have reference on

play10:30

the bootstrap website we can all just

play10:32

remove this so i'm just going to do this

play10:35

boom

play10:36

like that

play10:37

just leave the button here

play10:39

and

play10:41

this part and the navigation there

play10:43

okay so let's come back here and see

play10:45

what we've done if i remove

play10:49

now you see that

play10:51

okay

play10:52

oh where has that gone oopsie

play10:56

so let's undo so what i did is i got the

play11:00

form as well

play11:02

in here so let's just remove the

play11:04

unordered list from there

play11:06

boom

play11:07

okay

play11:09

now because we

play11:11

we are already having this div here

play11:13

because we need to add the form in here

play11:16

so we will tell it not to create a div

play11:19

of its own here

play11:20

so this div is the one with collapse

play11:22

collapse there so container container

play11:25

container

play11:26

now what do we do if we go back to nav

play11:29

menu here let's see where it says

play11:31

container so it says container whether

play11:34

to wrap the into a container or not

play11:37

okay

play11:38

so the default is div

play11:41

now what i want to do instead

play11:43

for container i'll remove the container

play11:46

id and container and then let's just put

play11:48

an empty string

play11:50

so that it doesn't give a container and

play11:52

then i'll move it

play11:55

into this space

play11:57

where i removed the list items

play12:00

like so

play12:03

okay

play12:04

that way i get to keep my form

play12:08

because if i had let this div stay it

play12:10

would have been created inside here then

play12:12

there would be no way of me putting this

play12:13

form in there

play12:15

so like this is better and then now i

play12:18

can refresh at least i have that and i

play12:21

still have my pages there so as you can

play12:23

see now i can click nicely and the pages

play12:26

go to where the menu

play12:29

is going right if i um

play12:32

if i go to my uh

play12:34

admin and add more menus they're going

play12:36

to show here but we still don't have our

play12:39

drop down list so let's figure that out

play12:42

in the next video

Rate This

5.0 / 5 (0 votes)

関連タグ
ウェブデザインブートストラップメニューカスタマイズCSSクラスナビゲーションウェブ開発チュートリアルHTMLタグドロップダウンユーザーインターフェース