Jump to content

Tsalagi

Members
  • Posts

    17
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Tsalagi's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks. I'm not sure about data persistence but since I'm learning, I'll look into it.
  2. I have some code that I think would be best off in a class or some other more efficient practice but I'm not versed in OOP so I'm looking for suggestions. The three lines of code here represent a whole block of code. In that block the functions can be repeated several times with the arguments always different. Any suggestions? I've commented to code to explain it's relation. register_setting( 'features', THEME.' Features', 'validate_features' ); //There may be many of these functions related to only one register_setting() function add_settings_section('main_section', 'Main Settings', 'section_cb', __FILE__); //There may be many of these related to only one add_settings_section() function. Note the final argument "main_section" drawing the relationship add_settings_field('banner_heading', 'Banner Heading:', 'banner_heading_setting', __FILE__, 'main_section'); add_settings_field('footer_text', 'Footer Text:', 'footer_text_setting', __FILE__, 'main_section'); Thanks in advance.
  3. I have a file I'm trying to split up to separate some HTML from PHP code. Everything works fine when all of the code is together but when I split it into two files the two call back functions in the html form will not work. No errors and when I view the page source my file is included with the form. Any help would be appreciated. Here is the file that has the include statement. add_action('admin_menu', 'sampleoptions_add_page_fn'); // Add sub page to the Settings Menu function sampleoptions_add_page_fn() { add_options_page('Options Example Page', 'Options Example', 'administrator', __FILE__, 'options_page_fn'); } function options_page_fn() { ?> <?php include('options_form.php'); ?> <?php } Here is the options_form.php file code. <div class="wrap"> <div class="icon32" id="icon-options-general"><br></div> <h2>My Example Options Page</h2> Some optional text here explaining the overall purpose of the options and what they relate to etc. <form action="options.php" method="post"> <?php settings_fields('plugin_options'); ?> <?php do_settings_sections(__FILE__); ?> <p class="submit"> <input name="Submit" type="submit" class="button-primary" value="<?php esc_attr_e('Save Changes'); ?>" /> </p> </form> </div> I'm guessing that it may have to do with this line of code, due to the page parameter but I don't know that much about that area. <?php do_settings_sections(__FILE__); ?> Thanks in advance
  4. Okay. I'll have to re-plan this one. Thanks a bunch! Thanks for the link to post rules too.
  5. Thanks. That works if I want to use it outside of another function, but when I want to use it as a parameter it doesn't work. I tried putting $ct into an array which I can use print_r to view it but I don't know how to target $ct->title as a $key $value pair and then pass that into a variable using a foreach statement. Any suggestions?
  6. I would right a quick check to see if you are connected to your database. if ($conn) echo "You're Connected" Good place to start.
  7. I'm not versed in PHP OOP and I have some code that I need to echo out onto a page. I don't know what the meaning of $ct->something is in this code. Is this an array of some type? How do I echo out the $ct->title onto another page? Use a function call? I just don't know what all of the $ct variables are and how to get to them. Any help is appreciated. function current_theme_info() { $themes = get_themes(); $current_theme = get_current_theme(); if ( ! isset( $themes[$current_theme] ) ) { delete_option( 'current_theme' ); $current_theme = get_current_theme(); } $ct->name = $current_theme; $ct->title = $themes[$current_theme]['Title']; $ct->version = $themes[$current_theme]['Version']; $ct->parent_theme = $themes[$current_theme]['Parent Theme']; $ct->template_dir = $themes[$current_theme]['Template Dir']; $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir']; $ct->template = $themes[$current_theme]['Template']; $ct->stylesheet = $themes[$current_theme]['Stylesheet']; $ct->screenshot = $themes[$current_theme]['Screenshot']; $ct->description = $themes[$current_theme]['Description']; $ct->author = $themes[$current_theme]['Author']; $ct->tags = $themes[$current_theme]['Tags']; $ct->theme_root = $themes[$current_theme]['Theme Root']; $ct->theme_root_uri = $themes[$current_theme]['Theme Root URI']; return $ct; }
  8. Thanks Premiso for the reply. The code was output into a table and styled there. I decided to break to table down into divs and style them. I can't believe people are still using tables for styling. Oh well it was good practice and it looks terrific! Thanks again
  9. Howdy! I've racked my brain over this for 24 hours now. I think it's time I asked for help. I'm learning PHP and believe my I've manipulated many code blocks trying to get this to work with for and foreach and while statements. There must be something I'm missing in my studies about arrays but anyway here is the issue. I have a multidimensional array. From that array I would like to extract only the values of a specific key['name'] so that I can then output it into html form with a special identifier. I was able to do this with nested if statements but that seemed a bit overkill to me. Here is the code I came up. I know there has to be a more efficient way of getting these results. Here is the Array code: $options = array( array( "name" => "General Administrative Settings", "type" => "title"), array( "type" => "open"), array( "name" => "Colour Scheme", "desc" => "Which colour scheme would you like?", "id" => $shortname."_colourscheme", "type" => "select", "std" => "Choose a colour scheme:", "options" => $styles), array( "name" => "Portfolio Category", "desc" => "Select the category portfolio items are being posted in.", "id" => $shortname. "_portfolio_cat", "type" => "select", "std" => "Choose a category:", "options" => $getcat), array( "name" => "Definition List", "desc" => "Select the page used as a definition list page.", "id" => $shortname."_definition_list", "type" => "select", "std" => "Select a page:", "options" => $getpag), array( "name" => "Blog page", "desc" => "Select the page to be used as a blog (post) page.", "id" => $shortname."_blogpage", "type" => "select", "std" => "Select a page:", "options" => $getpag), array( "type" => "close") ); Here is my output code: <?php if($options['name'] = "Colour Scheme"){ echo '<div id="col_schm">Colour Scheme</div>'; if($options['name'] = "Definition List") { echo '<div id="def_lst">Definition List</div>'; } } ?> If you can help I would appreciate it. Thanks in advance
  10. Thanks that got rid of one error but produced a parse error at the endforeach line. I've scanned the code over and over and can't see any missing elements. thanks for your time
  11. I'm getting a parse error with this simple code. I don't get it. It worked one time then when I reloaded the page in FF the code throws this parse error. Parse error: parse error in C:\wamp\www\bmreader.php on line 7 Line 7 is where the HTML Doctype line begins. Thanks in advance. Here is the code. <?php // This makes sure that the content is sent to the browser as text/html and the UTF-8 character set (since we didn't change it). $feed->handle_content_type(); // Let's begin our XHTML webpage code. The DOCTYPE is supposed to be the very first thing, so we'll keep it on the same line as the closing-PHP tag.> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Sample SimplePie Page</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <style type="text/css"> body { font:12px/1.4em Verdana, sans-serif; color:#333; background-color:#fff; width:700px; margin:50px auto; padding:0; } a { color:#326EA1; text-decoration:underline; padding:0 1px; } a:hover { background-color:#333; color:#fff; } div.header { border-bottom:1px solid #999; } div.item { padding:5px 0; border-bottom:1px solid #999; } div.image { height:250px; width:250px; border:3px solid blue; } </style> </head> <body> <?php $feed = file_get_contents("http://www.nasa.gov/rss/image_of_the_day.rss"); $xml = new SimpleXmlElement($feed);?> <?php foreach ($xml->channel->item as $entry){ echo $entry->title; echo $entry->description; } endforeach; ?> </body> </html>
  12. Here are all three files. I changed the extension of the ocw.opml to txt so I could include it. Just change it back to opml. Thanks for your help [attachment deleted by admin]
  13. Thanks MadTechie. I made the changes you suggested and this is what was rendered In FF and IE. Warning: Variable passed to each() is not an array or object in C:\wamp\www\ocw\parser.php on line 91 Notice: Undefined variable: retval in C:\wamp\www\ocw\parser.php on line 104. I placed the code you suggested in the body, nested between "<?php ?>" tags. I know very little about this type of php usage. Maybe I'm mucking up the placement. Thanks again for your help.
  14. Howdy! This code was taken from another site and is open source. I'm trying to use it to parse an xml file with oplm attributes and display it on a web page. On line 29 of the parser.php file there is a parameter for the getContents function that I think needs the url to the ocw.xml file. That file is located in the same directory and I insert the file name here. Then on my index.php page I use include once php method to call the parser.php file. Here is the code to the parser.php file. I may be approaching this in the wrong way and I would appreciate some direction. <?php class IAM_OPML_Parser { var $parser; var $data; var $index = 0; // Outline items we wish to map and their mapping names: link_url, link_name, link_target, link_description... var $opml_map_vars = array('URL' => 'link_url', 'HTMLURL' => 'link_url', 'TEXT' => 'link_name', 'TITLE' => 'link_name', 'TARGET' => 'link_target','DESCRIPTION' => 'link_description', 'XMLURL' => 'link_rss', "CREATED"=>'created', 'TYPE'=>'type'); function OPML_Parser() { $this->parser = null; $this->data = ''; } /** * IAM_OPML_Parser::getContent() * Fetch Contents of Page (from URL). * * @param string $url * @return string contents of the page at $url */ function getContent($url=ocw.xml') { $html = @file_get_contents($url); return $html; } function ParseElementStart($parser, $tagName, $attrs) { $map = $this->opml_map_vars; if ($tagName == 'OUTLINE') { foreach (array_keys($this->opml_map_vars) as $key) { if (isset($attrs[$key])) { $$map[$key] = $attrs[$key]; } } // save the data away. $this->data[$this->index][names] = $link_name; $this->data[$this->index][urls] = $link_url; $this->data[$this->index][targets] = $link_target; $this->data[$this->index][feeds] = $link_rss; $this->data[$this->index][descriptions] = $link_description; $this->data[$this->index][created] = $created; $this->data[$this->index][type] = $type; $this->index++; } // end if outline } function ParseElementEnd($parser, $name) { // nothing to do. } function ParseElementCharData($parser, $name) { // nothing to do. } function Parse($XMLdata) { $this->parser = xml_parser_create(); xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, array(&$this, 'ParseElementStart'), array(&$this, 'ParseElementEnd')); xml_set_character_data_handler($this->parser, array(&$this, 'ParseElementCharData')); xml_parse($this->parser, $XMLdata); xml_parser_free($this->parser); } function list_contents($arrayname, $tab = " ", $indent = 0) // recursively displays contents of the array and sub-arrays: { // This function (c) Peter Kionga-Kamau (http://www.pmkmedia.com) // Free for unrestricted use, except sale - do not resell. // use: echo LIST_CONTENTS(array $arrayname, string $tab, int $indent); // $tab = string to use as a tab, $indent = number of tabs to indent result while (list($key, $value) = each($arrayname)) { for($i = 0; $i < $indent; $i++) $currenttab .= $tab; if (is_array($value)) { $retval .= "$currenttab$key : Array: <BR>$currenttab{<BR>"; $retval .= $this->list_contents($value, $tab, $indent + 1) . "$currenttab}<BR>"; } else $retval .= "$currenttab$key => $value<BR>"; $currenttab = null; } return $retval; } function getFeeds($opml_url) { $this->index = 0; $this->Parse($this->getContent($opml_url)); $this->index = 0; return $this->data; } function displayOPMLContents($opml_url, $tab = " ") { echo $this->list_contents($this->getFeeds($opml_url), $tab, 0); } } ?> I'm testing on a wamp server localy Thanks in advance
  15. This issue has been solved by passing values to avariable with a form thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.