Давайте продолжим программировать детальную страницу портфолио. Нам осталось настроить вывод слайдера и дополнительных свойств. Для этого нужно воспользоватся мета боксоми(meta boxes) WordPress. Что бы их создать, воспользуемся классом SP_Framework_Post_Type_Meta_Box.
Добавим следующий код в файл meta-boxes.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 |
<?php /* * Meta boxes */ /* * Meta: sp_protfolio */ $spMB = new SP_Framework_Post_Type_Meta_Box(); $args = array( 'post_type' => 'sp_portfolio', 'name' => 'settings_name', 'label' => 'Settings', 'validate' => 'n', 'sanitize' => 'n', 'fields' => array( 'portfolio_images' => array( 'type' => 'images', 'name' => 'portfolio_images', 'label' => 'Images', 'caption' => '', 'required' => 'n', 'default' => '', ), 'portfolio_сreated_by' => array( 'type' => 'text', 'name' => 'portfolio_сreated_by', 'label' => 'Created by', 'caption' => '', 'required' => 'n', 'default' => '', ), 'portfolio_completed_on' => array( 'type' => 'text', 'name' => 'portfolio_completed_on', 'label' => 'Completed on', 'caption' => '', 'required' => 'n', 'default' => '', ), 'portfolio_skills' => array( 'type' => 'text', 'name' => 'portfolio_skills', 'label' => 'Skills', 'caption' => '', 'required' => 'n', 'default' => '', ), 'portfolio_client' => array( 'type' => 'text', 'name' => 'portfolio_client', 'label' => 'Client', 'caption' => '', 'required' => 'n', 'default' => '', ), ), ); $spMB->create($args); ?> |
Теперь настроим вывод в шаблоне. Для это воспользуемся методом get_meta класса SP_Framework_Post_Type_Utility. Есть один важный момент, для получения значения мета бокса типа images, в имени нужно использовать префикс
img_
1 |
$portfolioImages = SP_Framework_Post_Type_Utility::get_meta($postID, 'img_portfolio_images'); |
Теперь наш шаблон примет следующий вид:
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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
<?php /* * Portfolio single page */ get_header(); $postID = get_the_ID(); $postTitle = get_the_title(); $postContent = SP_Framework_Post_Type_Utility::get_content($postID); $portfolioImages = SP_Framework_Post_Type_Utility::get_meta($postID, 'img_portfolio_images'); $portfolioCreatedBy = SP_Framework_Post_Type_Utility::get_meta($postID, 'portfolio_сreated_by'); $portfolioCompletedOn = SP_Framework_Post_Type_Utility::get_meta($postID, 'portfolio_completed_on'); $portfolioSkills = SP_Framework_Post_Type_Utility::get_meta($postID, 'portfolio_skills'); $portfolioClient = SP_Framework_Post_Type_Utility::get_meta($postID, 'portfolio_client'); ?> <!-- Page Title ============================================= --> <section id="page-title"> <div class="container clearfix"> <h1><?php echo $postTitle;?></h1> </div> </section><!-- #page-title end --> <!-- Content ============================================= --> <section id="content"> <div class="content-wrap"> <div class="container clearfix"> <!-- Portfolio Single Gallery ============================================= --> <div class="col_full portfolio-single-image"> <div class="fslider" data-arrows="true" data-animation="slide"> <div class="flexslider"> <div class="slider-wrap"> <div class="slide"><a href="#"><img src="images/portfolio/single/full/1.jpg" alt=""></a></div> <div class="slide"><a href="#"><img src="images/portfolio/single/full/7.jpg" alt=""></a></div> <div class="slide"><a href="#"><img src="images/portfolio/single/full/10.jpg" alt=""></a></div> </div> </div> </div> <?php if(!empty($portfolioImages)){ echo '<div class="fslider" data-arrows="true" data-animation="slide">'; echo '<div class="flexslider">'; echo '<div class="slider-wrap">'; foreach ($portfolioImages as $imageID) { $imageFull = wp_get_attachment_image_url($imageID, 'full'); $imageLarge = wp_get_attachment_image_url($imageID, 'large'); echo '<div class="slide"><a href="'.$imageFull.'"><img src="'.$imageLarge.'" alt="Image: '.$postTitle.'"></a></div>'; } echo '</div>'; echo '</div>'; echo '</div>'; } ?> </div><!-- .portfolio-single-image end --> <div class="col_one_third nobottommargin"> <!-- Portfolio Single - Meta ============================================= --> <div class="card events-meta"> <div class="card-body"> <ul class="portfolio-meta nobottommargin"> <?php if(!empty($portfolioCreatedBy)){ echo '<li><span><i class="icon-user"></i>Created by:</span> '.$portfolioCreatedBy.'</li>'; } if(!empty($portfolioCompletedOn)){ echo '<li><span><i class="icon-calendar3"></i>Completed on:</span> '.$portfolioCompletedOn.'</li>'; } if(!empty($portfolioSkills)){ echo '<li><span><i class="icon-lightbulb"></i>Skills:</span> '.$portfolioSkills.'</li>'; } if(!empty($portfolioClient)){ echo '<li><span><i class="icon-link"></i>Client:</span> '.$portfolioClient.'</li>'; } ?> </ul> </div> </div> <!-- Portfolio Single - Meta End --> </div> <!-- Portfolio Single Content ============================================= --> <div class="col_two_third portfolio-single-content col_last nobottommargin"> <!-- Portfolio Single - Description ============================================= --> <div class="fancy-title title-dotted-border"> <h2>Project Info:</h2> </div> <div class="col_full nobottommargin"> <?php echo $postContent;?> </div> <!-- Portfolio Single - Description End --> </div><!-- .portfolio-single-content end --> <div class="clear"></div> <div class="divider divider-center"><i class="icon-circle"></i></div> <!-- Related Portfolio Items ============================================= --> <h4>Related Projects:</h4> <div id="related-portfolio" class="owl-carousel portfolio-carousel carousel-widget" data-margin="30" data-nav="false" data-autoplay="5000" data-items-xs="1" data-items-sm="2" data-items-md="3" data-items-xl="4"> <div class="oc-item"> <div class="iportfolio"> <div class="portfolio-image"> <a href="portfolio-single.html"> <img src="images/portfolio/4/1.jpg" alt="Open Imagination"> </a> </div> <div class="portfolio-desc"> <h3><a href="portfolio-single.html">Open Imagination</a></h3> <span><a href="#">Media</a>, <a href="#">Icons</a></span> </div> </div> </div> <div class="oc-item"> <div class="iportfolio"> <div class="portfolio-image"> <a href="portfolio-single.html"> <img src="images/portfolio/4/2.jpg" alt="Locked Steel Gate"> </a> </div> <div class="portfolio-desc"> <h3><a href="portfolio-single.html">Locked Steel Gate</a></h3> <span><a href="#">Illustrations</a></span> </div> </div> </div> <div class="oc-item"> <div class="iportfolio"> <div class="portfolio-image"> <a href="portfolio-single.html"> <img src="images/portfolio/4/1.jpg" alt="Open Imagination"> </a> </div> <div class="portfolio-desc"> <h3><a href="portfolio-single.html">Open Imagination</a></h3> <span><a href="#">Media</a>, <a href="#">Icons</a></span> </div> </div> </div> <div class="oc-item"> <div class="iportfolio"> <div class="portfolio-image"> <a href="portfolio-single.html"> <img src="images/portfolio/4/2.jpg" alt="Locked Steel Gate"> </a> </div> <div class="portfolio-desc"> <h3><a href="portfolio-single.html">Locked Steel Gate</a></h3> <span><a href="#">Illustrations</a></span> </div> </div> </div> <div class="oc-item"> <div class="iportfolio"> <div class="portfolio-image"> <a href="portfolio-single.html"> <img src="images/portfolio/4/1.jpg" alt="Open Imagination"> </a> </div> <div class="portfolio-desc"> <h3><a href="portfolio-single.html">Open Imagination</a></h3> <span><a href="#">Media</a>, <a href="#">Icons</a></span> </div> </div> </div> <div class="oc-item"> <div class="iportfolio"> <div class="portfolio-image"> <a href="portfolio-single.html"> <img src="images/portfolio/4/2.jpg" alt="Locked Steel Gate"> </a> </div> <div class="portfolio-desc"> <h3><a href="portfolio-single.html">Locked Steel Gate</a></h3> <span><a href="#">Illustrations</a></span> </div> </div> </div> </div><!-- .portfolio-carousel end --> </div> </div> </section><!-- #content end --> <?php get_footer(); |
Вывод слайдера из списка проектов(Related Projects) настроим чуть позже.