WP POST format works
Post format based post dynamic:-
..................................
//post format niye kaj korte hole template-parts folder er vitore file gula ke rekhe index.php theke include korte hobe.
<?php while(have_posts()) : the_post(); ?>
<?php get_template_part('template-parts/content', get_post_format()) ?> //index.php er code
<?php endwhile; ?>
.........................................
//content.php er code
<article class="post-single">
<div class="post-info">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<h6 class="upper"><span>By</span><a href="#"> <?php the_author(); ?></a><span class="dot"></span><span><?php the_time('F d, Y'); ?></span><span class="dot"></span><a href="#" class="post-tag"><?php the_tags(); ?></a></h6>
</div>
<div class="post-media"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></div>
<div class="post-body">
<p><?php echo wp_trim_words(get_the_content(), 30, false); ?></p>
<p><a href="<?php the_permalink(); ?>" class="btn btn-color btn-sm">Read More</a></p>
</div>
</article>
.....................
//template-parts er vitore coontent ke duplicate kore , content-audio,content-video, content-gallery, content-quote.php name file create korte hobe.
then, just post media ta change korte hobe, and quote er jonno
<blockquote class="italic">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Et quam neque facilis similique laborum, nihil id ratione, error illum. Porro quas maxime accusamus numquam consequatur consequuntur eveniet quis, fuga repellendus.</p>
</blockquote>
eita copy kore content-quote.php file er post-body er vitore rakhte hobe.
................
First step:-
//post er niche field anar jonno cmb2 er vitore config.php te ei script gulo add korte hobe:-
<?php
function amader_meta(){
//============for video box============
$com_post = new_cmb2_box([
'title' => 'Video Post Box',
'id' => 'com-video',
'object_types' => ['post']
]);
$com_post -> add_field([
'name' => 'Video Link',
'id' => 'video-post-link',
'type' => 'text'
]);
//=================for audio box=================
$com_post = new_cmb2_box([
'title' => 'Audio Post Box',
'id' => 'com-audio',
'object_types' => ['post']
]);
$com_post -> add_field([
'name' => 'Audio Link',
'id' => 'audio-post-link',
'type' => 'text'
]);
//=============for Gallery box===============
$com_post = new_cmb2_box([
'title' => 'Gallery Post Box',
'id' => 'com-gallery',
'object_types' => ['post']
]);
$com_post -> add_field([
'name' => 'Gallery Images',
'id' => 'gallery-images',
'type' => 'file_list'
]);
}
add_action('cmb2_init','amader_meta');
?>
.........
second step:-
.................
-----------------------------------------
//========================admin scripts====================
function admin_script(){
if(get_post_type() == 'post') :
?>
<script>
(function($){
$(document).ready(function(){
$('#com-video').hide();
$('#com-audio').hide();
$('#com-gallery').hide();
var id = $("input[class='post-format']:checked").attr('id');
if(id== 'post-format-video'){
$('#com-video').show();
}else{
$('#com-video').hide();
}
if(id== 'post-format-audio'){
$('#com-audio').show();
}else{
$('#com-audio').hide();
}
if(id== 'post-format-gallery'){
$('#com-gallery').show();
}else{
$('#com-gallery').hide();
}
$('input.post-format').change(function(){
var id = $("input[class='post-format']:checked").attr('id');
if(id== 'post-format-video'){
$('#com-video').show();
}else{
$('#com-video').hide();
}
if(id== 'post-format-audio'){
$('#com-audio').show();
}else{
$('#com-audio').hide();
}
if(id== 'post-format-gallery'){
$('#com-gallery').show();
}else{
$('#com-gallery').hide();
}
});
});
})(jQuery)
</script>
<?php
endif;
}
add_action('admin_print_scripts', 'admin_script', 1000); //1000 holo priority
//functions.php er code
then,
----
//video post dynamic
<article class="post-single">
<div class="post-info">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<h6 class="upper"><span>By</span><a href="#"> <?php the_author(); ?></a><span class="dot"></span><span><?php the_time('F d, Y'); ?></span><span class="dot"></span><a href="#" class="post-tag"><?php the_tags(); ?></a></h6>
</div>
<div class="post-media">
<div class="media-video">
<?php echo wp_oembed_get(get_post_meta(get_the_ID(), 'video-post-link', true)); ?> //cmb2 er config.php er add fliend er id eita.
</div>
</div>
<div class="post-body">
<p><?php echo wp_trim_words(get_the_content(), 30, false); ?></p>
<p><a href="<?php the_permalink(); ?>" class="btn btn-color btn-sm">Read More</a></p>
</div>
</article>
.....................
/audio post dynamic
<article class="post-single">
<div class="post-info">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<h6 class="upper"><span>By</span><a href="#"> <?php the_author(); ?></a><span class="dot"></span><span><?php the_time('F d, Y'); ?></span><span class="dot"></span><a href="#" class="post-tag"><?php the_tags(); ?></a></h6>
</div>
<div class="post-media">
<div class="media-audio">
<?php echo wp_oembed_get(get_post_meta(get_the_ID(), 'audio-post-link', true)); ?> //cmb2 er config.php er add fliend er id eita.
</div>
</div>
<div class="post-body">
<p><?php echo wp_trim_words(get_the_content(), 30, false); ?></p>
<p><a href="<?php the_permalink(); ?>" class="btn btn-color btn-sm">Read More</a></p>
</div>
</article>
....
//gallery post dynamic
<article class="post-single">
<div class="post-info">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<h6 class="upper"><span>By</span><a href="#"> <?php the_author(); ?></a><span class="dot"></span><span><?php the_time('F d, Y'); ?></span><span class="dot"></span><a href="#" class="post-tag"><?php the_tags(); ?></a></h6>
</div>
<div class="post-media">
<div data-options="{"animation": "slide", "controlNav": true" class="flexslider nav-outside">
<ul class="slides">
<?php
$gall = get_post_meta(get_the_ID(), 'gallery-images', true); //cmb2 er config.php er add fliend er id eita.
foreach ($gall as $gallllll) :
?>
<li><img src="<?php echo $gallllll ?>" alt="" ></li>
<?php endforeach; ?>
</ul>
</div>
</div>
<div class="post-body">
<p><?php echo wp_trim_words(get_the_content(), 30, false); ?></p>
<p><a href="<?php the_permalink(); ?>" class="btn btn-color btn-sm">Read More</a></p>
</div>
</article>
...................
//quote post dynamic
<article class="post-single">
<div class="post-info">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<h6 class="upper"><span>By</span><a href="#"> <?php the_author(); ?></a><span class="dot"></span><span><?php the_time('F d, Y'); ?></span><span class="dot"></span><a href="#" class="post-tag"><?php the_tags(); ?></a></h6>
</div>
<div class="post-body">
<blockquote class="italic">
<p><?php the_content(); ?></p>
</blockquote>
</div>
</article>
........................
No comments