doubo4336 2014-12-01 21:17
浏览 12

无法获取wordpress插件来填充xml文件中的选择选项。 (自定义wordpress插件)

Hi and thank you for your time. I´ve been trying to create a wordpress plugin for a project that i'm working on. it consist in a search form for cars make/model/year. The issue i'm having is with the XML data query to populate the option on the make and model selects. This is my code so far:

EDIT: I got the data from the XML, just updated my code now what im missing is the conditional argument which is not working. I arked it in the code

<?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' );

?>

What am i missing here? Can anyone point me to the right direction please? thanks a lot in advance!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序