Wordpress,自定义主题,自定义帖子类型

时间:2013-11-22 02:45:38

标签: php wordpress wordpress-theming

我是网络开发的初学者。我正在使用自定义主题(underscore.me)在WordPress中创建网站。我需要在网站上制作两张桌子。第一个表是“过去的项目”,第二个表是“未来项目”。 我为这个表创建了自定义帖子类型:call(Properties), 自定义帖子类型“属性”显示: 1.Past项目或未来项目 2.财产名称 3.属性照片 4.财产地址 5.属性日期 6.Property apts 7.属性大小 8.财产状况 9 ...

这是我的HTML表格:

<div id="main-content">
<div class="container">
     <div class="sixteen columns">
        <div class="tab-content sixteen columns">  
          <div class="tab-pane active" id="table1">
             <p class="table-name">Featured Projects</p>
              <table class="footable tablet footable-loaded">
                <thead>
                  <tr>
                    <th data-class="expand" data-sort-initial="true" class="footable-sortable footable-sorted footable-first-column">
                      <span title="table sorted by the column on load">Project</span>
                      <span class="footable-sort-indicator"></span>
                    </th>
                    <th class="footable-sortable">
                      <span title="sorting disabled on this column">Photos</span>
                      <span class="footable-sort-indecator"></span>
                    </th>
                    <th class="footable-sortable">
                        Address
                        <span class="footable-sort-indecator"></span>
                    </th>
                    <th data-hide="phone" data-type="numeric" class="footable-sortable">
                        Year
                        <span class="footable-sort-indecator"></span>
                    </th>
                    <th data-hide="phone" data-type="numeric" class="footable-sortable">
                        APTS
                        <span class="footable-sort-indecator"></span>
                    </th>
                    <th data-hide="phone" data-type="numeric" class="footable-sortable">
                        SQ. FT
                        <span class="footable-sort-indecator"></span>
                    </th>
                    <th data-hide="phone" data-type="numeric" class="footable-sortable">
                        STATUS
                        <span class="footable-sort-indecator"></span>
                    </th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                   <td class="expand footable-first-column">
                       <a href=""></a>
                   </td>
                   <td>
                     <a class="photo-icon" href="">Photo</a>
                   </td>
                   <td>21-45 45th Drive-Long Island City</td>
                   <td>2010</td>
                   <td>23</td>
                   <td>30,000</td>
                   <td class="footable-last-column">In Development</td>
                  </tr>
                  <tr>
                    <td class="expand footable-first-column">
                        <a href="">The Industry</a>
                    </td>
                    <td>
                        <a class="photo-icon" href="">Photo</a>
                    </td>
                    <td>21-45 45th Drive-Long Island City</td>
                    <td>2010</td>
                    <td>23</td>
                    <td>30,000</td>
                    <td class="footable-last-column">In Development</td>
                    </tr>
                </tbody>
              </table>    
          </div>     
        </div>  
     </div>
   </div>

问题:如何在我的自定义主题页面中使用php查询显示特定帖子类型(自定义帖子类型)的帖子,以及如何使用PHP查询创建功能以轻松创建或删除“过去项目”或“未来项目” ”。

如果有人能帮助我,我将非常感激。再次感谢你。

1 个答案:

答案 0 :(得分:1)

你让自己变得更加困难。您不需要创建任何其他数据库表,除非您真的想要...

当网站访问者点击链接查看自定义帖子类型时会发生什么。 (伪代码)

select * from wp_customPostType

它是这样的:

select * from wp_posts where posts.post_type = 'custom_post_type'

这是你如何做到的。 (你做的顺序没有区别)

  1. Use this post type generator创建自定义帖子类型,但只创建一个名为项目 it's DRYer )并启用 分类法。
  2. 在主题目录中复制single.php,粘贴并更改 name to single-Projects.php。
  3. 在你的主题的functions.php中(你应该真正使用一个孩子 主题(如果您还没有)使用?php register_post_type( $post_type, $args ) ?>

  4. 注册新帖子类型
  5. 在single.php(orignal,而不是你复制的那个)中添加如下内容:

  6. if ( 'Project' == get_post_type() )
    {
    use single-Project.php
    }
    else
    {
    continue using this page (single.php)
    

    您必须为单个Project.php创建新布局,但是您要做的就是为您创建的项目添加过去和将来的分类。当未来成为过去时,您所要做的就是更改分类,而不是为过去的项目创建新帖子。

相关问题