- This topic is empty.
-
AuthorPosts
-
February 11, 2014 at 8:04 pm #162644
cybershot
ParticipantI haven’t used select boxes much. I am using one in a new theme I am making. I have the dropdown and values working. The problem I have now is that the dropdown allows you to select a category that you want to display on a page in WordPress. When I choose my category and save the page, the first category in the list displays. I want the dropdown list to show the selected category.
February 11, 2014 at 8:27 pm #162646TheDoc
MemberAre you ending up on a category page? If so, that’s be quite easy:
<?php if( is_cat('Fun') { echo 'selected'; } ?>
If you’re actually using POST on a form you could do something like this:
<?php if( $form["category"] == 'cat-name' ) { echo 'selected'; } ?>
February 11, 2014 at 8:30 pm #162647TheDoc
MemberOf course, you’re probably not writing these out manually, so you could do something like this:
$categories=get_categories($cat_args); foreach($categories as $category) { echo "<option name.... yadda yadda }
February 11, 2014 at 8:42 pm #162649cybershot
ParticipantI am using the select in a page builder in the admin section of WordPress. It is being used to get the category to generate a shortcode that will call a custom loop to query that category
<option value="" default selected>Select your category</option> <option value="discography">Discography Page</option> <option value="contact">Contact Page</option> <option value="images">Images Page</option> <option value="news">News Page</option> <option value="shows">Shows Page</option> <option value="band">Band Page</option> <option value="videos">Videos Page</option>
The select box is inside a WordPress widget code. I was looking for something like the textbox has. Some way of showing the selected value.
February 11, 2014 at 8:54 pm #162651cybershot
ParticipantI just figured it out.
<option value="contact" <?php if($instance['cats'] == 'contact'){ echo 'selected'; } ?>>Contact Page</option>
February 12, 2014 at 9:59 am #162705TheDoc
MemberNice one! Hopefully what I provided helped!
February 12, 2014 at 10:02 am #162706cybershot
ParticipantYes, it helped. Thanks
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.