Snippets

Joseph Dickson Testimonials Custom Post Type and Twenty Twenty Child Theme

Created by Joseph Dickson
<?php
/**
 * The default template for displaying content
 *
 * Used for both singular and index.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package WordPress
 * @subpackage Twenty_Twenty
 * @since Twenty Twenty 1.0
 */

?>

<article <?php post_class(); ?> id="post-<?php the_ID(); ?>">

<?php
	if ( is_home() ) {
		if ( function_exists( 'jd_testimonial_custom_post_type' ) ) {
			// JD Testimonial Custom Post Types
			get_template_part( 'template-parts/query-welcome' );
			get_template_part( 'template-parts/query-testimonial' );
		}

	}
?>

	<?php

	get_template_part( 'template-parts/entry-header' );

	if ( ! is_search() ) {
		get_template_part( 'template-parts/featured-image' );
	}

	?>

	<div class="post-inner <?php echo is_page_template( 'templates/template-full-width.php' ) ? '' : 'thin'; ?> ">

		<div class="entry-content">

			<?php
			if ( is_search() || ! is_singular() && 'summary' === get_theme_mod( 'blog_content', 'full' ) ) {
				the_excerpt();

			} else {

				the_content( __( 'Continue reading', 'twentytwenty' ) );
			}
			?>

		</div><!-- .entry-content -->

	</div><!-- .post-inner -->

	<div class="section-inner">
		<?php
		wp_link_pages(
			array(
				'before'      => '<nav class="post-nav-links bg-light-background" aria-label="' . esc_attr__( 'Page', 'twentytwenty' ) . '"><span class="label">' . __( 'Pages:', 'twentytwenty' ) . '</span>',
				'after'       => '</nav>',
				'link_before' => '<span class="page-number">',
				'link_after'  => '</span>',
			)
		);

		edit_post_link();

		// Single bottom post meta.
		twentytwenty_the_post_meta( get_the_ID(), 'single-bottom' );

		if ( is_single() ) {

			get_template_part( 'template-parts/entry-author-bio' );

		}
		?>

	</div><!-- .section-inner -->

	<?php

	if ( is_single() ) {

		get_template_part( 'template-parts/navigation' );


	}

	/**
	 *  Output comments wrapper if it's a post, or if comments are open,
	 * or if there's a comment number – and check for password.
	 * */
	if ( ( is_single() || is_page() ) && ( comments_open() || get_comments_number() ) && ! post_password_required() ) {
		?>

		<div class="comments-wrapper section-inner">

			<?php comments_template(); ?>

		</div><!-- .comments-wrapper -->

		<?php
	}
	?>

</article><!-- .post -->
1
2
3
4
5
6
<?php
add_action( 'wp_enqueue_scripts', 'jd_theme_enqueue_styles' );
function jd_theme_enqueue_styles() {
	wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
 
}
<?php
/**
 * Plugin Name: JD Testimonial 
 * Description: Custom Post Type for customer testimonials and Homepage welcome
 * Version: 1.0
 * License: GPL2
 */

// Prevent direct access to this file
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

/**
 * https://codex.wordpress.org/Function_Reference/register_post_type#Arguments
 */
function jd_testimonial_custom_post_type() {

$labels = array(
	'name'			=> 'Testimonial',
	'singular_name'		=> 'Testimonial',
	'menu_name'		=> 'Testimonial',
	'name_admin_bar'	=> 'Testimonial',
	'add_new'		=> 'Add a Testimonials',
	'add_new_item'		=> 'Testimonial',
	'new_item'		=> 'Testimonial',
	'edit_item'		=> 'Edit Testimonial',
	'view_item'		=> 'View Testimonial',
	'all_items'		=> 'All Testimonials',
	'search_items'		=> 'Search Testimonials',
	'parent_item_colon'	=> 'Parent Testimonials:',
	'not_found'		=> 'No Testimonials found.',
	'not_found_in_trash'	=> 'No Testimonials found in Trash.',
);

$args = array(
	'labels'		=> $labels,
	'public'		=> false,
	'publicly_queryable'	=> false,
	'show_ui'		=> true,
	'show_in_menu'		=> true,
	'menu_icon'		=> 'dashicons-format-chat',
	'query_var'		=> true,
	'rewrite'		=> array( 'slug' => 'testimonial' ),
	'capability_type'	=> 'post',
	'has_archive'		=> false,
	'hierarchical'		=> false,
	'menu_position'		=> 16,
	'show_in_rest'		=> true,
	'supports'		=> array( 'title', 'editor', 'thumbnail' ),
);

register_post_type( 'testimonial', $args );

$labels = array(
	'name'			=> 'Welcome',
	'singular_name'		=> 'Welcome',
	'menu_name'		=> 'Welcome',
	'name_admin_bar'	=> 'Welcome',
	'add_new'		=> 'Add a Homepage Welcome',
	'add_new_item'		=> 'Welcome',
	'new_item'		=> 'Welcome',
	'edit_item'		=> 'Edit Welcome',
	'view_item'		=> 'View Welcome Messages',
	'all_items'		=> 'All Welcome Messages',
	'search_items'		=> 'Search Welcome Messages',
	'parent_item_colon'	=> 'Parent Welcome Messages:',
	'not_found'		=> 'No Welcome Messages found.',
	'not_found_in_trash'	=> 'No Homepage Welcome Messages found in the Trash.',
);

$args = array(
	'labels'		=> $labels,
	'public'		=> false,
	'publicly_queryable'	=> false,
	'show_ui'		=> true,
	'show_in_menu'		=> true,
	'menu_icon'		=> 'dashicons-star-filled',
	'query_var'		=> true,
	'rewrite'		=> array( 'slug' => 'hp-welcome' ),
	'capability_type'	=> 'post',
	'has_archive'		=> false,
	'hierarchical'		=> false,
	'menu_position'		=> 15,
	'show_in_rest'		=> true,
	'supports'		=> array( 'title', 'editor' ),
);

register_post_type( 'hp-welcome', $args );
}

add_action( 'init', 'jd_testimonial_custom_post_type' );

// Flush rewrite rules when plugin is activated
function pz_tile_rewrite_flush() {
	pz_tile_custom_post_type();
	flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'jd_testimonial_rewrite_flush' );

if ( function_exists( 'add_theme_support' ) ) {
	add_theme_support( 'post-thumbnails' );

	// delete the next line if you do not need additional image sizes
	add_image_size( 'testimonial-thumb', 600, 600, array( 'center', 'center') );
}
<?php
// The Query
$the_query = new WP_Query(
	array(
		'post_type' =>		'testimonial',
		'post_status' =>	'publish',
		'posts_per_page' =>	3,
		'orderby' =>		'rand',
	)
);
// The Loop
if ( $the_query->have_posts() ) {
	echo '<h1 class="clients">Our Clients</h1>';
	echo '<div class="testimonial-group">';
	while ( $the_query->have_posts() ) {
		echo '<div class="testimonial">';
        $the_query->the_post();
	the_title('<strong class="testimonial-title">', '</strong>');
		if ( has_post_thumbnail() ) {
			the_post_thumbnail( 'testimonial-thumb' );
		}
	the_content();
		echo '</div>';
	}
	echo '</div>';
} else {
    // no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
<?php
// The Query
$the_query = new WP_Query(
	array(
		'post_type' =>		'hp-welcome',
		'post_status' =>	'published',
		'posts_per_page' =>	1,
	)
);
// The Loop
if ( $the_query->have_posts() ) {
	echo '<div class="welcome">';
    while ( $the_query->have_posts() ) {
	    $the_query->the_post();
	    the_content();
    }
	echo '</div>';
} else {
    // no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
/*
 Theme Name:   Twenty Twenty Testimonial Child
 Description:  Twenty Twenty Child Theme
 Author:       Joseph Dickson 
 Author URI:   https://joseph-dickson.com 
 Template:     twentytwenty
 Version:      1.0.0
 License:      GNU General Public License v2 or later
 License URI:  http://www.gnu.org/licenses/gpl-2.0.html
 Text Domain:  twentytwenty-wcscv-child
*/

body:not(.singular) main > article:first-of-type {
	padding: 0;
}

body:not(.singular) main > article:first-of-type {
	padding: 0;
}

.testimonial-group {
	background-color: #3d003d; 
	color: #fff;
	padding: 5rem 0;
	margin-bottom: 5rem;
}

h1.clients {
	background-color: #3d003d; 
	color: #fff;
	display: block;
	text-align: center;
	margin: 0;
	padding: 6rem 0 3rem 0;
}

.testimonial {
	max-width: 30rem;
	margin: auto;
	font-size: 2rem;
	font-weight: bold;
}

.testimonial img {
	border-radius: 30rem;
	margin-bottom: 3rem;
	text-align: center;
	border: 5px solid #fff;
}

.testimonial-title {
	display: block;
	font-size: 3rem;
	margin-bottom: 3rem;
	text-align: center;
}

.welcome .alignfull {
	margin: 0;
}

/* Post Masonry */
.post-masonry-row {
          margin: 0 auto;
          max-width: 1600px;
}
.masonry-css {
  -webkit-column-count: 1;
          column-count: 1;
  -webkit-column-gap: 1rem;
          column-gap: 1rem;
}

@media screen and (min-width: 37.5em) {
  .masonry-css {
    -webkit-column-count: 2;
            column-count: 2;
  }
}

@media screen and (min-width: 37.5em) {
	.testimonal-group {
	-webkit-column-count: 2;
}

@media screen and (min-width: 68.75em) {
	.testimonial-group {
	-webkit-column-count: 3;
	column-count: 3;
}

	.testimonial {
		-webkit-column-break-inside: avoid;
		break-inside: avoid;
		margin-bottom: 1rem;
	}
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.