首页 文章

使用帖子 Headers 创建自定义WordPress页面

提问于
浏览
0

我正在尝试创建一个自定义WordPress页面,该页面仅包含指向我所有帖子 Headers 的链接,分为4列 . 我也在使用带有WordPress的Bootstrap .

我创建了php文件,用她的页面属性创建了一个新页面,但是帖子 Headers 没有显示 .

这是我使用的代码:

<?php
/**
 * The template used for displaying page content in questions.php
 *
 * @package fellasladies
 */
?>

<?php 

<article id="post-<?php the_ID(); ?>" <?php post_class('col-md-4 col-sm-4 pbox'); ?>>
    <header class="entry-header">
        <h1 class="entry-title"><?php the_title(); ?></h1>
    </header><!-- .entry-header -->

    <div class="entry-content">
        <?php the_content(); ?>
        <?php
            wp_link_pages( array(
                'before' => '<div class="page-links">' . __( 'Pages:', 'fellasladies' ),
                'after'  => '</div>',
            ) );
        ?>
    </div><!-- .entry-content -->
    <?php edit_post_link( __( 'Edit', 'fellasladies' ), '<footer class="entry-meta"><span class="edit-link">', '</span></footer>' ); ?>
</article><!-- #post-## -->

我非常感谢你的帮助!谢谢

2 回答

  • 1

    您需要首先创建一个Query,它使用您要迭代的帖子填充数组 . 阅读WordPress中的get_posts()函数 .

    这是一个例子 . 请注意,我们不能使用“在循环中”使用的函数,例如the_title()或the_content() . 我们必须为每次迭代指定post_id . 对于这种情况,我们不应该修改主查询 .

    // the arguments for the get_posts() function
    $args = array(
      'post_type' => 'post', // get posts int he "post" post_type
      'posts_per_page' => -1 // this means the array will be filled with all posts
    );
    $my_posts = get_posts($args);
    
    // now we'll iterate the posts
    foreach ( $my_posts as $p ) {
      // a title
      echo get_the_title($p->ID);
      // the link
      echo get_permalink($p->ID);
      // a custom field value
      echo get_post_meta($p->ID,'custom_field_key',true);
    }
    

    在每次迭代中发生的事情取决于你 .

    祝好运! :)

  • 1

    我鼓励你去阅读关于Wordpress Codex的Page Templates,这可以帮到你很多!

    Pages是WordPress的内置帖子类型之一 . 您可能希望大多数网站的页面看起来都一样 . 但有时,您可能需要一个特定的页面或一组页面来显示或表现不同 . 使用页面模板可以轻松完成此操作 .

    看来你的 <?php 没用了 . 你也没有't define your template'的名字,这是必需的 .

相关问题