Giter Club home page Giter Club logo

cmb2-starter-testimonials-plugin's Introduction

Template Testimonials Plugin

A basic template for a simple and customizable testimonials plugin for wordpress utilizing a custom post type, optional custom taxonomy, and custom meta fields using the CMB2 toolkit.

This should be an easy template to reuses and customize in future projects.

This is my first public repo so i am still figuring out how best to use the readme.md file.

Contents

The template testimonials plugins contains the following files:

  • README.md. The file your currently reading.
  • readme.txt. The required wordpress plugin readme with additional details and change log.
  • LICENSE. The GPLv2 license text.
  • index.php. Never hurts to include a blank index file.
  • sample template files. See the sample files section bellow for further details.
  • cpt-testimonials.php. The primary plugin file in which all other part files are included.
  • includes. Folder containing all the necessary part files.
    • testimonials-cpt.php. Contains the function to register the custom post type.
    • testimonials-taxonomy.php. Contains the function to register a custom taxonomy.
    • testimonials-metaboxes.php. Contains the functions to register the custom meta boxes.
    • testimonials-notices.php. Contains any plugin notices. In particular a check to see if CMB2 is already installed upon the plugins activation.
    • testimonials-edit-columns.php. Contain the functions needed to output the custom meta data in the admin edit screen columns.

Features

It comes with a few basic metadata fields:

  • Quote:
  • Client Name:
  • Website URL:
  • Location:
  • Client Image:

Since the custom meta fields are built with the CMB2 toolkit, customizing the available fields is relatively simple. See the list of available field types for possibilities of expanding the testimonial fields.

  • Custom Taxonomy: Testimonial Categories

The custom taxonomy is commented out in the cpt-testimonials.php file by default.

Structure

For the sake of reference and later styling, the structure for the testimonials as output via the content-testimonial.php file is outlined bellow. Some of the structure is conditional depending on what metadata fields are provided. See the sample sass file or check out the example code pen.

<div class="testimonial">
   <div class="testimonial-image">
      <img src="" alt="" />
   </div>
   <blockquote>
      <p>
         <!-- testimonial text -->
      </p>
      <cite>
         <!-- ::before - for styling -->
         <span class="testimonial-name">
         <!-- name without link text -->
         	<a href="#">
         	<!-- name with link text -->
         	</a>
         </span>
         <span class="testimonial-location" >
         <!-- location text -->
         </span>
      </cite>
   </blockquote>
</div>

Sample Files

The template plugin contains a folder called sample template files. This folder contains samples of the necessary theme template files to output the custom metaboxes for the testimonial post type.

Contents

  • archive-pbcpt_testimonials.php
  • single-pbcpt_testimonials.php
  • content-testimonial.php
  • _testimonials.sass
  • markup.php

Notice

I build the post type sample template files on the Genesis Framework . The plugin itself will run independent of the theme being used, but the archive- and single- sample template files contain functions and hooks specific to the Genesis Framework. Each is using the get_template_part( 'content', 'testimonial' ); function to include the content-testimonial.php file.

The content-testimonial.php contains all the functions to output the testimonials custom metadata and all its basic markup structure, and can be used within any theme. You will simply need to modify your loop to include it.

Example

Using the Twenty Fifteen single.php file for example, you could easily modify the loop of the single post template to include the content-testimonial.php file. You would also, in this example, need to add aditional structure to the content-testimonial.php as needed for your theme.

<?php get_header(); ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">

		<?php
		// Start the loop.
		while ( have_posts() ) : the_post();

			/*
			 * Include the testimonial post format-specific template for the content.
			 */
			get_template_part( 'content', 'testimonial' );

		// End the loop.
		endwhile;
		?>

		</main><!-- .site-main -->
	</div><!-- .content-area -->

<?php get_footer(); ?>

Installation

  1. Manually upload the cpt-testimonials plugin to your /wp-content/plugins/ directory.
    • Alternatively upload the cpt-testimonials.zip file through the Plugins menu in your wordpress admin by clicking Add New > Upload Plugin.
  2. Activate the plugin through the Plugins menu in WordPress.
  3. Download CMB2 from the wordpress plugin directory, https://wordpress.org/plugins/cmb2/
  4. Manually upload the cmb2 plugin to your /wp-content/plugins/ directory.
  5. Activate the CMB2 plugin through the Plugins menu in WordPress.

Required Plugins

CMB2 can be built within the plugin itself, but for the sake of keeping the template plugin easy to update and expand upon, i have chosen not to included it. Otherwsie you will need to modify the plugin and include CMB2 on your own.

To use the plugin as is, you will need to install the following plugin:

To Do

  1. The single and archive post type will share vary similar structure so i should break out the main content structure into a separate part file to include into the respective templates.
    • Structure of the single testimonial post type has been moved to its own part file content-testimonial.php, to make it easier to reuse the structure in both single and archive template files.
  2. Build the archive post template for testimonials.
    • Done, though in reality i think can just create a function to reuse one of the template files and tell wordpress to use if for both. Haven't tried this on singe & archive post type so will have to give it a shot.
  3. Playing with Review schema. Added a sample file for the necessary genesis filter to add the review microdata to the body of the cpt archive page. I tried adding additional microdata to the content-testimonial.php file but google wouldn't validate as google only recognizes it in terms of an item. Not even sure if you can use the review microdata on testimonials.

Change Log

Please see the the readme.txt file included in the root of the plugin’s directory for a complete change log.

License

License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

A copy of the license is included in the root of the plugin’s directory. The file is named LICENSE.

Credits & References

  • WebDevStudios - Maintaners of CMB2
  • Bill Erickson - For help in understanding Genesis, cpt's as core plugins, and avoiding front end dependency when using custom metadata fields.
  • Justin Tadlock - For his tutorial and code snipets relating to adding custom meta to the admin edit columsn.
  • Gary Jones - For his tutorial and code for the widget notice.

Codex

Custom Post Type Information

CMB2 Information

Custom Taxonomy

Others

cmb2-starter-testimonials-plugin's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.