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 lookalike 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 ) )
            return;
    
        $post_title = get_the_title( $post_id );
        update_post_meta( $post_id, 'cvp_glossary_filter', substr( $post_title, 0, 1 ) );
    }
    // End code
    
  • 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, please select cvp_glossary_filter for the “Field Key”, then select the checkbox: Show as filters to visitors

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

Best regards,

Change border (width, style, color) of Read More button

To change border (width, style, color) of Read More button of Content Views, please use this CSS:

.pt-cv-view .pt-cv-readmore {
    border-width: 3px !important;
    border-style: solid !important;
    border-color: red !important;
}

.pt-cv-view .pt-cv-readmore:hover {
    border-width: 3px !important;
    border-style: solid !important;
    border-color: red !important;
}

You can change values of width, style, color as you want.

Best regards,

How to switch from Live Filter to Shuffle Filter?

Live Filter is the next generation of filters which is available to your site’s visitors. Live Filter has some advantages over Shuffle filter, but if you like the animation of Shuffle filter, you can easily switch from Live Filter to Shuffle Filter with 2 steps:

1. Disable live filter by deselecting the “Show as filters to visitors” checkbox under Filter Settings >> Advance >> Filter by Taxonomy
Content Views Pro - enable live filter taxonomy

2. Enable Shuffle filter by selecting the top checkbox in “Shuffle Filter” tab

Best regards,

Prevent images in View from being pinned to Pinterest.com

Content Views helps you to show thumbnail image of posts easily.
If you are installing another plugin which adds the “pin” button of Pinterest to images, but want to disable that button for images in View, 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 - Prevent images from being pinned to Pinterest
add_filter( 'pt_cv_field_thumbnail_image_html', 'cvp_theme_field_thumbnail_image_html', 100, 1 );
function cvp_theme_field_thumbnail_image_html( $args ) {
	global $pt_cv_id;
	if ( $pt_cv_id === 'VIEW_ID' ) {
		$args = str_replace('<img', '<img nopin = "nopin" data-pin-nopin="true"', $args);
	}

	return $args;
}

(replace VIEW_ID with ID of your View)

Best regards,

Live Filter – disable loading results on changing filter option, only loading on click “Submit” button

Live Filter helps you to show taxonomies, custom fields… as filter options, which allows your visitors to filter content in their way.
By default, the results are loaded on changing a filter option (select an option from dropdown, select a checkbox, select an option…)
To disable that behavior, and only loading results on click the “Submit” button, please add this code to Custom JS field (the right textarea) in Content Views >> Settings page:

var cvp_lf_loadonsubmit=function(){$("input, select",".cvp-live-filter").each(function(){$(this).data("nosubmit",!0)})};cvp_lf_loadonsubmit(),$("body").on("pt-cv-pagination-finished",function(){cvp_lf_loadonsubmit()});

Best regards,

Show posts list of custom code, or another plugin in Content Views Pro layout

In case you used custom code to query posts, or used another plugin to get posts, you can use Content Views Pro to display these posts in a beautiful grid or list.
Here is the code you need to use:

$pids = array();

// #1: If there is existing variable contains array of post objects
// Replace $posts by the existing variable
if ( isset( $posts ) ) {
	foreach ( $posts as $post ) {
		$pids[] = $post->ID;
	}
} 
else {
	// #2: If there is existing loop
	// Replace null by the query variable
	$query_obj = null;
	while ( $query_obj ? $query_obj->have_posts() : have_posts() ) :
		$query_obj ? $query_obj->the_post() : the_post();
		$pids[] = get_the_ID();
	endwhile;
}

// Replace VIEW_ID with the ID string of your grid/list View
echo do_shortcode('[pt_view id="VIEW_ID" post_type="any" post_id="' . implode( ',', $pids ) . '"]');

Notice: Above code requires your knowledge of PHP.

Best regards,

List posts by year (display yearly archives)

If you want to show list of years, and list of posts in each year, this document will help.
We will leverage the live filter for the custom field to display yearly archives, with only 2 steps:

  • Step 1: add a custom field to every existing and upcoming posts, to store the published year.
    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 to store the published year
    add_action( 'admin_head', 'cvp_theme_add_ctf_to_exising_posts' );
    function cvp_theme_add_ctf_to_exising_posts() {
    	if ( !get_option( 'cvp_theme_add_ctf_to_posts' ) ) {
    		global $wpdb;
    		$wpdb->query( "INSERT INTO {$wpdb->postmeta} (post_id,meta_key,meta_value)
      SELECT ID, 'cvp_published_year', STR_TO_DATE(post_date_gmt,'%Y')
      FROM {$wpdb->posts} WHERE {$wpdb->posts}.post_type = 'post' AND {$wpdb->posts}.post_status = 'publish'" );
    		add_option( 'cvp_theme_add_ctf_to_posts', 1, '', false );
    	}
    }
    add_action( 'save_post', 'cvp_theme_add_ctf_to_new_posts' );
    function cvp_theme_add_ctf_to_new_posts( $post_id ) {
    	if ( wp_is_post_revision( $post_id ) )
    		return;
    	update_post_meta( $post_id, 'cvp_published_year', get_the_date( 'Y', $post_id ) );
    }
    // End code
    
  • Step 2: Create a new View to show the years list, and allow visitors to filter posts by year.
    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, please select options as same as here:

    Content Views Pro - live filter by year

Then you can save the View, and add View shortcode to where you want to display the yearly archives.

Best regards,