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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵