Get pages instead of categories.
-
Hi, I got a little snippet of a theme options page. It displays a select multiple list of all categories you got.
<?php $news_categories = get_categories(); $news_categories[] = false; ?> <select id="<?php echo $data['category']; ?>" name="<?php echo $data['category']; ?>[]" multiple="multiple" style="height:150px;"> <?php foreach($news_categories as $cat) : ?> <option value="<?php echo $cat->term_id; ?>" <?php if(is_array($val['category']) && in_array($cat->term_id, $val['category'])) echo ' selected="selected"'; ?>> <?php echo $cat->name; ?> </option> <?php endforeach; ?> </select>
So I want to display instead of categories, pages. I changed somethings and now it looks like
<?php $news_categories = get_pages(); $news_categories[] = false; ?> <select id="<?php echo $data['category']; ?>" name="<?php echo $data['category']; ?>[]" multiple="multiple" style="height:150px;"> <?php foreach($news_categories as $page) : ?> <option value="<?php echo $page->term_id; ?>" <?php if(is_array($val['category']) && in_array($page->term_id, $val['category'])) echo ' selected="selected"'; ?>> <?php echo $page->name; ?> </option> <?php endforeach; ?> </select>
What is wrong in this code?
– Steven.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Get pages instead of categories.’ is closed to new replies.