Skip to content

Commit dab534a

Browse files
committed
v0.1 - Updated CPT
1 parent 7150313 commit dab534a

4 files changed

Lines changed: 153 additions & 11 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
assets/.DS_Store
22
assets/inc/.DS_Store
3+
.DS_Store

assets/inc/cpts/custom-type.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -308,30 +308,29 @@ function myTheme_projectServices() {
308308
add_action( 'init', 'myTheme_customTags', 0 );
309309
add_action( 'init', 'myTheme_projectServices', 0 );
310310

311-
function get_custom_post_type_template($archive_template){
311+
function myPlugin_postArchive_portfolio($archive_template){
312312
global $post;
313-
$plugin_root_dir = WP_PLUGIN_DIR . '/product-plugin/';
314313

315-
if (is_archive() && get_post_type($post) == 'product'){
316-
$archive_template = $plugin_root_dir . '/inc/templates/archive-product.php';
314+
if (is_archive() && get_post_type($post) == 'portfolio'){
315+
$archive_template = ZEROPLUGIN_PATH . '/assets/inc/templates/archive-portfolio.php';
317316
}
318317
return $archive_template;
319318
}
320-
add_filter('archive_template', 'get_custom_post_type_template');
319+
add_filter('archive_template', 'myPlugin_postArchive_portfolio');
321320

322-
function load_movie_template( $template ) {
321+
function myPlugin_singlePost_portfolio( $template ) {
323322
global $post;
324323

325-
if ( 'movie' === $post->post_type && locate_template( array( 'single-movie.php' ) ) !== $template ) {
324+
if (get_post_type($post) == 'product' && locate_template( array( 'single-portfolio.php' ) ) !== $template ) {
326325
/*
327-
* This is a 'movie' post
328-
* AND a 'single movie template' is not found on
326+
* This is a 'portfolio' post
327+
* AND a 'single portfolio template' is not found on
329328
* theme or child theme directories, so load it
330329
* from our plugin directory.
331330
*/
332-
return plugin_dir_path( __FILE__ ) . 'single-movie.php';
331+
return ZEROPLUGIN_PATH . '/assets/inc/templates/single-portfolio.php';
333332
}
334333

335334
return $template;
336335
}
337-
add_filter( 'single_template', 'load_movie_template' );
336+
add_filter( 'single_template', 'myPlugin_singlePost_portfolio' );
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Portfolio Template (Custom Post Template)
4+
* @package WordPress
5+
* @subpackage Project_Zero
6+
* @since 0.1
7+
*
8+
* This is a custom template for the 'portfolio' post type.
9+
* You can find out more about the Template Hierarchy at
10+
* @link https://developer.wordpress.org/themes/basics/template-hierarchy/
11+
*
12+
* Typically, index.php contains your blog archive template (content that could also be displayed in a home.php file).
13+
* However, it is used for any content that does not have a specific template.
14+
*/
15+
16+
get_header();
17+
?>
18+
<section id="archive-title" class="archive-title page-title">
19+
<div class="container">
20+
<h1><?php echo _x( 'Portfolio', 'portfolio archive title', 'zero-theme' ); ?></h1>
21+
</div> <!-- .container -->
22+
</section> <!-- #archive-title -->
23+
24+
<section id="portfolio-archive" class="portfolio-archive archive-page page-container">
25+
<div class="container">
26+
<main id="archive-content" class="projects row">
27+
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
28+
<?php
29+
/**
30+
* Loads a reusable section of code from within your child theme.
31+
* If the template part is not within your child theme, it will look within the parent theme.
32+
*
33+
* @link https://developer.wordpress.org/reference/functions/get_template_part/
34+
*
35+
* @param string $slug The slug name for the generic template. Required.
36+
* @param string $name The name of the specialised template.
37+
* @param array $args Additional arguments to be passed through to the template.
38+
*
39+
* The function looks for the file {$slug}-{$name}.php.
40+
* In this instance, it looks for inc/parts/portfolio-archive.php
41+
*/
42+
get_template_part( 'inc/parts/portfolio', 'archive' );
43+
?>
44+
<?php endwhile; // Stops looping through the posts in WP_Query ?>
45+
<?php blog_archive_pagination(); ?>
46+
<?php else : // If there are no posts in the loop ?>
47+
404
48+
<?php endif; // Ends the loop ?>
49+
</main> <!-- #archive-content -->
50+
</div> <!-- .container -->
51+
</section> <!-- #blog-archive -->
52+
<?php get_footer(); ?>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Custom Post Type ('portfolio') - Single Template
4+
* @package WordPress
5+
* @subpackage Project_Zero
6+
* @since 0.1
7+
*
8+
* This template applies to all pages without a specialised page template or a custom page template.
9+
* To create a specialised page template, save this as page-{slug}.php or page-{id}.php, as required.
10+
*
11+
* For more information, check out
12+
* @link https://developer.wordpress.org/themes/template-files-section/page-template-files/
13+
*/
14+
15+
get_header();
16+
if ( have_posts() ) : while ( have_posts() ) : the_post();
17+
?>
18+
<section id="project-title" class="project-title page-title single-title">
19+
<div class="container">
20+
<h1 class="title"><?php the_title(); ?></h1>
21+
</div> <!-- .container -->
22+
</section> <!-- #project-title -->
23+
24+
<section id="project-<?php the_ID(); ?>" class="single-project page-container">
25+
26+
<div class="container row">
27+
28+
<main id="page-content" <?php post_class( array('col-8') ); // Lists all classes for the post, and adds the 'col-8' CSS class ?>>
29+
30+
<?php if ( has_post_thumbnail() ) {
31+
/**
32+
* @var $featured - Returns attachment source as an array, based on an ID number.
33+
* get_post_thumbnail_id( get_the_ID() ) gets the ID of the featured image linked to the post ID.
34+
* $featured[0] - Image URL
35+
* $featured[1] - Image width in pixels
36+
* $featured[2] - Image height in pixels
37+
*/
38+
$featured = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'full' );
39+
?>
40+
<figure class="featured-image">
41+
<img src="<?php echo $featured[0]; ?>" width="<?php echo $featured[1]; ?>" height="<?php echo $featured[2]; ?>" />
42+
</figure> <!-- .featured-content -->
43+
<?php } ?>
44+
45+
<article class="project-content">
46+
<div class="entry">
47+
<?php the_content(); ?>
48+
</div> <!-- .entry -->
49+
</article> <!-- .project-content -->
50+
51+
</main> <!-- #page-content -->
52+
53+
<aside id="project-sidebar" class="col-4">
54+
<?php if ( !empty( get_post_meta( get_the_ID(), 'client_name', true ) ) ){ ?>
55+
<!-- Client information -->
56+
<h6 class="project-meta meta-title client">Client:</h6>
57+
<p class="project-meta meta-data client"><?php echo get_post_meta( get_the_ID(), 'client_name', true ); ?></p>
58+
<?php } ?>
59+
60+
<?php if ( !empty( get_post_meta( get_the_ID(), 'client_url', true ) ) ){ ?>
61+
<!-- Website link -->
62+
<h6 class="project-meta meta-title website">Website:</h6>
63+
<p class="project-meta meta-data website"><a href="<?php echo get_post_meta( get_the_ID(), 'client_url', true ); ?>"
64+
target="<?php echo get_post_meta( get_the_ID(), 'is_external', true ); ?>"
65+
rel="<?php if ( get_post_meta( get_the_ID(), 'nofollow', true ) === '1' ){
66+
echo 'nofollow,';
67+
}
68+
if ( get_post_meta( get_the_ID(), 'noindex', true ) === '1' ) {
69+
echo 'noindex';
70+
} ?>"><?php echo get_post_meta( get_the_ID(), 'client_url', true ); ?></a></p>
71+
<?php } ?>
72+
73+
<!-- Services custom taxonomy -->
74+
<h6 class="project-meta meta-title services">Services:</h6>
75+
<p class="project-meta meta-data services">
76+
<?php
77+
$services_arr = get_the_terms( get_the_ID(), 'project_services' );
78+
$services = join(', ', wp_list_pluck($services_arr, 'name'));
79+
echo $services;
80+
?>
81+
</p>
82+
</aside> <!-- #project-sidebar -->
83+
84+
</div>
85+
86+
</section> <!-- #project-{page_id} -->
87+
<?php
88+
endwhile; endif;
89+
get_footer();
90+
?>

0 commit comments

Comments
 (0)