Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Wordpress的新闻页面上显示帖子?_Php_Wordpress - Fatal编程技术网

Php 如何在Wordpress的新闻页面上显示帖子?

Php 如何在Wordpress的新闻页面上显示帖子?,php,wordpress,Php,Wordpress,我可以很容易地做到这一点,如果我做一个自定义的职位,但这样做会使原来的职位类型未使用。我想使用它,而不是建立一个新的自定义职位类型。我制作了page-news.php,但它无法显示在此页面上。目前,也有帖子出现 www.somedomain.com/posts\u title格式我希望它是www.somedomain.com/news/posts\u title 这是我的页面。news.php <?php /* Template Name: News */ ?> <?ph

我可以很容易地做到这一点,如果我做一个自定义的职位,但这样做会使原来的职位类型未使用。我想使用它,而不是建立一个新的自定义职位类型。我制作了page-news.php,但它无法显示在此页面上。目前,也有帖子出现 www.somedomain.com/posts\u title格式我希望它是www.somedomain.com/news/posts\u title

这是我的页面。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();?>

更改此选项:

$loop = new WP_Query( array( 'post_type' => '', 'posts_per_page' => -1 ) );
为此:

$loop = new WP_Query( array( 'post_type' => 'post', 'posts_per_page' => -1 ) );
因此,您可以在新闻页面中显示本机
帖子。你所需要做的就是循环

if ( $loop->have_posts() ) {
    while ( $loop->have_posts() ) {
        $loop->the_post();
        ?><h2><?php the_title(); ?></h2><?php
    }
}
if($loop->have_posts()){
而($loop->have_posts()){
$loop->the_post();

?>$loop=new WP\u查询(数组('post\u type'=>'','posts\u per\u page'=>-1));用于显示。其作用与$loop=new WP\u查询相同(数组('post\u type'=>'post','posts\u per\u page'=>-1));因为它是内置的默认帖子类型。那么您的问题/问题是什么?它无法获取page-news.php进行模板化,并且无法像下面这样显示url www.somedomain.com/news/posts_title news是我创建的页面。我想显示关于新闻的帖子。在这种情况下,您需要创建一个,我已经回答了如何更改
url
格式。