Wordpress不显示数据库中的信息

时间:2015-11-13 18:00:23

标签: php wordpress

我对PHP和Wordpress都很陌生,我正在尝试从数据库中获取信息并将其显示在页面的各个位置。页面格式很好,但它没有用数据库中的信息填充它。我完全不知所措!我有一种感觉,问题出在代码的这一部分:

<?php
function objectToArray($form_obj) {

    if (is_object($form_obj)) {
        $form_obj = get_object_vars($form_obj);
    }

    if (is_array($form_obj)) {
        return array_map(__FUNCTION__, $form_obj);
    } else {
        return $form_obj;
    }

}

function get_data($url) {
    $ch = curl_init();
    $timeout = 31;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}
?> 

<div id="primary" class="content-area">
    <main id="main" class="site-main" role="main">
        <?php
        $query_string = $_SERVER['QUERY_STRING'];
        $query_vars = explode("=", $query_string);
        $id = $query_vars[1];
        $catalog = get_data('key to database is here');
        $catalog_item = json_decode($catalog_item);
        $catalog_item = objectToArray($catalog_item);
        $catalog_item = $catalog_item['rows'][0]['value'];
        ?>
        <?php while ( have_posts() ) : the_post(); ?>
        <article id="post-<?php the_ID(); ?>"
        <?php post_class(); ?>>
        <?php
        $directory_path = getcwd() . '/wp-content/uploads/';
        ?>
        <header class="entry-header">
            <?php
            $IMG_name = 'IMG-' . $catalog_item['c_cat_no'] .'.gif';
            if( file_exists($directory_path . $IMG_name) ){
            ?>
                <img src="/wp-content/uploads/<?=$IMG_name;?>" />
                <?php
            }
            ?>

0 个答案:

没有答案