2

So basically, I have a page that is a custom archive showing a list of posts on it. The only issue is, the client wants to be able to edit the actual archive page content itself (image and title), not just the content of the posts. All of this needs to be able to be done inside the dashboard so that its easy for the client. Is there any way i can make is so that the archive page's custom template will show up in the "pages" tab? Or is editable via the dasbhoard at all? Thanks!

1

Depending on the set-up there are multiple ways to handle this. I'm assuming the most likely scenario is that you're using a third-party theme, meaning you can't edit any of the theme files yourself (you definitely shouldn't do it as updates will erase your changes). This limits your options a bit and the easiest route would be, as other answers have suggested, to simply populate the Category content under the 'Posts' menu in the dashboard. There are plugins that will allow you to add more content, like a featured image: Category Featured Image

You could also build your own plugin allowing for greater control as to what you're adding to the categories. Here is a segment of code I've used to add a colour picker and a checkbox option to a custom taxonomy. You could of course apply it to an existing taxonomy.

function yourplugin_taxonomy_custom_fields( $tag ) {
    $t_id = $tag->term_id;
    $term_meta = get_option( 'taxonomy_term_'.$t_id );
    $level_public = $term_meta['level_public'];
    if ( $level_public == 'true' ) {
        $checked = ' checked="checked"';
    } else {
        $checked = '';
    }
?>
<tr class="form-field">
    <th scope="row" valign="top">
        <label for="level_colour"><?php _e('Player Level Colour'); ?></label>
    </th>
    <td>
        <input type="text" name="term_meta[level_colour]" id="term_meta[level_colour]" class="ifs-pp-colour-picker" value="<?php echo $term_meta['level_colour'] ? $term_meta['level_colour'] : ''; ?>">
        <p class="description"><?php _e('Select the label colour for this Player Level.'); ?></p>
        <script type="text/javascript">
            jQuery( document ).ready( function( $ ) {
                $( '.ifs-pp-colour-picker' ).wpColorPicker();
            } );
        </script>
    </td>
</tr>
<tr class="form-field">
    <th scope="row" valign="top">
        <label for="level_public"><?php _e('Player Level Visibility'); ?></label>
    </th>
    <td>
        <input type="checkbox" name="term_meta[level_public]" id="term_meta[level_public]" value="true"<?php echo $checked; ?>>Level is Visible to users when viewing frontend Player Profiles.
        <p class="description"><?php _e('Please indicate if this Player Level should be visible on the player profile page or not. This is useful for providing context for some of the ratings or not.  It may be helpful, in some instances, for users to understand that the ratings a player has recieved are relative to their category or level of play.'); ?></p>
    </td>
</tr>
<?php }
add_action( 'yourplugin_player_levels_edit_form_fields', 'yourplugin_taxonomy_custom_fields', 10, 2 );

function save_yourplugin_custom_fields( $term_id ) {
    if ( isset( $_POST['term_meta'] ) ) {
        $t_id = $term_id;
        $term_meta = get_option( 'taxonomy_term_'.$t_id );
        $cat_keys = array_keys( $_POST['term_meta'] );
        foreach ( $cat_keys as $key ){
            if ( isset( $_POST['term_meta'][$key] ) ){
                $term_meta[$key] = $_POST['term_meta'][$key];
            }
        }
        update_option( 'taxonomy_term_'.$t_id, $term_meta );
    } else {
        delete_option( 'taxonomy_term_'.$t_id, $term_meta );
    }
}
add_action( 'edited_yourplugin_player_levels', 'save_yourplugin_custom_fields', 10, 2 );

If you want to add the colour picker you'll have to do the proper script inclusion, etc. (This should cover the process.)

Please note that with this option, you still need to be able to edit the archive-cpt.php file so that you can utilize these new options you've just added. Depending on the theme you're using, you may be able to edit it yourself or perhaps your third-party theme has some hooks your plugin can utilize.

However, if you're using a custom child theme or a custom theme, you actually have a great deal more flexibility and can set up archive templates - you can then control what content is fed into it. You can manipulate content by adding theme options which are covered in @admcfajn's answer, or you use the category options I've covered above.

| improve this answer | |
  • It was because I was using a third-party theme. Wasted a lot of time figuring that out thanks. – Nelles Dec 10 '19 at 18:25
0

Sure it can be done. For taxonomies (category, tag, any custom tax - i assume this is what you're after) it's easy, they each have their own page in the dashboard - see under posts -> category/tag -> edit category. There's a custom field called description but you can add more (photo, whatever) via functions.php or some plugin. Of course, you'd have to edit the templates yourself first, so they fetch the contents of the wanted fields.

| improve this answer | |
0

In your archive-cpt.php file make sure to give it a Template Name

 //Template Name: Archive Template Your CTP 

Then when creating a new Page your archive template will be available in the Page Attributes > Template dropdown

| improve this answer | |
0

Making it a taxonomy and allowing the client to edit the term title & description would be an option I'd consider.

The theme may or may not be using a custom template-file to control the cpt-archive's front-end.

Using a page-template would be ill-advised because by loading the post-type and the page at the same url, problems can arise.

Using theme-options would be a good way. Having a theme option in combination with a custom archive-template for the post-type archive could do it.

For how to create theme-options, See this example: https://codex.wordpress.org/Creating_Options_Pages#Example_.232

& for custom-page templates, this has you covered: https://developer.wordpress.org/themes/basics/template-hierarchy/#visual-overview

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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