Display Editable Text Above CPT Archive Listings

One of the easiest (although not the only) of ways to achieve this is by creating a custom options panel in the WP dashboard that will allow your client to create and update information that can be used through out your template files with no technical knowledge being necessary.

You can either paste the following directly into your functions.php file or you can save it in a file i.e. config-menu.php (within your theme directory) and then include it into your functions.php file – the choice is yours however the code is;

// create config menu in dashboard
add_action('admin_menu', 'config_menu');

function config_menu() {

    //create a menu in the dashboard
    add_menu_page('Website Custom Settings',
                  'Configure Site', 
                  'administrator',
                  __FILE__,
                  'custom_settings_page',
                  ''.get_bloginfo('template_directory').'/images/your_icon.png', 4);

}

//register settings
add_action( 'admin_init', 'register_settings' );

function register_settings() {

    register_setting(   'my-settings-group', 'partners');
    register_setting(   'my-settings-group', 'authors');
}

function my_settings_page() {
?>

<div class="wrap">

    <form method="post" action="options.php">

    <?php settings_fields('my-settings-group'); ?>

    Enter your Partner description here <br/>
    <textarea  name="partners"><?php echo get_option('partners');?></textarea>

    <br />

    Enter your Author description here <br/>
    <textarea  name="authors"><?php echo get_option('authors');?></textarea>
    <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />

    </form>

</div>

<?php } ?>

Then in your archive template files for each post type you can do the following;

<?php echo wpautop(get_option('partners');?>

and

<?php echo wpautop(get_option('authorss');?>

This will call the respective values (text entered) into the textarea fields you have created in the dashboard area for the client.

NOTE: The example code above is very rudementary and its stripped down to provide you a basic example. No CSS styling provided which I’ll leave up to you. But this will get the job done.

Leave a Comment