I can easily do it if i make a custom post but doing so will make the original post type unused. I would like to use it than building a new custom post type. I have made page-news.php but it is not able to show up on this page. also Currently, post are showing up www.somedomain.com/posts_title format i would like it to be www.somedomain.com/news/posts_title
here is my page.news.php
<?php
/*
Template Name: News
*/
?>
<?php get_header();?>
<div class="mainwrapper">
<!-- slide -->
</div>
<div class="content content-topone">
<div class="container-fluid">
<div class="row portfolio">
<?php $loop = new WP_Query( array( 'post_type' => '', 'posts_per_page' => -1 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="col-lg-3 col-md-4 col-sm-6 col-xs-12 portfoliobox">
<div class="thumbnail">
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php
if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
the_post_thumbnail();
} else {
$img = '/img/responsive-webness.png"';
$attrib = ' class="' . 'img-responsive' . '" alt="' . ' '. '"/>';
$begin = '<img src="';
$getpath = get_template_directory_uri();
echo $begin . $getpath. $img . $attrib;
}
?>
</a>
<p><?php the_title(); ?></p>
<p><?php the_content(); ?></p>
</div><!-- .thumbnail -->
</div>
<?php endwhile; wp_reset_query(); ?>
<div class="clear"></div>
</div>
</div>
</div>
<?php get_footer();?>
Change this:
$loop = new WP_Query( array( 'post_type' => '', 'posts_per_page' => -1 ) );
To this:
$loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1 ) );
So you can display native posts
in your news page. All you need to do just loop
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) {
$loop->the_post();
?><h2><?php the_title(); ?></h2><?php
}
}
To display any custom post type just change the post_type
in the array. Read more on Codex .
To change the URI
format, go to your WordPress
dashboard and then navigate to Settings->Permalink
from menu and then select the Custom Structure
radio button and enter /%postname%/%category%/
in the text box and then save the changes. Check this for more.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.