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

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

报告相同问题?

悬赏问题

  • ¥20 matlab计算中误差
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊