Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the end, what you want to use is what will be</p> <ol> <li>Easy to understand for someone else</li> <li>Convenient to you</li> </ol> <p>You've grasped the DRY - don't repeat yourself - principle. This is very good. If you have to change something in the future, you don't want to have to change the same thing in multiple places (it's not convenient). So if you repeat the same thing in several different template files, you can use <code>get_template_part</code>. This function renders <code>include()</code> obsolete.</p> <p>You could stick your code into a function that takes the meta key as an argument. This would be a pretty neat solution. It would be very convenient. The problem is that if someone else reads this template they will not immediately know how that function looks, since it's something custom that you made up, and they will have to find that function in order to figure it out.</p> <p>So perhaps your best bet is to use a foreach loop:</p> <pre><code>foreach( array( 'meta_key1', 'meta_key2' ) as $key ) { // Your code } </code></pre> <p>If the code is not too long and is mostly about displaying information not so much processing it, this could be a good solution. But this only works if the output you want to generate is adjacent. Otherwise you're stuck with having to create a function, and in that case you should put it in functions.php.</p> <p>If the code does a lot of processing of information you should probably put it in functions.php. The template files are for displaying stuff, and should be readable by designers with only a little PHP experience.</p> <p>(btw it's not wrong for functions to contain both PHP and HTML. All template tags essentially are such functions. WordPress does not encourage truly strict separation.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload