首页 文章

如何在WordPress中获得帖子 Headers

提问于
浏览
-5

我在wordpress工作,我需要在循环中显示帖子 Headers 及其描述 .

我不知道如何获得帖子的 Headers 及其描述 .

我目前的HTML代码如下:

<div class="col-md-4 col-sm-6">
                    <div class="single-service-home">
                        <div class="icon-box">
                            <div class="inner-box">
                                <i class="flaticon-gesture-1"></i>
                            </div>
                        </div>
                        <div class="content">
                                                    <h3>Charity For Education</h3>
                            <p>There are many variations of lorem <br>passagei of Lorem Ipsum available <br> but the majority have </p>
                            <a href="service-details.html">Read More</a>
                        </div>
                    </div>
                </div>

在上面的代码里面 <h3> 标签我需要显示 Headers ,在 <p> 标签中我需要显示描述 .

另外在阅读更多我需要提供该帖子的详细页面链接 .

1 回答

  • 2

    你需要从the loop开始 . WordPress文档包含大量信息和示例 . 循环是一个标准PHP代码片段,用于设置模板中的当前发布数据,并允许您为每个帖子(或页面)使用所有标准模板标记 .

    循环基本上是这样的:

    <?php 
    if (have_posts()): while (have_posts()) : the_post(); 
        //
        // HTML & any template tags go here.
        //
    endwhile; endif;
    ?>
    

    设置"the loop"后,您可以轻松回显诸如the titlethe permalink之类的内容以及其他模板标记 .

    例如,这很常见:

    <?php // Open the loop
    if (have_posts()): while (have_posts()) : the_post(); ?>
    
      <h1>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
      </h1>
      <div class="content"><?php the_content();?></div>
      <a class="read-more" href="<?php the_permalink(); ?>">Read more</a>
    
    <?php // End the loop
    endwhile; endif; ?>
    

    您还需要使用get headerget footer确保正确设置模板的其余部分 .

    谈到WordPress,只需Google吧 . 它已经在某个地方得到了解答,而WordPress文档也是开始的地方 . 例如,搜索“Wordpress节目 Headers ”,您将获得所需的信息 .

相关问题