简体   繁体   English

如何在WordPress中获取帖子标题

[英]How to get the post title in WordPress

I am working in wordpress, and I need to show post title and its description in a loop.我在 wordpress 工作,我需要循环显示帖子标题及其描述。

I don't know how to get the post's title and its description.我不知道如何获得帖子的标题和描述。

My current html code is below:我当前的 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>

In the above code inside <h3> tag I need to show the title and in <p> tag I need to show the description.<h3>标签中的上述代码中,我需要显示标题,而在<p>标签中,我需要显示描述。

Also in readmore I need to give that post's detail page link.同样在阅读中,我需要提供该帖子的详细信息页面链接。

You need to start with the loop .你需要从循环开始。 The WordPress docs have loads of info with examples. WordPress 文档包含大量带有示例的信息。 The loop is a snippet of standard PHP code that sets up the current post data in your template and allows you to use all the standard template tags for each post (or page).该循环是一段标准 PHP 代码,用于在您的模板中设置当前帖子数据,并允许您为每个帖子(或页面)使用所有标准模板标签。

The loop is basically this:循环基本上是这样的:

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

Once you've set up "the loop", you can easily echo out things like the title , the permalink , and loads of other template tags.一旦您设置了“循环”,您就可以轻松地回显诸如titlepermalink和其他模板标签的负载。

For example, this is common:例如,这是常见的:

<?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; ?>

You'll also need to make sure the rest of your template is set up correctly, using get header and get footer .您还需要使用get headerget footer确保模板的其余部分设置正确。

When it comes to WordPress, just Google it.说到 WordPress,只需谷歌一下。 It'll be answered already somewhere, and the WordPress docs are the place to start.它会在某个地方得到回答,而 WordPress 文档是开始的地方。 For example, search "Wordpress show title" and you'd get the info you need.例如,搜索“Wordpress 节目标题”,您将获得所需的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM