Glossary layout supports pagination

The default Glossary layout doesn’t support pagination, that is ineffective when there are a lot of posts in your site.
To show a glossary look-alike list, click each index will show relative posts, and support pagination, please follow instructions below:

  • Step 1: add a custom field to every existing and upcoming posts, to store the glossary index.

    Please add this code to file functions.php in the theme’s folder (or install this plugin Code Snippets then add this code to the “Code” textarea):

    // Content Views Pro - add custom field glossary heading for each post
    add_action( 'admin_head', 'cvp_theme_add_ctf_glossary_to_exising_posts' );
    function cvp_theme_add_ctf_glossary_to_exising_posts() {
        if ( !get_option( 'cvp_theme_add_ctf_glossary_index' ) ) {
            global $wpdb;
            $wpdb->query( "INSERT INTO {$wpdb->postmeta} (post_id,meta_key,meta_value)
      SELECT ID, 'cvp_glossary_filter', LEFT(post_title,1)
      FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_type = 'post' AND {$wpdb->posts}.post_status = 'publish'" );
            add_option( 'cvp_theme_add_ctf_glossary_index', 1, '', 'no' );
    add_action( 'save_post', 'cvp_theme_add_ctf_glossary_to_new_posts' );
    function cvp_theme_add_ctf_glossary_to_new_posts( $post_id ) {
        if ( wp_is_post_revision( $post_id ) )
        $post_title = get_the_title( $post_id );
        update_post_meta( $post_id, 'cvp_glossary_filter', mb_substr( $post_title, 0, 1 ) );
    // End code


    Above code works for the Post type.
    To use for Page type, please replace 'post' in above code by 'page'.
    To use for Custom Post type, please replace 'post' in above code by Post Type Key, for example: 'product' or 'event' depends on your post type.

  • Step 2: Create a new View to show the glossary indexes, and allow visitors to filter posts by indexes.
    In Admin area, click Content Views > Add New menu item.

    In Filter Settings tab of the View:

    • select Custom Fields in Advance group, then click Add New button. A new field will be added.
    • select cvp_glossary_filter for the “Field Key”
    • select the checkbox: Show as filters to visitors
    • select the Button option for the Type dropdown

    In Display Settings tab of the View:

    • Select the Grid option for Layout. Please do not select the Glossary option, because it doesn’t support pagination.
    • Enable pagination

Then save the View, and add View shortcode to where you want to display it.

Best regards,

Scroll to Top