I have a basic understanding of PHP, but I feel like what I am trying to do could by done in a much simpler way. I am using PHP to display HTML content for a Wordpress theme. I want users to be able to determine the order in which HTML "blocks" are displayed. Currently I am using an if/elseif
setup. Here is an overly simplified example:
if ( $layout == 'layout_one' ) {
echo '<div class="header">Header</div>';
echo '<div class="content">Content</div>';
echo '<div class="footer">Footer</div>';
} elseif ( $layout == 'layout_two' ) {
echo '<div class="content">Content</div>';
echo '<div class="header">Header</div>';
echo '<div class="footer">Footer</div>';
} elseif ( $layout == 'layout_three' ) {
echo '<div class="footer">footer</div>';
echo '<div class="header">Header</div>';
echo '<div class="content">Content</div>';
}
Now, this technique becomes an absolute bear due to the shear number of layout options (permutations). So in my mind you would write a separate function for each HTML content block, and then in some way have another function that presents them in the order specified by the user. Or maybe putting all the blocks into an array and then reordering the array based on the layout selection...
Anyway, I have hit a wall on how to actually do this. Any guidance would be greatly appreciated. Thanks