DotDragnet
February 04, 2012, 10:50:34 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: WordPress options page select category  (Read 841 times)
SLEE
Hero Member
*****
Posts: 815



View Profile WWW Awards
« on: April 27, 2010, 08:20:10 PM »

I am creating an options page for a site I am building and I have hit a problem that I have not noticed before and that is when selecting a category that has an ampersand (&) in the category name it will not show the correctly selected category when going back to the options page.

Is there a way around this?
I have tried using & but i guess as it contains the & it still errors.

This is for an options page, so I am using:

Code:
$categories_list = get_categories('hide_empty=0');

$categories = array();
foreach ($categories_list as $catlist) {
$categories[$catlist->cat_ID] = $catlist->cat_name;
}
array_unshift($categories, "Choose a category");

then

Code:
case 'select':
?>

<div class="tfh_input tfh_select">
<label for="<?php echo $value['id']; ?>"><?php echo $value['name']; ?></label>

<select name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>">
<?php foreach ($value['options'] as $option) { ?>
<option <?php if ( get_settings$value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option?></option><?php ?>
</select>
<small><?php echo $value['desc']; ?></small>
<div class="clearfix"></div>
</div>
<?php
break;

which i think is pretty standard?

Any ideas on how i can around this so it still works with the ampersand in the category name?
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
sarahA
DDN Contribs
Hero Member
*****
Posts: 2122



View Profile WWW Awards
« Reply #1 on: April 28, 2010, 07:49:01 AM »

I don't really understand your code with what you're saying (wanting to allow someone to select a category) but have you tried using the function wp_dropdown_categories to create your dropdown instead? http://codex.wordpress.org/Template_Tags/wp_dropdown_categories
Logged

JasonD
Global Moderator
Hero Member
*****
Posts: 529



View Profile Awards
« Reply #2 on: April 28, 2010, 02:32:29 PM »

If I understood correctly, you need to urlencode() the category when making the link.
Logged
SLEE
Hero Member
*****
Posts: 815



View Profile WWW Awards
« Reply #3 on: April 28, 2010, 02:43:24 PM »

@sarah that could be a solution but if possible id like it to work in this way. Basically it is a framework for creating an options page by telling it to be a select item and then you pass in the array for it to use:

Code:
array( "name" => "News Category",
          "desc" => "Choose News Category",
            "id" => $shortname."_news_cid",
            "std" => "",
            "type" => "select",
"options" => $categories),

I could of course create a type of selectcategory and then get it to use the dropdown which i may look into doing if i cannot do it this way.

@jason unfortunately it did this:
Code:
<option  value="News+%26amp%3B+Issues">News+%26amp%3B+Issues</option>
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
JasonD
Global Moderator
Hero Member
*****
Posts: 529



View Profile Awards
« Reply #4 on: April 28, 2010, 03:02:47 PM »

You would need to urlencode only in the value attribute and htmlspecialchars only the text.
Code:
<option  value="News+%26+Issues">News &amp; Issues</option>

But I'm not convinced that is what you want either. Is this an actual form that get's the values into the url? (in which case don't bother with the urlencode) Or is there some javascript magic standing in the way?
Logged
SLEE
Hero Member
*****
Posts: 815



View Profile WWW Awards
« Reply #5 on: April 29, 2010, 08:24:26 AM »

Thanks for the tips Jason.
It is for a form and the value is stored to be used (as an example) for checking the category you are on.
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!