【问题标题】:Wordpress how to create custom post templateWordpress 如何创建自定义帖子模板
【发布时间】:2017-11-20 12:01:49
【问题描述】:

Wordpress 如何从 INDEX.php 的部分创建自定义帖子模板!在我的首页 (Index.php) 我有一个很棒的 Post Grid。我想在每个帖子下都有这个网格(在评论字段之间的帖子内容下)。我已经从 (Index.php) 代码中复制了一些部分并插入到 post.php 中,但是结果并不令人满意。

我到处搜索,但找不到与我的 wordpress 主题兼容的令人满意的解决方案。如果有人可以帮助我,请让我知道您需要什么代码。我很乐意听到解决方案!

提前致谢

【问题讨论】:

  • 在评论字段之间的帖子内容下?,混淆你的问题,解释清楚一点。

标签: wordpress wordpress-theming customization custom-post-type custom-wordpress-pages


【解决方案1】:

不是很清楚你的意思,但我想你想在你的 single.php 文件上打印一些帖子。为此,您需要一个类似于以下内容的WP_Query

<?php 
// the query
$args = array(
    'post_type' => 'post' // change as needed
);
$the_query = new WP_Query( $args ); ?>

<?php if ( $the_query->have_posts() ) : ?>

<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <h2><?php the_title(); ?></h2>  <!-- Copy same structure and data as the one on the index.php file -->
<?php endwhile; ?>
<!-- end of the loop -->

<?php wp_reset_postdata(); ?>

您需要保持与 index.php 中相同的 div 结构和类,以使它们看起来相似。 祝你好运!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多