Last active
August 8, 2018 05:13
-
-
Save sudipbd/529061e18e44558fb28334d1a20ce6f5 to your computer and use it in GitHub Desktop.
WordPress custom post with custom field
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ah_custom_posts() { | |
//for slider | |
register_post_type('banner',array( | |
'public' => true, | |
'label' => 'Banner', | |
'labels' => array( | |
'name' => 'Banner', | |
'singular_name' => 'Banner', | |
'add_new' => 'Add new banner', | |
), | |
'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'custom-fields') | |
)); | |
add_action( 'init', 'ah_custom_posts' ); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
global $post; | |
$number = 0; | |
$args = array( 'posts_per_page' => -1, 'post_type'=> 'banner', 'order' => 'ASC', ); | |
$myposts = get_posts( $args ); | |
foreach( $myposts as $post ) : setup_postdata($post); ?> | |
<?php //adding custom fields ?> | |
<?php | |
$link_text1= get_post_meta($post->ID, 'link_text1', true); | |
$btn_link1= get_post_meta($post->ID, 'btn_link1', true); | |
$link_text2= get_post_meta($post->ID, 'link_text2', true); | |
$btn_link2= get_post_meta($post->ID, 'btn_link2', true); | |
?> | |
<div class="banner_single"> | |
<?php the_post_thumbnail(); ?> | |
<div class="banner_text"> | |
<p><?php the_excerpt(); ?></p> | |
<h1><?php the_title(); ?></h1> | |
<a href="<?php echo $btn_link1; ?>" class="pust_btn"><?php echo $link_text1; ?></a> | |
<a href="<?php echo $btn_link2; ?>" class="pust_btn"><?php echo $link_text2; ?></a> | |
</div> | |
</div> | |
<?php endforeach; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment