dsw7547 2014-11-16 01:01
浏览 47
已采纳

自定义帖子类型元框单选按钮输出

I like to do a simple thing with my custom meta box, but i d'ont find a (easy) solution for this problem.

I have done a custom post type with some meta boxes => text, textarea, select fields, ect.

all work just fine. Now if i set the button to sold,(see code excerpt from the radio array below) the text(div) should be red; if i set it to for_sale, it should be green.

but i have no idea how to do this, i mean there are this two states possible. nothing else. and that is what i want. but the html output is only text. or text in a html-tag, this i can style with css, but it would be red, or it is blue, green what else i sett it. is there a simple thing, like a class to set for each value? i c'ant find an answer. i hope i have explained it understandable. thanks so much for taking time for this.

array(
'label' => 'Status',
'desc'  => 'product status',
'id'    => $prefix.'radio_status',
'type'  => 'radio',
'options' => array (
    'one' => array (
        'label' => 'Product for sale',
        'value' => 'for_sale'
    ),
    'two' => array (
        'label' => 'Product is sold',
        'value' => 'is_sold'
    ),
),
),

EDIT :)

<span class="saleBox"><span class="noBox"><?php echo $post_meta_data['custom_radio_status'][0]; ?></span></span>

Thats the HTML, and what i get is the value thats setted.

<span class="saleBox"><span class="noBox">for sale</span></span>

or then: *soled

So i need a Output with a true-value, or class, ID,... something that i can adress with css.


A good idea that works. only thing that i doesen't understand is, is must call the array.

<?php $post_meta_data = get_post_custom($post->ID); ?>

if i call only the specific data:

<?php get_post_meta($post->ID, 'custom_radio_status', true) ?>

for me, it won't. or i made a typo. it doesen't matter i works!

thank you mr. Maguire

  • 写回答

1条回答 默认 最新

  • dsdapobp26141 2014-11-16 09:58
    关注

    Put a conditional statement, something like:

    <span class = "
    <?php
        if ($post_meta_data['custom_radio_status'][0] == "is_sold"){
            echo "red_class";
         }else{
            echo "green_class";
        }
    ?>
    ">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路