doula2426 2017-04-04 07:35
浏览 51
已采纳

如何制作自定义WordPress主题节目页面,而不是帖子

I have recently created a custom WordPress theme, following a guide I found online.

However, all of the guides I came across explain how to set up a blogging site and do not explain how to set up a static website page. I am guessing that it is something to do with this code in my index.php:

.

                >.   get_template_part( 'content', get_post_format() );

            >.   endwhile; endif; 
        >.   ?>

When I remove this, it removes the blog layout. However, I do not know what to amend to make a static page layout.

Can anyone help please?

  • 写回答

2条回答 默认 最新

  • douqiu1604 2017-04-04 09:15
    关注

    get_post_format() Returns the post format of a post. This will usually be called in the the loop, but can be used anywhere if a post ID is provided. and its usually found on the posts pages/blogs.. therefore Its used in a theme when you want to display blog posts.

    As you you might know that wp have different posts types. let's just take two of them.

    Post (Post Type: 'post')

    Page (Post Type: 'page')

    The get_post_format() is used to get the format of a post,(blog Post) if you open your wp dashboard and start a new post or editing existing post you will see different posts formats types

    enter image description here

    As you can see from the image above, the red highlited part is the post format, that is what you are requesting when u use get_post_format() wp treats that template as it should display posts, but not pages.

    If you want the content of the page you then need to use the_content()

    Therefore this

    get_template_part( 'content', get_post_format() );
    
    endwhile; endif;
    

    becomes :

    get_template_part( 'content', the_content() );
    
    endwhile; endif; 
    

    alternatively :

     <div class="YourContainer">
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
      <div class="YourContentDiv">
    
       <?php the_content();?>
    
      </div>
      <?php endwhile; ?>
      <?php else:
            echo "no content found";
       ?>
    <?php endif; ?>
     </div>
    

    Hope this helps, Goodluck

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器