Step-by-Step Guide to Add Private Documents Listing in Child Theme

1. Create and Activate a Child Theme


Follow these steps:

  • In your WordPress installation, navigate to wp-content/themes.
  • Create a new folder named hueman-child.

  • Inside hueman-child, create a file named style.css.
  • Add the following content to style.css:
/*
Theme Name: Hueman Child
Template: hueman
*/

  • Inside hueman-child, create a file named functions.php.
  • Add the following content to functions.php:
<?php
// Enqueue parent theme styles
function hueman_child_enqueue_styles() {
    wp_enqueue_style('hueman-parent-style', get_template_directory_uri() . '/style.css');
}
add_action('wp_enqueue_scripts', 'hueman_child_enqueue_styles');
  • Go to Appearance > Themes in your WordPress dashboard.
  • Activate the Hueman Child theme.

2. Add Shortcode for Private Documents Listing


  • Edit the functions.php file in your hueman-child theme.
  • Add the following code to create a shortcode for listing private documents by category:
<?php
// Enqueue parent theme styles
function hueman_child_enqueue_styles() {
    wp_enqueue_style('hueman-parent-style', get_template_directory_uri() . '/style.css');
}
add_action('wp_enqueue_scripts', 'hueman_child_enqueue_styles');

// Shortcode to list private documents by category
function list_private_documents_by_category() {
    // Query private documents
    $args = array(
        'post_type' => 'post', // Change to 'documents' if using a custom post type
        'posts_per_page' => -1,
        'post_status' => 'private',
        'orderby' => 'category',
        'order' => 'ASC'
    );

    $query = new WP_Query($args);

    if ($query->have_posts()) {
        $output = '<ul>';
        while ($query->have_posts()) {
            $query->the_post();
            $categories = get_the_category();
            if (!empty($categories)) {
                foreach ($categories as $category) {
                    $output .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a> (' . esc_html($category->name) . ')</li>';
                }
            }
        }
        $output .= '</ul>';
        wp_reset_postdata();
    } else {
        $output = 'No private documents found.';
    }
    return $output;
}
add_shortcode('private_documents', 'list_private_documents_by_category');

3. Create a Private Page


  • Go to Pages > Add New.
  • Enter a title for your page, e.g., “Private Documents”.

  • In the “Publish” box on the right, click “Edit” next to “Visibility”.
  • Select “Private”.
  • Click “OK” and then “Publish”.
  • Edit the “Private Documents” page or Widgets.
  • Add the [private_documents] shortcode to the page content.
  • Update the page.

4. Set Documents to Private


  • Go to Posts (or Documents) > All Posts.
  • Edit each document.
  • In the “Publish” box, click “Edit” next to “Visibility”.
  • Select “Private”.
  • Click “OK” and then “Update”.

References


8019_STRONA – ct.sophiadavenport.com – 002

You may also like...

Leave a Reply