faevilangel_designs
faevilangel_designs Recent Posts Threads Started
83 posts
    Has been part of the Envato Community for over 4 years Sells items exclusively on Envato Market Located in United Kingdom
faevilangel_designs says

I have never really delved into the admin control functions (building themes that add a page to the admin menu).

I have always used pre-built widgets.

I read the codex and think I have it sussed but can someone who has done these, check for me.

functions.php
 // add menu
<?php add_action('admin_menu', 'mt_add_pages'); 
 add_options_page('simpl_options', 'simpl_options', 'administrator', 'simpl__options', 'simpl_options_page');

function simpl_options_page() {
?>
<div class="wrap">
<h2>Simpl Theme Options</h2>

<form action="&lt;?php $_SERVER['PHP_SELF']; ?&gt;" method="post">

&lt;?php settings_fields( 'simpl_theme' ); ?&gt;

<label>Featured Post Category Number:</label><br />
<input name="featured_post" type="text" value="&lt;?php echo get_option('featured_post'); ?&gt;" />
<br />
<input name="action" type="hidden" value="update" />
<input name="page_options" type="hidden" value="new_option_name" />

<p class="submit">
<input class="button-primary" type="submit" value="&lt;?php _e('Save Changes') ?&gt;" />
</p>
</form>
}
&lt;?php $featured_post = $_POST['featured_post']; 

function register_mysettings() { 
 register_setting( 'simpl_theme', 'featured_post' );
}

?&gt;
</div>

I’m building a featured post, and the $featured_post will store the category # then, I will call that in the index.php.

the code that uses the above,
 <?php query_posts('showposts='1'&cat='.$featured_post.'')?>

Is that code ok, or have i missed something?

cheers

53 posts
    Has been part of the Envato Community for over 5 years Has referred 1+ members Has sold $40,000+ on Envato Market Has collected 100+ items on Envato Market
+4 more
templateup says

looks alright,

you can add

add_menu_page(‘simpl_options’, ‘theme options’, ‘administrator’, ‘simpl__options’, ‘simpl_options_page’, ’’);

just below add_options_page to show a main menu button instead of the appearance>simpl_options button that isn’t as easy to find.

Will probably get messy copy and pasting all the setting fields you will have, I use a similar template to http://www.wpshout.com/create-an-advanced-options-page-in-wordpress/

by
by
by
by
by
by