1

I want to allow my client to change some introductory text on a custom post archive page (eg. archive-unicorn.php), but I can't see how to do this.

I guess one way I could do this is would be to create a page template page instead (eg. page-unicorn.php), and use query_posts() to get when I want on the page instead.

What's the best way to do this?

1
  • /u/gmazzap and /u/kraftner posted some good answers to a similar question. Pretty much allows the user to assign a fake template to a page then some hooks will pull that page title and content to supplement that data using post_type_archive_title() and such which I find to be pretty good methods.
    – Howdy_McGee
    Apr 18, 2016 at 16:04

3 Answers 3

2
  1. You can use Options API or Setting API to store the data in the database. Write a plugin to create a meta box for the introduction text and show that text on the archive-unicorn.php.

  2. Or you can utilize the description parameter when you register_post_type and print it in the archive-unicorn.php like this:

    $unicorn_obj = get_post_type_object('unicorn');
    
    if ( !empty($unicorn_obj) ) {
        echo $unicorn_obj->description;
    }
    
  3. Or you can add_meta_box, e.g. _is_sticky_unicorn, to the unicorn custom post type then use a query to show the post marked sticky on the very top of the archive-unicorn.php:

    if( get_post_meta( $post->ID, '_is_sticky_unicorn', true ) ) {
        // show your sticky post here
    } else {
        // show the rest here
    }
    
1
  • He asked for the best way, not for how many ways.
    – wpclevel
    Apr 18, 2016 at 13:13
2

You can try to build some options custom page to allow users to change some text. there are many plugins for easily creating that functionality. I will suggest you the most popular - ACF - Options Page

You can use the following code with ACF PRO:

/**
 * Create ACF setting page under Campaign CPT menu
 *
 * @since 1.0.0
 */
if (function_exists('acf_add_options_sub_page')) {
    acf_add_options_sub_page(
        array(
            'title' => 'All Campaign Options',
            'parent' => 'edit.php?post_type=campaign',
            'capability' => 'manage_options'
        )
    );
}
0

comment is related to post, page, or custom post type content, not an archive page, so I think you rather need add a front form than comment form on archive pages. You can use the "visual form builder" or some other front form plugins to get the done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.