下面的代码是wordpress自定义插件代码。我正在尝试以下链接中的代码:
http://code.tutsplus.com/tutorials/create-a-custom-wordpress-plugin-from-scratch--net-2668
<?php
if($_POST[\'oscimp_hidden\'] == \'Y\') {
//Form data sent
$dbhost = $_POST[\'oscimp_dbhost\'];
update_option(\'oscimp_dbhost\', $dbhost);
$dbname = $_POST[\'oscimp_dbname\'];
update_option(\'oscimp_dbname\', $dbname);
$dbuser = $_POST[\'oscimp_dbuser\'];
update_option(\'oscimp_dbuser\', $dbuser);
$dbpwd = $_POST[\'oscimp_dbpwd\'];
update_option(\'oscimp_dbpwd\', $dbpwd);
$prod_img_folder = $_POST[\'oscimp_prod_img_folder\'];
update_option(\'oscimp_prod_img_folder\', $prod_img_folder);
$store_url = $_POST[\'oscimp_store_url\'];
update_option(\'oscimp_store_url\', $store_url);
?>
<div class="updated"><p><strong><?php _e(\'Options saved.\' ); ?></strong></p></div>
<?php
} else {
//Normal page display
$dbhost = get_option(\'oscimp_dbhost\');
$dbname = get_option(\'oscimp_dbname\');
$dbuser = get_option(\'oscimp_dbuser\');
$dbpwd = get_option(\'oscimp_dbpwd\');
$prod_img_folder = get_option(\'oscimp_prod_img_folder\');
$store_url = get_option(\'oscimp_store_url\');
}
?>
<div class="wrap">
<?php echo "<h2>" . __( \'OSCommerce Product Display Options\', \'oscimp_trdom\' ) . "</h2>"; ?>
<form name="oscimp_form" method="post" action="<?php echo str_replace( \'%7E\', \'~\', $_SERVER[\'REQUEST_URI\']); ?>">
<input type="hidden" name="oscimp_hidden" value="Y">
<?php echo "<h4>" . __( \'OSCommerce Database Settings\', \'oscimp_trdom\' ) . "</h4>"; ?>
<p><?php _e("Database host: " ); ?><input type="text" name="oscimp_dbhost" value="<?php echo $dbhost; ?>" size="20"><?php _e(" ex: localhost" ); ?></p>
<p><?php _e("Database name: " ); ?><input type="text" name="oscimp_dbname" value="<?php echo $dbname; ?>" size="20"><?php _e(" ex: oscommerce_shop" ); ?></p>
<p><?php _e("Database user: " ); ?><input type="text" name="oscimp_dbuser" value="<?php echo $dbuser; ?>" size="20"><?php _e(" ex: root" ); ?></p>
<p><?php _e("Database password: " ); ?><input type="text" name="oscimp_dbpwd" value="<?php echo $dbpwd; ?>" size="20"><?php _e(" ex: secretpassword" ); ?></p>
<hr />
<?php echo "<h4>" . __( \'OSCommerce Store Settings\', \'oscimp_trdom\' ) . "</h4>"; ?>
<p><?php _e("Store URL: " ); ?><input type="text" name="oscimp_store_url" value="<?php echo $store_url; ?>" size="20"><?php _e(" ex: http://www.yourstore.com/" ); ?></p>
<p><?php _e("Product image folder: " ); ?><input type="text" name="oscimp_prod_img_folder" value="<?php echo $prod_img_folder; ?>" size="20"><?php _e(" ex: http://www.yourstore.com/images/" ); ?></p>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e(\'Update Options\', \'oscimp_trdom\' ) ?>" />
</p>
</form>
</div>
配置文件数据如下所示:数据库主机:localhostdatabase名称:osc234database用户:rootpassword:passwordOSCommerce存储设置
Stroe URL:http://localhost:8383/osc-234/目录/索引。phpproduct映像文件夹:http://localhost:8383/osc-234/目录/图像
模板侧栏。php代码我放置了下面的代码
但我不确定我是否放在了正确的位置。图像未显示在前端。
我的侧边栏。php现在如下所示:
<?php
/**
* Sidebar containing the main widget area
*
* @package WordPress
* @subpackage Twenty_Eleven
* @since Twenty Eleven 1.0
*/
$options = twentyeleven_get_theme_options();
$current_layout = $options[\'theme_layout\'];
if ( \'content\' != $current_layout ) :
?>
<div id="secondary" class="widget-area" role="complementary">
<?php if ( ! dynamic_sidebar( \'sidebar-1\' ) ) : ?>
<aside id="archives" class="widget">
<h3 class="widget-title"><?php _e( \'Archives\', \'twentyeleven\' ); ?></h3>
<ul>
<?php wp_get_archives( array( \'type\' => \'monthly\' ) ); ?>
</ul>
</aside>
<aside id="meta" class="widget">
<h3 class="widget-title"><?php _e( \'Meta\', \'twentyeleven\' ); ?></h3>
<ul>
<?php wp_register(); ?>
<li><?php wp_loginout(); ?></li>
<li><?php echo oscimp_getproducts(3); ?></li>
<?php wp_meta(); ?>
</ul>
</aside>
<?php endif; // end sidebar widget area ?>
</div><!-- #secondary .widget-area -->
<?php endif; ?>
SO网友:user95017
谢谢你的回复。oscommer\\u导入程序。php文件已尝试从products表中检索字段。我把它附在这里了。
`
<?php
/*
Plugin Name: OSCommerce Product Display
Plugin URI: http://localhost:8383
Description: Plugin for displaying products from an OSCommerce shopping cart database
Author: Priya Mohan
Version: 1.0
*/
function oscimp_admin() {
include(\'oscommerce_import_admin.php\');?>
<?php
}
function oscimp_admin_actions() {
add_options_page("OSCommerce Product Display", "OSCommerce Product Display", 1, "OSCommerce Product Display", "oscimp_admin");
}
add_action(\'admin_menu\', \'oscimp_admin_actions\');
function oscimp_getproducts($product_cnt=1) {
//Connect to the OSCommerce database
$oscommercedb = new wpdb(get_option(\'oscimp_dbuser\'),get_option(\'oscimp_dbpwd\'), get_option(\'oscimp_dbname\'), get_option(\'oscimp_dbhost\'));
$retval = \'\';
for ($i=0; $i<$product_cnt; $i++) {
//Get a random product
$product_count = 0;
while ($product_count == 0) {
$product_id = rand(0,30);
$product_count = $oscommercedb->get_var("SELECT COUNT(*) FROM products WHERE products_id=$product_id AND products_status=1");
}
//Get product image, name and URL
$product_image = $oscommercedb->get_var("SELECT products_image FROM products WHERE products_id=$product_id");
$product_name = $oscommercedb->get_var("SELECT products_name FROM products_description WHERE products_id=$product_id");
$store_url = get_option(\'oscimp_store_url\');
$image_folder = get_option(\'oscimp_prod_img_folder\');
//Build the HTML code
$retval .= \'<div class="oscimp_product">\';
$retval .= \'<a href="\'. $store_url . \'product_info.php?products_id=\' . $product_id . \'"><img src="\' . $image_folder . $product_image . \'" /></a><br />\';
$retval .= \'<a href="\'. $store_url . \'product_info.php?products_id=\' . $product_id . \'">\' . $product_name . \'</a>\';
$retval .= \'</div>\';
}
return $retval;
}
?>
`我检查了日志文件,没有php错误。我有点觉得商店url和产品图片url给错了。
存储URL:[http://localhost:8383/wordpress/][1]
产品图像文件夹:[http://localhost:8383/osc-234/catalog/images/][1]
当我尝试使用其他链接存储url和产品图像文件夹时,它显示了X而不是图像。(图像未显示,但显示了X等符号)请帮助