jquery - 在 wordpress 中添加自定义帖子类型

标签 jquery html css wordpress twitter-bootstrap

我正在尝试将 bootstrap 单页模板转换为 wordpress 模板,我想添加自定义帖子类型,它显示具有相同 css 的服务组合中的元素....这是我的服务部分。///我遵循了答案下面是我的部分代码

   <!-- Services -->
<section id="services" class="services bg-primary text-white">
  <div class="container">
    <div class="row text-center">
      <div class="col-lg-10 mx-auto">
        <h2>Our Services</h2>

        <hr class="small">
        <div class="row">

          <?php
              $args = array( 'post_type' => 'service', 'posts_per_page' => 10 );
              $the_query = new WP_Query( $args );
              ?>
              <?php if ( $the_query->have_posts() ) : ?>
              <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

              <div class="col-md-3 col-sm-6">
                                      <div class="service-item">
                                          <span class="fa-stack fa-4x">
                                              <i class="fa fa-circle fa-stack-2x"></i>
                                              <i class="fa fa-flask fa-stack-1x text-primary"></i>
                                          </span>
                                          <h4><?php the_title(); ?></h4>
                                          <p><?php the_content(); ?> </p>
                                          <a href="<?php the_permalink(); ?>" class="btn btn-light">Learn More</a>
                                      </div>
                                  </div>

              <?php wp_reset_postdata(); ?>
              <?php else:  ?>
              <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
              <?php endif; ?>


        </div>
        <!-- /.row (nested) -->
      </div>
      <!-- /.col-lg-10 -->
    </div>
    <!-- /.row -->
  </div>
  <!-- /.container -->
</section>

我很困惑我必须添加什么功能以及如何添加???????以及我必须在 index.php 文件中为不同部分替换的内容。和 functions.php 代码..

// Our custom post type function
 function create_posttype() {

     register_post_type( 'service',
     // CPT Options
         array(
             'labels' => array(
                 'name' => __( 'Services' ),
                 'singular_name' => __( 'Service' )
             ),
             'public' => true,
             'has_archive' => true,
             'rewrite' => array('slug' => 'service'),
         )
     );
 }
 // Hooking up our function to theme setup
 add_action( 'init', 'create_posttype'

);

现在显示语法错误

最佳答案

注册帖子类型将此代码添加到 function.php 中。 (建议创建单独的插件文件)

   // Our custom post type function
    function create_posttype() {

        register_post_type( 'service',
        // CPT Options
            array(
                'labels' => array(
                    'name' => __( 'Services' ),
                    'singular_name' => __( 'Service' )
                ),
                'public' => true,
                'has_archive' => true,
                'rewrite' => array('slug' => 'service'),
            )
        );
    }
    // Hooking up our function to theme setup
    add_action( 'init', 'create_posttype'

 );

使用以下代码显示服务:

<?php 
$args = array( 'post_type' => 'service', 'posts_per_page' => 10 );
$the_query = new WP_Query( $args ); 
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

<div class="col-md-3 col-sm-6">
                        <div class="service-item">
                            <span class="fa-stack fa-4x">
                                <i class="fa fa-circle fa-stack-2x"></i>
                                <i class="fa fa-flask fa-stack-1x text-primary"></i>
                            </span>
                            <h4><?php the_title(); ?></h4>
                            <p><?php the_content(); ?> </p>
                            <a href="<?php the_permalink(); ?>" class="btn btn-light">Learn More</a>
                        </div>
                    </div>
<?php endwhile; ?> 
<?php wp_reset_postdata(); ?>
<?php else:  ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

关于jquery - 在 wordpress 中添加自定义帖子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46215912/

相关文章:

html - TD背景不显示

html - 带有缩略图和缩放功能的纯 CSS 图片库

html - 没有嵌套容器的桌面和移动 flexbox 布局

javascript - 我应该如何改进我的 jQuery 点击功能?

jquery - 如何设置发生任何更改时退出弹出窗口并尝试移动到其他页面

php - 提醒另一个页面

java - play 2.0中使用ajax调用jsp/html页面

html - 我可以在 HTML 按钮上写公式吗?

javascript - 从 html 和 javascript 中的下拉选择中调用函数

javascript - Webpack html-loader 返回完整的模块定义