简体   繁体   English

勾选复选框后,wordpress选项标题将不会显示在网站上

[英]wordpress option title won't appear on site when checkbox ticked

I have an issue with displaying information if a checkbox is ticked. 如果勾选了复选框,则显示信息时会出现问题。 I believe the if statement is incorrect. 我相信if语句不正确。

Below is the code from my options page: 以下是我的选项页中的代码:

<div class="admin-options">Title:<input type="checkbox" name="option_title" value="1" <?php checked( '1', get_option( 'option_title' ) ); ?> ></div>  

 register_setting( 'option_control', 'option_title' );       

This is the code sent to display: 这是发送给显示的代码:

 function display_option_title() {     

if (get_option('option_title') == 1 || get_option('option_title') <> ''){
echo ' 
<a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<h2><?php the_title(); ?></h2></a>
';
 }
 }

 add_action( 'print_option_title', 'display_option_title' );     

Any help would be most helpful. 任何帮助将是最有帮助的。

You are using php tags in your string, so it won't be parsed. 您在字符串中使用了php标记,因此不会对其进行解析。

Use it like this: 像这样使用它:

function display_option_title() {
    if (get_option('option_title') == 1 || get_option('option_title') <> '') {
        ?>
        <a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
            <h2><?php the_title(); ?></h2>
        </a>
        <?php
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM