【问题标题】:Display code dynamically in wp footer based on value in db根据 db 中的值在 wp 页脚中动态显示代码
【发布时间】:2017-10-22 18:17:57
【问题描述】:

我正在使用 wordpress 插件来显示房地产数据。当在 db 中找到某个值时,我需要在 wordpress 页脚中显示某个 sn-p 代码。细节。我已经使用以下函数显示了页脚代码:

// Adds Tucson Association of Realtors required board html to wp_footer()    
dynamically.
function wwidx_footer_script() { ?>
<div class="aztarfooter" style="text-align:center;">©2016 Tucson Association of Realtors. All rights reserved. All information deemed reliable, but Not Guaranteed. IDX information is provided exclusively for consumers' personal, non-commercial use and may not be used for any purpose other than to identify prospective properties consumers may be interested in purchasing.<br> <br><img src="https://www.weeboweb.com/wp-content/uploads/2016/10/tarlogo.gif"><br><img src="https://www.weeboweb.com/wp-content/uploads/2017/05/EHO-logo-e1494994377845.jpeg"> <img src="https://www.weeboweb.com/wp-content/uploads/2017/05/MLS_Clear-1-e1494994488609.jpg"></div>
<?php }
add_action( 'wp_footer', 'wwidx_footer_script' );

这个函数在我想要的位置和几乎想要的方式显示代码。问题是我需要让它动态化。在我的数据库中,有一个名为wp_realty_controlpanel 的表。在该表中,有一个名为controlpanel_masterdb_user 的字段。当该表中的值为"wwidx_az_tar" 时,我希望显示代码,否则不显示。您可以在这里Link 看到我想要的确切位置的 sn-p。

感谢任何帮助。

【问题讨论】:

    标签: php mysql database wordpress


    【解决方案1】:
    function wwidx_footer_script() {
        global $wpdb;
        $table_name = $wpdb->prefix . "realty_controlpanel";
        $results = $wpdb->get_row( "SELECT controlpanel_masterdb_user FROM $table_name WHERE controlpanel_masterdb_user = 'wwidx_az_tar' " );
        if( $results->controlpanel_masterdb_user == "wwidx_az_tar" ){ ?>
            <div class="aztarfooter" style="text-align:center;">©2016 Tucson Association of Realtors. All rights reserved. All information deemed reliable, but Not Guaranteed. IDX information is provided exclusively for consumers' personal, non-commercial use and may not be used for any purpose other than to identify prospective properties consumers may be interested in purchasing.<br> <br><img src="https://www.weeboweb.com/wp-content/uploads/2016/10/tarlogo.gif"><br><img src="https://www.weeboweb.com/wp-content/uploads/2017/05/EHO-logo-e1494994377845.jpeg"> <img src="https://www.weeboweb.com/wp-content/uploads/2017/05/MLS_Clear-1-e1494994488609.jpg"></div>
    <?php 
        }
    }
    add_action( 'wp_footer', 'wwidx_footer_script' );
    

    你能试试上面的代码吗?

    【讨论】:

    • 这是赢家。太感谢了!我给了你一票,但我的分数还不够高,无法显示。
    • @DominicGiusti 如果此答案对您有帮助,请将其标记为已批准,以便对其他人有所帮助。
    • 当然。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 2013-03-19
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    相关资源
    最近更新 更多