Archive for the ‘Microwave’ Category

Thermal imager gradient fix

One of the ther­mal imagers I have been con­sid­er­ing using is the Seek Ther­mal cam­era. An impres­sive cam­era, cur­rent­ly only avail­able in the US, they use a Raytheon sen­sor to cre­ate a small USB cam­era designed to be used with a mobile phone. Most impor­tant­ly for me it sup­ports a wide range of tem­per­a­ture, an inten­tion­al lim­i­ta­tion with the FLIR cores.

Sad­ly the cam­era has some issues. All ther­mal sen­sors require post-pro­cess­ing to clean up the image and work around qual­i­ty issues with the image, it is a bit more com­plex than a stan­dard CCD. The Seek cam­era does some basic pro­cess­ing in the device but most of the image manip­u­la­tion required to get the cam­era work­ing is per­formed in the Android appli­ca­tion. Seek has been promis­ing an SDK since the prod­uct was first announced, pre­sum­ably this will allow oth­er clients to be used, but no SDK has been forth­com­ing.

I have been spend­ing a fair bit of time try­ing to under­stand how to use their fac­to­ry cal­i­bra­tion val­ues and get a good tem­per­a­ture read­ing out of the device, so far unsuc­cess­ful­ly.

As a side effort I spent a bit of time work­ing on anoth­er prob­lem with the device, with more suc­cess.

When first released the cam­era had an erro­neous ther­mal gra­di­ent at the edges and par­tic­u­lar­ly the cor­ners. This was par­tic­u­lar­ly obvi­ous if you point­ed the cam­era at a ther­mal­ly flat sur­face, such as a wall, the autoscal­ing would high­light the error as the only vari­a­tion in the image. Var­i­ous peo­ple report­ed that adjust­ing the lens hold­er helped and that the prob­lem var­ied with time. I believe that the issue is a com­bi­na­tion of the lens hold­er being imper­fect­ly aligned and so its tem­per­a­ture influ­ences the sen­sor, the lens hold­er is heat­ed by the cir­cuit­ry around it and so gets worse with time.

Ear­ly this year Seek cor­rect­ed the prob­lem with a soft­ware update. Look­ing at ver­sion num­bers of each com­po­nent it was clear that the fix was pure­ly post-pro­cess­ing per­formed by the Android appli­ca­tion. They have nev­er respond­ed to ques­tions on how this was achieved.

I have man­aged to fig­ure out their tech­nique and have doc­u­ment­ed it in an Octave/Matlab func­tion which repro­duces the process used. Hope­ful­ly this will allow peo­ple mak­ing inde­pen­dent clients to apply sim­i­lar cor­rec­tions and allow the cam­era to be used with non-phone devices.

I dis­cuss details of the tech­nique on the eevblog forum where most of the Seek dis­sec­tion has tak­en place. The script is also rel­a­tive­ly sim­ple and com­ment­ed for any­one with Mat­lab expe­ri­ence.

Some before and after pho­tos of the pro­cess­ing. A ther­mal­ly flat image and some ugly face.


Before — Floor

After — Floor

Before — Face

After — Face

It is inter­est­ing to see that the cor­rec­tions to the face go far fur­ther than I ini­tial­ly expect­ed.
The fix­up in the bot­tom right cor­ner is obvi­ous, the gra­di­ent gets changed to a flat back­ground.
How­ev­er the fix­es around the bot­tom of my face were star­tling, my neck gets cor­rect­ed to a much bet­ter tem­per­a­ture, the beard cools down and the jumper col­lar cools right off. I think all these revised details are more accu­rate.

Source code, includ­ing the raw data of my face and usage instruc­tions, is on github.

Door design

Designing a door

Design­ing the door to the microwave is turn­ing out to be a bit more fid­dly than I hoped. This is a com­bi­na­tion of mechan­i­cals being new to me and reg­u­la­to­ry con­cerns about keep­ing the dan­ger­ous radi­a­tion in the box.

The cri­te­ria isn’t too com­plex, dis­cov­er­ing that non-Aus­tralian stan­dards are a touch more expan­sive was an unpleas­ant sur­prise though:

  1. Must open to allow foods in and out.
  2. Must com­ply with Aus, US & EU stan­dards.
    • Must pro­vide RF seal when shut (no cook­ing bystanders).
    • Must have dou­ble inter­lock to pre­vent oper­a­tion when open.
    • Must be durable and main­tain seal through lifes­pan.
  3. Must indi­cate when sealed to allow oper­a­tion.
  4. Must pro­vide mech­a­nism to open/lock.
  5. Should allow view­ing of food.

Standards

I was a bit annoyed to dis­cov­er the US FDA stan­dard Part 1030 in work­ing through the door design. The Aus­tralian microwave stan­dards sim­ply spec­i­fy a max­i­mum allowed exter­nal radi­a­tion lev­el. The US stan­dards cov­er the radi­a­tion lev­el, door inter­locks and also man­date the pres­ence of a user man­u­al, ser­vice man­u­al and a pair of warn­ing stick­ers. The EU stan­dards fur­ther pro­scribe dura­bil­i­ty tests.

Accord­ing to a com­plete­ly rep­utable source I actu­al­ly only have to com­ply with the Aus­tralian reg­u­la­tions, if I ship a prod­uct to the US then the per­son buy­ing it is con­sid­ered the importer and are respon­si­ble for the local com­pli­ance. This is a touch dodgy, even for me. My plan is to com­ply and cer­ti­fy with the rel­e­vant Aus­tralian, US and EU (IEC) stan­dards for a domes­tic microwave. As most coun­tries have for­mal­ly har­mo­nized with the IEC stan­dard or based their stan­dard off the US or Europe stan­dards I should actu­al­ly com­ply with basi­cal­ly every­one world­wide. I am not going to pay for hun­dreds of cer­ti­fi­ca­tion marks and the doc­u­men­ta­tion required to make it for­mal though.

Radiation leakage

All the stan­dards spec­i­fy lim­its on radi­a­tion leak­age. Dur­ing oper­a­tion a radi­a­tion detec­tor is moved around 5cm from the unit and the lev­el must not exceed 1mW/cm². The areas of con­cern are any holes in the cav­i­ty like air holes or the front view­ing pan­el, any seams to ensure they are weld­ed cor­rect­ly and my biggest con­cern is the edge around the sides of the door.

Delib­er­ate holes are the eas­i­est issue to han­dle. Radi­a­tion has a wave­length, for a microwave oven this is rough­ly 120mm. You can do com­plex maths around radi­a­tion holes by treat­ing them as wave­guides but it basi­cal­ly boils down to a 120mm wave needs a 120mm hole. As the hole gets small­er than 120mm you get an expo­nen­tial drop in the radi­a­tion slip­ping through. Often a hole less than 1/4 or 1/10th of the wave­length is approx­i­mat­ed as hav­ing zero trans­mis­sion. My Pana­son­ic microwave has holes of 1mm at the front, 2mm on the top and 3mm on the side, all less than 1/40th of the wave­length. I think the small holes are pre­ferred by the man­u­fac­tur­ers for their strength rather than due to radi­a­tion con­cerns.

The microwave radi­a­tion cav­i­ty is going to be made of sev­er­al sheets of met­al weld­ed togeth­er. As radi­a­tion can slip out a nar­row slit just as hap­pi­ly as a gap­ing hole care has to be tak­en at the joins to pre­vent this. My vic­tim microwaves both put a dent in just before the join to block the radi­a­tion from reach­ing the slit. The spot welds they used also seem to involve inden­ta­tion which would assist in break­ing up any slit, the welds are spaced every 22mm. Dents like that are a bit hard­er with my man­u­fac­tur­ing tech­niques but are pos­si­ble, I think this one can be solved in con­sul­ta­tion with the man­u­fac­tur­er and a lit­tle bit of test­ing.

Metal plate with a long dent parallel to the edge and a series of weld dents closer to the edge

Panasonic’s RF safe weld­ing join

The most con­cern­ing issue is the edges of the door. These are nice big slits, just per­fect for radi­a­tion to spew out of. Look­ing at the Sam­sung microwave I think the way this is gen­er­al­ly solved is very sneaky and clever. They haven’t fol­lowed the obvi­ous solu­tion of try­ing to cre­ate a tight seal, with the Sam­sung microwave door shut I can see light from a torch shin­ing through, a piece of paper moves with­out resis­tance. How­ev­er if you look close­ly the alu­mini­um out­er frame of the microwave over­laps the door by a few mm. I’ve checked and found this in three microwaves, all dif­fer­ent brands. I think what is hap­pen­ing is that the alu­mini­um lip catch­es the radi­a­tion that slips out and lim­its the amount that gets through. The lip isn’t present on the bot­tom, so I think they have been dif­fer­ent­ly sneaky there. For the test­ing of the device it would be rea­son­able to assume it would be placed a hor­i­zon­tal sur­face, the man­u­al prob­a­bly spec­i­fies this as the stan­dard oper­at­ing con­di­tion. This posi­tion would pre­vent the detec­tion device being placed 5cm below the microwave door, com­pli­ance achieved, prob­lem solved.

Door Interlocks

An inter­lock is a switch which pre­vents oper­a­tion of a device when it is open. For exam­ple robots often have a prox­im­i­ty sen­sor or gate, get too close and the robot imme­di­ate­ly shuts down. A com­mon exam­ple of this is the auto­mat­ed air­port bag drop sys­tems, if you are too close to your bag the con­vey­or will shut down. Giv­en that a microwave is a touch dan­ger­ous it is only sen­si­ble that we employ an inter­lock to pre­vent oper­a­tion when the door is open. How­ev­er US stan­dards require that we take this a fair bit fur­ther.

The US Fed­er­al Reg­u­la­tions are very spe­cif­ic about what safe­ty inter­lock must be employed and that spe­cial pro­vi­sion must be tak­en to pre­vent them from being dis­abled. Being able to dis­able an inter­lock is often a desired fea­ture, the think­ing is that if you want to delib­er­ate­ly bypass the safeties then you have cho­sen to accept the risk and know what you are doing. I assume some­body in the US dis­abled the inter­lock on their microwave and got fried, per­son­al­ly I feel they achieved their desired out­come but the reg­u­la­tor obvi­ous­ly felt dif­fer­ent­ly.

The reg­u­la­tions aren’t easy to read, it comes down to this exam­ple cir­cuit. Mod­ern microwaves have tweaked it slight­ly but all fol­low rough­ly this pat­tern. You have three switch­es, your pri­ma­ry inter­lock which shuts off pow­er to the sys­tem, your sec­ondary or mon­i­tor inter­lock which shorts the unpow­ered sys­tem and a sense switch for the con­trol log­ic. The com­bi­na­tion of these two inter­locks means that if either one of them fails or is dis­abled then the short cir­cuit caus­es the fuse to blow, as these are small mechan­i­cal com­po­nents this is a com­mon microwave fail­ure point.

There are addi­tion­al restric­tions how­ev­er, the pri­ma­ry inter­lock must be designed such that it can­not be delib­er­ate­ly dis­abled. Specif­i­cal­ly a mechan­i­cal inter­lock must be con­cealed such that it can’t be poked by any body part or straight object, a mag­net­ic inter­lock can’t be tripped by stick­ing a mag­net against the body of the microwave. Also the pri­ma­ry and mon­i­tor inter­locks must be mechan­i­cal­ly and elec­tri­cal­ly dis­tinct. The ubiq­ui­tous dou­ble hook design that every microwave uses makes far more sense with this under­stand­ing. A hook is required to meet the con­cealed require­ment and two hooks are required to keep things dis­tinct.

There are oppor­tu­ni­ties to vary the dou­ble hook pat­tern how­ev­er. A sin­gle hook could be used for the pri­ma­ry inter­lock with an alter­na­tive method used for the oth­er switch­es. A flex­i­ble stick would also meet the cri­te­ria if it was guid­ed into a bend. My pref­er­ence though is for a non-mechan­i­cal switch, some­thing more ele­gant to con­trast against the clunky nature of a door. For­tu­nate­ly there are lots of options. I am lean­ing towards a mag­net despite the restric­tions imposed by the stan­dard, I think with a non-mag­net­ic chas­sis I should be ok as it won’t self-sup­port and there are oth­er ways to skin the cat such as cod­ed mag­nets.

Durability

The European/International stan­dard is IEC 60335–2-25 ed6.1. I can’t actu­al­ly find a copy of the doc­u­ment so I might have to buy it. How­ev­er from the pub­lic doc­u­men­ta­tion you can see that it con­tains the restric­tions in the US reg­u­la­tions, with some slight vari­a­tion, and some addi­tion­al dura­bil­i­ty tests. I have found a brief write­up of the dura­bil­i­ty tests and the news isn’t good. I don’t think pass­ing the tests will be dif­fi­cult, just need decent hinges. How­ev­er get­ting the test house to open and shut the door 100,000 times is going to be expen­sive. Assum­ing one sec­ond to open the door and one sec­ond to close it, that is 56 hours of con­tin­u­ous test­ing using their 6-DOF robot. The oth­er tests will take anoth­er day, this has prob­a­bly just dou­bled my test­ing expens­es. I’ll build a basic push/pull robot for my pretest­ing which could be fun.

Options

Under­stand­ing the cri­te­ria I now have to design a door.
There are sev­er­al obvi­ous options, each with their own draw­backs.

I can design a clone of the stan­dard door and make my own. Start­ing with this one to get it out of the way. The cost of doing this makes it a non-starter. I spoke to the very help­ful staff at SK Plas­tic to under­stand the costs around injec­tion mold­ing. To build the latch for a microwave door would prob­a­bly cost rough­ly $10k-15k for the tool, $1 per part and some oth­er costs for the design and run start etc. At my pric­ing quan­ti­ty of 500 units the latch alone would come to rough­ly $26. The cost of the oth­er larg­er plas­tic parts would be high­er and the met­al screen would either have to be stamped (at least anoth­er $10k tool­ing) or every hold punched indi­vid­u­al­ly (sev­er­al dol­lars per sheet).

I can buy a door. All the doors are the same, so there is obvi­ous­ly a few com­pa­nies mak­ing these doors. A log­i­cal option would be to buy an exist­ing door, either whole or in parts. For exam­ple Aliba­ba has man­u­fac­tur­ers offer­ing the door latch, I haven’t enquired as to the price but expect it would be well under $1 per unit. Going half way down this path is dif­fi­cult, the stan­dard latch means I have to use the match­ing catch­es and microswitch­es with the relat­ed dura­bil­i­ty issues. The latch also dic­tates the thick­ness of the door, which push­es again towards plas­tics as met­al would be very heavy. Buy­ing exist­ing out­er plas­tics would result in the microwave hav­ing the same appear­ance as every oth­er microwave, prob­a­bly look­ing like the cheap end of the spec­trum as that is what is avail­able. Vac­u­um formed plas­tic is prob­a­bly with­in my price enve­lope as the set­up costs aren’t too bad, I am wary about a heat sen­si­tive plas­tic in a microwave but appar­ent­ly PET and HDPE can work.

I can design some­thing new. The big risk here is falling prey to not-invent­ed-here syn­drome and a belief that I my design skills are supe­ri­or to all the major man­u­fac­tur­ers com­bined. How­ev­er this entire exer­cise is essen­tial­ly pred­i­cat­ed on that case so I’ll just move on. Doing this will allow me to dif­fer­en­ti­ate the prod­uct in a way that is obvi­ous to any­one inter­act­ing with it. It will add time and cost to put it all togeth­er.

Going for­ward my plan A is going to be to design from scratch, plan B is to buy in com­po­nents. Get­ting half way through a scratch design and then buy­ing in parts where required would prob­a­bly be a rea­son­able com­pro­mise out­come so blun­der­ing for­ward on my own isn’t a total loss.

Draft design

The mod­ern microwave is almost entire­ly injec­tion mold­ed plas­tic and stamped steel, both tech­niques require mass pro­duc­tion I can’t rely on. My man­u­fac­tur­ing is pri­mar­i­ly ori­en­tat­ed around bend­ing sheet met­al and for the door, glass.

The pre­lim­i­nary design is for a met­al and glass sand­wich, in my head it is rather ele­gant. The lay­ers to the sand­wich are a met­al inner frame, glass plate, met­al RF mesh, glass plate, met­al out­er frame, some trim. Each glass sheet is 2mm thick, the met­al 1mm thick and the RF shield 1mm, so the total thick­ness is just 7mm com­pared to my Samsung’s 30mm. Being thin won’t just look awe­some, it also helps keep my weight down.

As bonus fea­tures I should also be able to get the door to open almost 180 degrees and be able to sup­port left hand­ed doors.

I have envis­aged that the sand­wich will be assem­bled and then the two met­al sheets spot weld­ed to seal the glass in. Then a trim piece of met­al glued on to cov­er the spot welds and pret­ty it up.

I am yet to set­tle on the hinges, latch or inter­lock mech­a­nisms. At the moment I am think­ing of them as acces­soris­ing for the door. Real­is­ti­cal­ly some tri­al and error is going to be required for all three of these areas.

Pencil sketch of the lower right corner of each layer showing their assembly and relative size.

Pen­cil sketch of door sand­wich

RF Shield

Every microwave I have seen has a sol­id met­al sheet in the front win­dow with cir­cu­lar holes stamped in it. The two microwaves I have mea­sured both have holes rough­ly 1mm in size. As dis­cussed ear­li­er this is 1/120th of the wave­length and exces­sive­ly cau­tious, inter­nal air vent holes are 3mm for exam­ple. The pat­tern is a trade­off between min­imis­ing the met­al between the holes, struc­tur­al strength and ease of clean­ing. I think with my door struc­ture the trade­off isn’t required so I can bet­ter opti­mise the vis­i­bil­i­ty.

A typ­i­cal guide­line for RF shield­ing is 1/4 of the wave­length allow­ing holes up to 3cm. Because it is eas­i­er to buy I am going to use a square hole, radi­a­tion is sneaky and can sneak out on the diag­o­nal so to main­tain 1/4 wave­length the square hole must be small­er than 21x21mm.

A wire mesh at 20x20mm is a fair­ly cheap option and at rough­ly 75% open area pro­vides bet­ter vis­i­bil­i­ty than the exist­ing microwaves. The RF per­for­mance will be worse than the exist­ing stan­dard due to the increased hole size and decreased thick­ness how­ev­er I think it should be with­in spec, test­ing will con­firm this before the design is finalised.

Poten­tial sup­pli­ers:

If I had suf­fi­cient quan­ti­ty what I real­ly want to do is have a piece of glass man­u­fac­tured with the met­al screen built into the glass. This would sig­nif­i­cant­ly reduce com­plex­i­ty by remov­ing the lay­ers and the glass would pro­tect the screen from dam­age. How­ev­er doing this would require a spe­cial man­u­fac­tur­ing rig with asso­ci­at­ed costs that can only be recov­ered with large quan­ti­ties.

Latch

Once closed the door has to stay closed until it is delib­er­ate­ly opened. I have a strong pref­er­ence for a latch that releas­es by being pulled on, the push but­ton to open design feels clum­sy to me. Again we have options :)

A hook latch is stan­dard in microwaves. The hook is on the door and hooks into a sta­t­ic hole on the body of the microwave. A spring on the hook keeps it closed until deli­brate­ly opened. A slope on the back of the hook allows it to be shut while closed, the hook slides up the latch until it is over then pulls shut. There are two com­mon open­ing mech­a­nisms, the stan­dard push but­ton works by phys­i­cal­ly push­ing against the hook to raise and released it. The doors you can sim­ply pull open have an oval shaped hook, basi­cal­ly a slope on the inside of the hook allows it to be pulled out much like it is pushed in.

Grav­i­ty is an inter­est­ing option. By mak­ing the door on an angle I can have it nat­u­ral­ly sit in the closed posi­tion but lit­tle force would be required to open it again. This would be cheap but have the down­sides of not look­ing stur­dy and not work­ing if the microwave wasn’t flat. Pair­ing this with a top open­ing door might work.

Spring loaded hinge is an easy solu­tion. Putting springs into hinge mech­a­nisms is fair­ly com­mon prac­tice for auto-clos­ing doors, gates or cup­boards. The spring hinge can be fit­ted with­out much addi­tion­al work and allows easy oper­a­tion. I don’t know if an auto­clos­ing door is an advan­tage or dis­ad­van­tage.

Mag­nets are awe­some. Mag­nets are also a pos­si­ble door latch mech­a­nism, the com­mon stain­less steel isn’t mag­net­ic so I would do this by putting a mag­net in both the door and body of the microwave. The mag­net would help close the door if it was almost closed and keep it closed until tugged open. Best of all I should be able to hide them so it just hap­pens mag­i­cal­ly.

Closed detection

Both my vic­tim microwaves have three microswitch­es that get hit by the latch when the door is closed. Two of these are used to imple­ment the stan­dards required inter­lock sys­tem, the third is a low volt­age sig­nal to the con­trol cir­cuit­ry.

The stan­dards require that there be at least two inde­pen­dent detec­tion devices, one of which must be tam­per resis­tant.

Again, there are mul­ti­ple options.

A hook latch paired with microswitch­es like every oth­er microwave. Rather bor­ing though.

Direct­ly push­ing a microswitch stuck on the sur­face, prob­a­bly hid­ing under a plas­tic film for clean­ing. This is sim­ple, noth­ing is required on the door and con­tact is mea­sure direct­ly. It doesn’t meet the tam­per resis­tant require­ments but is suit­able for a sec­ondary switch.

Mag­net­ic prox­im­i­ty detec­tion works by mount­ing a per­ma­nent mag­net on the door and then look­ing for it. For this to be tam­per resis­tant it can’t be trig­gered by plac­ing a mag­net on the microwave, I think this is free because a stain­less steel body shouldn’t be mag­net­ic. This cou­ples nice­ly with a mag­net­ic clos­ing mech­a­nism.

Light gate detec­tion much like a shop uses a light beam and mir­ror I can do the same. Requir­ing a mir­ror to be mount­ed on the door ful­fills the pri­ma­ry switch require­ments. I can prob­a­bly use pol­ished steel which would be reflec­tive enough to achieve this and with a tiny hole on the body it would be suf­fi­cient­ly mag­ic to be awe­some. The down­side is that any food or grime that block the mir­ror would pre­vent the switch from clos­ing. And being fair­ly mag­ic like it wouldn’t be obvi­ous which bit of grime was the prob­lem.

A rota­tion sen­sor posi­tioned in the hinge would also work. This would com­pli­cate the hinge area a bit but would meet all the require­ments for the pri­ma­ry switch. One could be placed on the top and bot­tom to get two inde­pen­dent con­trols. This would require a microchip for each sen­sor (ATTiny — yay!) to read the val­ue and con­trol a high volt­age relay but we are still in the few dol­lars price range.

Fifteen Twenty

I am pub­lish­ing my first Word­Press theme, Fif­teen Twen­ty. Born out of frus­tra­tion at the Word­Press theme struc­ture when attempt­ing to update the theme of this blog it demon­strates an alter­na­tive. This theme is designed as a tech­ni­cal demon­stra­tion of struc­tur­ing a Word­Press theme with a sin­gle core lay­out file. As this is an inver­sion of the stan­dard struc­ture of the default theme Twen­ty Fif­teen I have dubbed it Fif­teen Twen­ty. The appear­ance, styling and gen­er­at­ed html is the same as the orig­i­nal.

Word­Press is an open source blog­ging plat­form, it is the most pop­u­lar blog­ging plat­form with over 60 mil­lion web­sites using it. To enable all of these web­sites Word­Press has a theme sys­tem which allows the user to rad­i­cal­ly change the appear­ance of their blog with just a few clicks. Most of these themes are con­tributed by users but the Word­Press team does release a theme every year, this is the default theme and acts as a best prac­tices tem­plate for theme design­ers. The default themes are named after the year, the cur­rent one is Twen­ty Fif­teen.

Word­Press themes con­sist of a col­lec­tion of php tem­plate files. Word­Press choos­es a tem­plate based on the type of con­tent being request­ed, this allows a dif­fer­ent tem­plate to be used for search results or an audio attach­ment. The deci­sion is made using the tem­plate hier­ar­chy depict­ed below. Word­Press pro­ceeds from left to right until it finds a file which match­es the desired pat­tern, on the far right index.php acts as a catch all for any file types not spe­cial­ly han­dled.

The advan­tage of this struc­ture is that it allows for a huge degree of flex­i­bil­i­ty in the styling. Any con­tent can have a com­plete dif­fer­ent set of styling pro­vid­ed to it and the hier­ar­chy allows for very spe­cif­ic spe­cial­i­ty pages to be cre­at­ed.

The dis­ad­van­tage is that every tem­plate requires a dupli­ca­tion of the site struc­ture. Changes such as reorder­ing the HTML struc­ture require the rework­ing of every sin­gle tem­plate file, this was exact­ly the prob­lem I faced when work­ing on this blog’s tem­plate Piano Black.

In prac­tice I feel the theme hier­ar­chy struc­ture is a poor design choice as you want to retain the same look a feel across the entire site. This means that the lay­out is con­sis­tent and the vari­a­tions are typ­i­cal­ly iso­lat­ed to the cen­tral con­tent pane. Theme authors attempt to reduce the amount of dupli­ca­tion by using a head­er and foot­er file which is pulled into each tem­plate, this helps to reduce work for minor changes but makes struc­tur­al alter­ations even hard­er.

The alter­na­tive tech­nique is to have a sin­gle tem­plate file which sets the struc­ture of the web­site. This file then pulls in par­tial tem­plates based on the con­tent being request­ed. The par­tial tem­plates pro­vide a reduced lev­el of flex­i­bil­i­ty com­pared to the full tem­plate mod­el but are sim­pler as they do not need to include as much of the site’s struc­ture. The Twen­ty Fif­teen theme actu­al­ly uses both full and par­tial tem­plates, the par­tial tem­plates are used with­in the full tem­plates to cus­tomise dif­fer­ent cat­e­gories of posts.

I do not mean this as an attack or crit­i­cism of the Word­Press team, the choice was a trade off and they chose the more flex­i­ble approach lead­ing to a prod­uct far more suc­cess­ful than any I have ever pro­duced. This choice was also made for the ini­tial release in 2003, a dif­fer­ent online envi­ron­ment with alter­na­tive aes­thet­ic (MySpace) and less use of javascript. They have made a fan­tas­tic prod­uct and the flex­i­bil­i­ty built through it allows for nov­el uses, like mine.

By remov­ing all the cus­tom tem­plate files Word­Press will always use index.php as a tem­plate. As the tem­plate is a full php file it can exam­ine the request­ed con­tent type and pull in the required par­tial tem­plate. This tech­nique uses the Word­Press par­tial include func­tion which enables sub-themes to cus­tomise spe­cif­ic par­tials.

To demon­strate this lay­out tech­nique I chose to rework the Twen­ty Fif­teen theme as it is designed as a basis for theme authors to work from, which is also my goal. I took each of the tem­plate files and pushed the com­mon ele­ments up to index.php con­vert­ing them into a par­tial. The files designed to reduce dupli­ca­tion such as header.php, footer.php and sidebar.php were also pushed into index.php. I then set up a demo site using the wptest.io test data and used wget –mir­ror, HTML tidy, a tiny bit of sed and diff to beat the last bugs out and ensure that the final result was unchanged from the ini­tial Twen­ty Fif­teen design.

In the future I’ll be releas­ing my updat­ed ver­sion of Piano Black, this blog’s theme, with mobile sup­port (respon­sive lay­out) and oth­er mod­ernising updates under the hood. I may also make an Angu­lar­JS pow­ered demon­stra­tion ver­sion of Fif­teen Twen­ty for fun.

Return top