› A Sample Custom Archive Template for Staffer

A Sample Custom Archive Template for Staffer

Email this to someoneShare on Facebook0Share on Google+0Share on LinkedIn0Share on Tumblr0Share on StumbleUpon0Tweet about this on TwitterShare on Reddit0Pin on Pinterest0

Staffer was made to be compatible with most WordPress themes, and its custom content-wrapper feature makes it easy to integrate it with your theme’s layouts when it’s not.

Staffer also includes a template-override feature, which works similar to WooCommerce’s template override. In a nutshell, you can drop a custom template (named either archive-staff.php or single-staff.php) into your theme’s directory.

If this file is present, Staffer will use it instead of the plugin’s own templates. This means you can further customize Staffer without worrying about losing your changes during updates.

See the following (or download here) to get started with a custom archive template for Staffer, and feel free to customize the markup (leave the other code alone) to suit your needs.

<?php
/**
 * Staffer Custom Archive Template
 * http://www.edwardrjenkins.com/plugins/staffer/
 * 
 * Drop this in your theme's directory to override
 * Staffer's default archive pages.  Leave non-markup
 * elements intact to preserve option-panel settings.
 *
 */
?>

<?php get_header(); ?>

<?php 
	// loads the options
	// must be carried over if using a custom template, else options will not work
	$stafferoptions = get_option ( 'staffer' );
		if (isset ($stafferoptions['customwrapper']) && isset ($stafferoptions['startwrapper'])) {
			$customstartwrapper = $stafferoptions['startwrapper'];
			echo $stafferoptions['startwrapper'];
			}
		else {
			echo '<div id="staffer-container"><div id="staff-content" role="main">';
			}
			
			// checks for the custom title
			$stafferarchivetitle = $stafferoptions['ptitle'];
			if ( isset ( $stafferarchivetitle ) && ($stafferarchivetitle != '' ) ) {
			?>
			<h2 class="staffer-archive-page-title"><?php echo $stafferarchivetitle; ?></h2>
			<?php }
				else {
				?>
			<h2 class="staffer-archive-page-title"><?php post_type_archive_title(); ?></h2>
			<?php } ?>

			<?php
				// adds description if present
				$stafferdescription = $stafferoptions['sdesc'];
				if ($stafferdescription != '') { ?>
				<div class="staffer-page-description">
					<?php echo wpautop( $stafferdescription ); ?>
				</div>
			<?php } ?>

			
		<?php
			// chooses between the grid and list layout
			if (isset ($stafferoptions['gridlayout']) ) {

			$stafferoptions = get_option('staffer');
					
			if (have_posts() ) : ?>

			<!-- Starts Grid Markup -->
			
			<ul class="staffer-archive-grid">
			
			<?php while ( have_posts() ) : ?>
			
			<?php the_post(); ?>

			<li>
				<header class="staffer-staff-header">
				<h3 class="staffer-staff-title"><a href="<?php the_permalink(); ?>">
					<?php echo the_title(); ?>
					</a>
				</h3>
				<?php
				if ( get_post_meta ($post->ID,'staffer_staff_title', true) != '' ) {
					echo '<em>' . get_post_meta ($post->ID,'staffer_staff_title', true) . '</em><br>';
					}
					?>
				
				</header>
					<div class="staff-content">
					<?php
						if ( has_post_thumbnail() ) { ?>
							<a href="<?php the_permalink(); ?>">
								<?php the_post_thumbnail ( 'medium', array ('class' => 'alignleft') ); ?>
							</a>
							<?php
						}
						if ($stafferoptions['estyle'] == null or $stafferoptions['estyle'] == 'excerpt' ) {
							the_excerpt();
						} elseif ($stafferoptions['estyle'] == 'full' ) {
							the_content();
						} elseif ($stafferoptions['estyle'] == 'none' ) {
							// nothing to see here
						} 
						?>
					</div>
				</li>
			<?php endwhile;
			endif; ?>
			</ul>

			<!-- Ends Grid Markup -->

			<?php
		 
		}
			if ( ! isset ($stafferoptions['gridlayout'] ) ) {

		// staffer list template

		$stafferoptions = get_option('staffer');
					
			if (have_posts() ) : ?>

			<!-- Starts List Markup -->
			
			<ul class="staffer-archive-list">
			
			<?php while ( have_posts() ) : ?>
			
			<?php the_post(); ?>

			<li>
				<header class="staffer-staff-header">
				<h3 class="staffer-staff-title"><a href="<?php the_permalink(); ?>">
					<?php echo the_title(); ?>
					</a>
				</h3>
				<?php
				if ( get_post_meta ($post->ID,'staffer_staff_title', true) != '' ) {
					echo '<em>' . get_post_meta ($post->ID,'staffer_staff_title', true) . '</em><br>';
					}
					?>
				
				</header>
					<div class="staff-content">
					<?php
						if ( has_post_thumbnail() ) { ?>
							<a href="<?php the_permalink(); ?>">
								<?php the_post_thumbnail ( 'medium', array ('class' => 'alignleft') ); ?>
							</a>
							<?php
						}
						if ($stafferoptions['estyle'] == null or $stafferoptions['estyle'] == 'excerpt' ) {
							the_excerpt();
						} elseif ($stafferoptions['estyle'] == 'full' ) {
							the_content();
						} elseif ($stafferoptions['estyle'] == 'none' ) {
							// nothing to see here
						} 
						?>
					</div>
				</li>
			<?php endwhile;
			endif; ?>
			</ul>

			<!-- Ends List Markup -->

			<?php
		 
		}
				?>

		<?php
			if ( $wp_query->max_num_pages > 1 ) { ?>
				<div class="staffer-navigation">
					<?php posts_nav_link(); ?>
				</div>
			<?php } ?>
			
	<?php
		// prints the end wrapper
		// must be carried over if using a custom template, else options will not work
		if (isset ($stafferoptions['customwrapper']) && isset ($stafferoptions['endwrapper'])) {
		$customstartwrapper = $stafferoptions['endwrapper'];
		echo $stafferoptions['endwrapper'];
		}
		else {
			echo '</div></div>';
			}
			?>
<?php get_footer(); ?>

Subscribe for weekly tutorials


  • Wes Linda

    Will this also edit the output of shortcodes? Or simply the post type? Using SCs exclusively and would like to edit the template if that’s an option.

  • curiouslt

    This doesn’t seem to work for the taxonomy-staffer-department.php template. I was able to add the archive-staff.php and single-staff.php to my child theme, but when i add taxonomy-staffer-department.php, it doesn’t see it and defaults to my index.php. If I remove it, it uses the taxonomy-staffer-department.php from the plugin folder.

  • sgodwin

    I really like this plugin a lot, mainly because so much flexibility is given to developers. However, here’s one thing that I didn’t understand, and I offer it here to help others who may be in the same situation…

    The archive-staffer.php template is called *only* for the main staffer archive (list) page. It is *not* called if you’re using the shortcode [staffer].

    The list generated for the shortcode is built in the load-staffer.php file in the plugin folder. Unfortunately, if you try to modify that file, your changes will get overwritten when the plugin is updated.

    IMO, it would be nice if there was a template part that you could modify and add to your theme folder so that the list generated for the shortcode is the same as the list generated by the main archive page.

    • edwardrj

      Hi, I agree. There are a lot of aspects of the plugin that could be more developer friendly and logical, including the use of more actions and filters.

      I’m in the process of re-building the plugin using the plugin boilerplate as a canvas. It’s been a long time coming due to my other commitments, but it’s about 95% complete. I’d expect to push it to the repo by the end of the month.