$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>php - Show different button text if no content|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - Show different button text if no content

matteradmin7PV0评论

With this code:

<?php if ( $clpr_options->coupon_code_hide ) {
            $button_text = fl_get_option( 'fl_lbl_show_coupon' );
            $button_text = '<i class="icon-lock"></i>' . $button_text;
            $class .= ' coupon-hidden';
            }
         ?>

I get a special Text show on a button. Now I would like to show a special button_text if the field clpr_coupon_codeis empty.

Tried

<?php if ( $clpr_options->coupon_code_hide ) {
            $button_text = fl_get_option( 'fl_lbl_show_coupon' );
            $button_text = '<i class="icon-lock"></i>' . $button_text;
            $class .= ' coupon-hidden';

            } else {
            $class .= ' coupon-hidden';
            $meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );} 
            $meta == '';
            $button_text = 'Angebot anzeigen';

            }
         ?>

But just getting empty page.

With this code:

<?php if ( $clpr_options->coupon_code_hide ) {
            $button_text = fl_get_option( 'fl_lbl_show_coupon' );
            $button_text = '<i class="icon-lock"></i>' . $button_text;
            $class .= ' coupon-hidden';
            }
         ?>

I get a special Text show on a button. Now I would like to show a special button_text if the field clpr_coupon_codeis empty.

Tried

<?php if ( $clpr_options->coupon_code_hide ) {
            $button_text = fl_get_option( 'fl_lbl_show_coupon' );
            $button_text = '<i class="icon-lock"></i>' . $button_text;
            $class .= ' coupon-hidden';

            } else {
            $class .= ' coupon-hidden';
            $meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );} 
            $meta == '';
            $button_text = 'Angebot anzeigen';

            }
         ?>

But just getting empty page.

Share Improve this question asked Nov 22, 2018 at 18:52 joloshopjoloshop 211 silver badge8 bronze badges 4
  • There's an unwanted } after the get_post_meta() call - true );}, and what is that $meta == ''; doing? – Sally CJ Commented Nov 22, 2018 at 19:46
  • removed the } the $meta == ' '; is checking if meta is empty. – joloshop Commented Nov 22, 2018 at 19:56
  • still not working just stuck – joloshop Commented Nov 22, 2018 at 20:14
  • Check and try my answer? – Sally CJ Commented Nov 22, 2018 at 20:31
Add a comment  | 

1 Answer 1

Reset to default 0

First off, as I mentioned in the comment, you got a syntax error here, where there's an unwanted }:

$meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );} // <- that }

(Updated answer — Previous code were removed since they didn't work for you.)

So if you want to show the special text when $clpr_options->coupon_code_hide does not evaluate to a true and that the field clpr_coupon_code is empty; try this:

<?php if ( $clpr_options->coupon_code_hide ) {
    $class .= ' coupon-hidden';
    $meta = get_post_meta( $post->ID, 'clpr_coupon_code', true );

    // If clpr_coupon_code is empty.
    if ( ! $meta ) {
        $button_text = 'Angebot anzeigen';
    // If clpr_coupon_code is not empty.
    } else {
        $button_text = fl_get_option( 'fl_lbl_show_coupon' );
        $button_text = '<i class="icon-lock"></i>' . $button_text;
    }
}
?>

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far