嗨,谢谢你的时间。我一直在尝试为我正在开发的项目创建一个wordpress插件。它包含汽车制造/型号/年的搜索表单。我遇到的问题是使用XML数据查询来填充make和model选项上的选项。到目前为止,这是我的代码:
编辑:我从XML获取了数据,现在只更新了我的代码,我缺少的是条件参数,它不起作用。我在代码中解决了这个问题<?php
/*
Plugin Name: Busqueda Rapida
Plugin URI:
Description: Plugin de busqueda rapida
Version: 1.0
Author:
Author URI:
*/
define( 'CD_PLUGIN_PATH', plugin_dir_path( __FILE__ ) );
define( 'CD_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
function html_form_code() {
$path = CD_PLUGIN_PATH . 'marcamodelo.xml';
$doc = simplexml_load_file($path);
echo '<div class="buswrap"> ';
echo '<form id="buscaForm" method="POST" action="">';
echo '<fieldset>';
echo '<select id="marca" name="marca" class="select">';
foreach($doc->marca as $marca)
{
$selected = '';
if ($marca['name'] == **WHAT GOES HERE?** ) { // This is the conditional statement that doesn't work
$selected = ' selected ';
}
echo "<option value='".$marca['name']."' $selected>".$marca['name']."</option>";
}
echo '</select>';
echo '<select id="modelo" name="modelo" class="select">';
// Code to get model goes here
echo '</select>';
echo '<select id="year" name="year" class="select">';
for($i = 1950; $i < date("Y")+2; $i++){
echo '<option value="'.$i.'">'.$i.'</option>';
}
echo '</select>';
echo '</fieldset>';
echo '<input type="submit" value="Buscar" id="search-bt" class="button">';
echo '</form>';
echo '</div>';
}
function generate_url() {
if(isset($_POST['marca'], $_POST['modelo'], $_POST['year'])) {
// gather all the values
$marca = urlencode($_POST['marca']);
$modelo = urlencode($_POST['modelo']);
$year = $_POST['year'];
// make a header redirect
header("Location: http://www.exampledomain.com/$marca/$modelo/$year");
exit;
}
}
function garaje_busqueda_rapida_shortcode() {
ob_start();
generate_url();
html_form_code();
return ob_get_clean();
}
add_shortcode( 'buscador-garaje', 'garaje_busqueda_rapida_shortcode' );
?>
我在这里缺少什么?有人能指出我正确的方向吗?非常感谢!