236
You can add custom post with category/taxonomy option on WordPress
add_action( 'init', 'design_taxonomy');
# Registering Custom Market Type Post
add_action( 'init', 'register_design_post', 20 );
function register_design_post() {
$labels = array(
'name' => _x( 'Design Post', 'design_post','custom' ),
'singular_name' => _x( 'Design Post', 'design_post', 'custom' ),
'add_new' => _x( 'Add New', 'design_post', 'custom' ),
'add_new_item' => _x( 'Add New Design Post', 'design_post', 'custom' ),
'edit_item' => _x( 'Edit Design Post', 'design_post', 'custom' ),
'new_item' => _x( 'New Design Post', 'design_post', 'custom' ),
'view_item' => _x( 'View Design Post', 'design_post', 'custom' ),
'search_items' => _x( 'Search Design Post', 'design_post', 'custom' ),
'not_found' => _x( 'No Design Post found', 'design_post', 'custom' ),
'not_found_in_trash' => _x( 'No Design Post found in Trash', 'design_post', 'custom' ),
'parent_item_colon' => _x( 'Parent Design Post:', 'design_post', 'custom' ),
'menu_name' => _x( 'Design Post', 'design_post', 'custom' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'description' => 'Design Posts',
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'post-formats', 'custom-fields' ),
'taxonomies' => array( 'design_tag','design_categories'),
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => "dashicons-buddicons-replies",
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'query_var' => true,
'can_export' => true,
'public' => true,
'has_archive' => 'design',
'capability_type' => 'post'
);
register_post_type( 'design_post', $args );//max 20 charachter cannot contain capital letters and spaces
}
add_action( 'init', 'flush_on_init' );
function flush_on_init(){
flush_rewrite_rules();
}
How to show the post
<div class="container clearfix">
<div class="row">
<?php
$args = array(
'posts_per_page' => 12,
'orderby' => 'date',
'order' => 'DESC',
'post_type' => 'post',
'post_status' => 'publish',
'paged' => get_query_var('paged') ? get_query_var('paged') : 1
);
$the_query = new WP_Query( $args );
query_posts($args);
if ( $the_query->have_posts() ) :
while( $the_query->have_posts()):$the_query->the_post(); ?>
<div class="col-sm-6 col-md-4 col-lg-4">
<div class="news-back">
<div class="row up">
<div class="col-sm-12 ">
<div class="news-bg-wrap">
<?php the_post_thumbnail(); ?>
</div>
</div>
</div>
<div class="row down">
<div class="col-sm-12 text">
<p class="title"><a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a></p>
<div class="post_excerpt"><?php echo strip_tags(post_excerpt(10)); ?>.....</div>
<div class="readmores"><a href="<?php the_permalink(); ?>">Read More</a></div>
</div>
</div>
</div>
</div>
<?php
endwhile; ?>
</div>
<div class="row">
<div class="col-lg-12">
<?php the_posts_pagination(
array(
'prev_text' => '<',
'next_text' => '>',
'screen_reader_text' => ' '
)
); ?>
</div>
</div>
<?php endif;
wp_reset_query();
wp_reset_postdata();?>
</div>
Related