dpo60833 2014-05-17 10:01
浏览 61
已采纳

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

I am new at 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'. 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. Have spent my much time in looking for this but could not solve this problem.

Please help me.

Thank you in advance

  • 写回答

1条回答 默认 最新

  • dongshuxi3105 2014-05-17 10:06
    关注

    You can not write php codes in editor.

    From what you want your normal archive.php should be showing the post of those two category when you visit those category url.

    But if you really want to make pages for that you have to use custom page template

    http://codex.wordpress.org/Page_Templates

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥200 求能开发抖音自动回复卡片的软件
  • ¥15 关于freesurfer使用freeview可视化的问题
  • ¥100 谁能在荣耀自带系统MagicOS版本下,隐藏手机桌面图标?
  • ¥15 求SC-LIWC词典!
  • ¥20 有关esp8266连接阿里云
  • ¥15 C# 调用Bartender打印机打印
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。
  • ¥15 已知隐函数其中一个变量τ的具体值,求另一个变量