-
Notifications
You must be signed in to change notification settings - Fork 0
/
hvboom-portfolio-cpt.php
108 lines (90 loc) · 2.89 KB
/
hvboom-portfolio-cpt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/**
* Require helper class
*/
require_once(CURRENT_PLUGIN_PATH . 'vendor/wp-custom-post-type-class/src/CPT.php');
/**
* Register custom post type Portfolio
*/
$portfolio = new CPT(
array(
'post_type_name' => 'portfolio',
'singular' => 'Portfolio',
'plural' => 'Portfolio',
'slug' => 'portfolio'
),
array(
'supports' => array('title', 'editor', 'thumbnail', 'comments'),
'menu_icon' => 'dashicons-portfolio',
'set_textdomain' => 'hvboom'
)
);
/**
* Register taxonomy
*/
$portfolio->register_taxonomy(
array(
'taxonomy_name' => 'portfolio_tags',
'singular' => 'Portfolio Tag',
'plural' => 'Portfolio Tags',
'slug' => 'portfolio-tag'
)
);
function hvboom_get_portfolio(){
$portfolio = '<section class="hvboom-portfolio">' . PHP_EOL;
$args = "post_type=portfolio";
$catalog = new WP_Query($args);
while($catalog->have_posts()) : $catalog->the_post();
$img = hvboom_get_image();
$portfolio .= ' <article>' . PHP_EOL;
$portfolio .= ' <div class="styling-wrapper">' . PHP_EOL;
$portfolio .= $img;
$portfolio .= ' <header><h1>';
$portfolio .= sprintf ('<a href="%s" rel="bookmark">', esc_url( get_permalink() ) ) . get_the_title() . '</a>';
$portfolio .= '</h1></header>' . PHP_EOL;
$portfolio .= ' <section>' . get_the_excerpt() . '</section>' . PHP_EOL;
$portfolio .= ' <hr />' . PHP_EOL;
$portfolio .= ' <footer>' . PHP_EOL;
$portfolio .= sprintf (' <a href="%s" class="" role="button">', esc_url( get_permalink() ) ) . __('View Project', 'hvboom') . '</a>' . PHP_EOL;
$portfolio .= ' </footer>' . PHP_EOL;
$portfolio .= ' </div> <!-- end of styling-wrapper -->' . PHP_EOL;
$portfolio .= ' </article>' . PHP_EOL;
$portfolio .= ' <smart-break></smart-break> <!-- styling element used only to break article in a responsive way -->' . PHP_EOL;
endwhile;
wp_reset_postdata();
$portfolio .= '</section>' . PHP_EOL;
return $portfolio;
}
/**
* Shortcode
*/
function hvboom_portfolio_shortcode($atts, $content = null) {
$portfolio = hvboom_get_portfolio();
return $portfolio;
}
add_shortcode('hvboom_portfolio', 'hvboom_portfolio_shortcode');
/**
* Template-Tag
*/
function hvboom_portfolio_tag() {
print hvboom_get_portfolio();
}
/**
* Include CSS
*/
function hvboom_plugin_scripts() {
wp_enqueue_style('hvboom-portfolio', CURRENT_PLUGIN_STYLESHEET_URL . 'hvboom-portfolio.css', array('bootstrap-styles'));
}
add_action('wp_enqueue_scripts', 'hvboom_plugin_scripts');
/**
* Helper functions
*/
function hvboom_get_image($pid = NULL, $size = 'thumbnail') {
$url = wp_get_attachment_image_src(get_post_thumbnail_id($pid), $size);
$content = '';
if($url) {
$content .= ' <img src="' . $url[0] . '" alt="' . esc_attr(get_the_title($pid)) . '" />' . PHP_EOL;
}
return $content;
}
?>