简体   繁体   English

如何在WordPress页面添加帖子?

[英]How to add posts in wordpress pages?

我想在我的wordpress网站的首页上显示一些帖子。我该怎么做?或者有任何插件可以帮助我完成此操作?或者有可以在我的首页中显示并显示这些帖子的简码吗?

If you want to do it the easy way, you can use a plugin like Display Posts Shortcode . 如果您想以简单的方式进行操作,可以使用Display Posts Shortcode之类的插件。

Or, if you want to do it manually, you can use get_posts() . 或者,如果您想手动进行操作,则可以使用get_posts()

Here's an example you could use: 这是您可以使用的示例:

<?php
if (is_page()) {
  $cat=get_cat_ID($post->post_title); //use page title to get a category ID
  $posts = get_posts ("cat=$cat&showposts=5");
  if ($posts) {
    foreach ($posts as $post):
      setup_postdata($post); ?>
      <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <?php endforeach;
  }
}
?>

I hope this helps! 我希望这有帮助!

The implemetation varies greatly by theme. 实现因主题而异。 Check if your wordpress theme has a file called index.php. 检查您的wordpress主题是否有一个名为index.php的文件。 If you have this file for your current theme, this is the file responsible for displaying your home page. 如果您拥有用于当前主题的文件,则该文件负责显示您的主页。 And this is where you will have to put the code snippets to display posts. 这是您必须放置代码段以显示帖子的地方。

Presuming that you know a bit of html and PHP you will have to decide the suitable place within index.php to add the code suggested above by Amal Murali. 假设您了解一些html和PHP,则必须确定index.php中的合适位置,以添加上述Amal Murali建议的代码。

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

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