Skip to content
Norris edited this page Dec 7, 2017 · 8 revisions

Register a New layout

New layouts must extend either

Photography_Portfolio\Frontend\Layout\Single\Single_Portfolio_Layout

or

Photography_Portfolio\Frontend\Layout\Archive\Archive_Portfolio_Layout

For example:

namespace Wonder_Theme_5000;

use Photography_Portfolio\Frontend\Layout\Single\Single_Portfolio_Layout;

class Horizontal_Layout_Single extends Single_Portfolio_Layout {

	public $attached_sizes = array(
		'thumb' => 'w5000_portfolio_horizontal',
		'full'  => 'full',
	);

}

Once you've created your class, you can register it as a layout, like so:

add_action(
	'phort/core/register_layouts',

	/**
	 * @var \Photography_Portfolio\Frontend\Layout_Registry $registry
	 */
	function ( $registry ) {

		/**
		 * Single Horizontal Portfolio
		 */
		$registry->add(
		// Fully Qualified class name.
		// You must make sure that your class is included when neccessary, either by autoloading or manually including it
			'Wonder_Theme_5000\Horizontal_Layout_Single',

			// The layout group. `single` or `archive`
			'single',

			// Your unique layout slug.
			'w5000_horizontal',

			// The title that's going to appear in Portfolio Settings
			esc_html__( 'Wonder Theme 5000: Horizontal', 'w5000-text-domain' )

		);
	});

Change the defaults

When extending the plugin (either in an extension or a theme) you might want to have a different default. For example, if you create a custom horizontal layout for a theme, you might want to set that horizontal layout as the default, instead of making the user select that layout manually.

add_action( 'phort/core/loaded', 'prefix_modify_portfolio_defaults' );
function prefix_modify_portfolio_defaults() {

	phort_set_defaults(
		[
			'single_portfolio_layout' => 'packed',
			'archive_description'     => 'enable',
		]
	);

}

Alter featured image size

The portfolio uses "large" image sizes by default. If you're making a theme compatible with the plugin, you might want to alter/optimize the image size. To do that you can use filters phort/archive/$slug/attached_sizes and phort/single/$slug/attached_sizes, for example:

add_filter( 'phort/archive/masonry/attached_sizes', 'theme_prefix_adjust_phort_masonry_sizes' );
add_filter( 'phort/single/masonry/attached_sizes', 'theme_prefix_adjust_phort_masonry_sizes' );

// Alter image size for "Easy Photography Portfolio" masonry layouts
function theme_prefix_adjust_phort_masonry_sizes( $attached_sizes ) {

	if ( $attached_sizes['thumb'] == 'large' ) {
		$attached_sizes['thumb'] = 'thumbnail_masonry';
	}

	return $attached_sizes;
}

Change settings on the fly

Easy Photography Portfolio allows you to change settings programmatically. This is useful to, for example, change portfolio layout based on the portfolio category you're in.

add_filter( 'phort_option_portfolio_layout', function ( $default ) {

	// this is where you do stuff
	$conditions = [
		'A masonry category'         => 'masonry',
		'Another category name'      => 'horizontal',
	];


	// don't touch this
	foreach ( $conditions as $condition => $layout ) {
		if ( is_tax( 'phort_post_category', $condition ) ) {
			return $layout;
		}
	}

	return $default;
} );
Clone this wiki locally