简体   繁体   English

在wordpress页面中编写php代码以显示特定类别的帖子

[英]Write php codes in wordpress pages to show particular category posts

I am new at Wordpress. 我是Wordpress的新手。 I have two pages namely 'Newsletters' and 'Service News' to show the news in my website. 我有两个页面,分别是“新闻通讯”和“服务新闻”,以在我的网站上显示新闻。 I want to show the posts belonging to a particular category in these pages. 我想在这些页面中显示属于特定类别的帖子。 The page 'Newsletters' should pull all the posts belonging to category slug 'newsletters' and the page 'Service News' should pull all the posts belonging to category slug 'service-news'. “ Newsletters”页面应拉出属于“ slug”“ newsletters”类别的所有帖子,而“ Service News”页面应拉出属于“ slug”“ service-news”类别的所有帖子。 How can i do so? 我该怎么办?

Somewhere i found that the following code can perform so. 我在某个地方发现以下代码可以执行此操作。

<?php $catPost = get_posts(array('category' => get_cat_ID(“newsletters”))); 
$event=array_splice($catPost, 0, 1); 
foreach ($event as $post) : setup_postdata($post); 
the_content(); ?>

But on writing the code on the text editor of the page, the whole code gets shown in the page. 但是,在页面的文本编辑器上编写代码后,整个代码就会显示在页面上。 Am i doing it wrong? 我做错了吗? Can't we write php codes in the editor. 我们不能在编辑器中编写php代码。 Have spent my much time in looking for this but could not solve this problem. 花了我很多时间在寻找这个问题,但无法解决这个问题。

Please help me. 请帮我。

Thank you in advance 先感谢您

You can not write php codes in editor. 您不能在编辑器中编写php代码。

From what you want your normal archive.php should be showing the post of those two category when you visit those category url. 从您想要的文件中,当您访问那些类别URL时,普通的archive.php应该显示这两个类别的帖子。

But if you really want to make pages for that you have to use custom page template 但是,如果您真的想为此创建页面,则必须使用自定义页面模板

http://codex.wordpress.org/Page_Templates http://codex.wordpress.org/Page_Templates

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

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