gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 08:11:53 25 4
gpt4 key购买 nike

我正在尝试将 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com