当前位置: 动力学知识库 > 问答 > 编程问答 >

wordpress - custom field value which can change css class in custom post type

问题描述:

I have created portfolio page type in wordpress-theme with 3 column layout for portfolio item's. I want to create meta-box with drop down to select column number for portfolio list item (may be Images), so I can change column number from 1 column to 4 column layout. I have css class for list item which is responsible for 3 column layout. How can I change css class for list Item with custom field value to change number of column layout.

网友答案:

Ok. Create your custom field. Let's say "number_of_columns". Type your values in this custom field on each page. Then in your page template, just use get_post_meta to output the value in a CSS rule name, like this :

<div class="<?php get_post_meta($postid, 'number_of_columns', true); ?>_column_layout">
Create the layout here with the n_column_layout CSS class...
</div>

There you go. If number_of_columns was 2, you will get a div with the 2_column_layout class, etc. Right answer?

分享给朋友:
您可能感兴趣的文章:
随机阅读: