Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Dynamically change display different layouts / styling. WordPress

  • SOLVED

Hi All,

I am creating a WordPress theme at the moment, which has the ability for the user to select the following options, with the admin area:

- Number of article blocks to display

Then, depending on how many they select, they have the ability to add the following options, for each number selected:

- Select category (dropdown list of categories to display posts)
- Article Colour (colour of the article)
- Article Layout (dropdown list of a number of article layouts)

So within the admin area, I have the following fields, which is displaying this information:

Number of articles = <strong>number_of_categories</strong>
Select category = <strong>select_category1</strong>*
Article Colour = <strong>select_category_colour1</strong>*
Article Layout = <strong>select_category_layout1</strong>*

I have the fields that have an <strong>*</strong> next to them repeated 10 times, with the associated number next to them. For example, the tenth article layout will have a field name of <strong>select_category_layout10</strong>

-----------------------------------------------------------------------------

All of that data is working correctly and being saved within the admin option panel, however I want to dynamically pull out all of this information, pulling out the number of options, depending on the number of article they wish to display.

Can somebody help out with this?

This may help, but I currently pull out the admin options by using the following code:

<?php if ( $options['number_of_categories'] ) { ?>
<?php echo $options['number_of_categories'] ?>
<?php } ?>

Thanks for your help with this...

Answers (1)

2014-10-23

Arnav Joy answers:

try this

<?php if ( $options['number_of_categories'] ) {


echo $options['number_of_categories'] ;

echo '<br>';

for( $i=1;$i<=$options['number_of_categories'];$i++){
echo 'Article Colour '.$i.' == '.$options['select_category_colour'.$i];

echo '<br>';

echo 'Article Layout '.$i.' == '.$options['select_category_layout'.$i];
}
} ?>


craigfarrall comments:

Hi Arnav,

Thanks for getting back to me so quickly.

I tried what you provided and it pretty much works. It displays all of the information that I was looking for, however I wanted to modify this slightly, to incorporate the layouts I have created, so I used the following code:


<?php if ( $options['number_of_categories'] ) { ?>
<?php echo $options['number_of_categories'] ; ?>
<?php for( $i=1;$i<=$options['number_of_categories'];$i++) { ?>

<?php echo 'Article Layout '.$i.' == '.$options['select_category_layout'.$i]; ?>

<?php if ( $options['select_category_layout'.$i] == 'Two Columns' ) { ?>
<?php include(TEMPLATEPATH . '/includes/two_columns.php'); ?>
<?php } elseif ( $options['select_category_layout'.$i] == 'Three Columns' ) { ?>
<?php include(TEMPLATEPATH . '/includes/three_columns.php'); ?>
<?php } elseif ( $options['select_category_layout'.$i] == 'Three Columns' ) { ?>
<?php include(TEMPLATEPATH . '/includes/five_columns.php'); ?>
<?php } ?>

<?php } ?>
<?php } ?>


If I display two article blocks for example, it is only showing one. Do you know why this would be? It seemed to stop displaying this once I add the conditional if statement for the layouts.

On another note, do you know how I can keep a separate layout files for each layout, whilst also passing through the values from, such as colours?

Please let me know.

Thanks for your help so far...


Arnav Joy comments:

are you sure this or other else if condition meets your condition

$options['select_category_layout'.$i] == 'Two Columns'


craigfarrall comments:

It seems to be, yes.

I fixed a quick typo in there, so that the template for five columns, goes into the correct layout.

It strange, because it displays the first one that is echo out, but doesn't echo the second one out. I have attached a screenshot to illustrate this.

As you can see with the first echo, it should be displaying two blocks.

Thanks...