Customize the HTML template/structure of each post in the grid layout

Each layout of Content Views Pro has its own way to display post fields (thumbnail, title, content…). Normally, you can change the display order of fields by drag & drop checkboxes under Display Settings >> Fields settings easily.

But if you want to create your own HTML output of post in View, you can add this code to file functions.php of your active theme:

// Content Views Pro - Very custom HTML output for each post
add_filter( 'pt_cv_view_type_custom_output', 'cvp_theme_view_type_custom_output', 100, 3 );
/**
 * Customize HTML output of each post
 *
 * @param string $args       Current HTML output for a post
 * @param array $fields_html Array of fields (title, thumbnail, content...) and their HTML output
 * @param object $post       The current post object
 * @return string
 */
function cvp_theme_view_type_custom_output( $args, $fields_html, $post ) {
	// Do this for only specific Views
	global $pt_cv_id;
	if ( in_array( $pt_cv_id, array( 'VIEW_1', 'VIEW_2', 'VIEW_3' ) ) ) {
		ob_start();
		?>
		<!-- Your custom HTML here. You can access:
		$fields_html[ 'thumbnail' ]
		$fields_html[ 'title' ]
		$fields_html[ 'content' ]
		$fields_html[ 'meta-fields' ]
		$fields_html[ 'custom-fields' ]
		$fields_html[ 'others-wrap' ] (when enable "Do not wrap text around image")
		-->
		<?php
		$args = ob_get_clean();
	} // Ensure to put } BELOW the line of ob_get_clean()

	return $args;
}

Please replace VIEW_1, VIEW_2, VIEW_3 with IDs of your Views. And you can add/remove Views as you want.

Notice: This task requires your coding skills about PHP, HTML.

Best regards,

Scroll to Top