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

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

报告相同问题?

悬赏问题

  • ¥15 questasim仿真报错
  • ¥15 寻找电脑攻防的导师,有问题请教一下。
  • ¥20 微信同是win11,我的电脑安装不了pageoffice,一直无法打开
  • ¥15 这个界面我通过postman请求不到,但是通过浏览器可以正常访问
  • ¥15 动态规划算法实现背包问题
  • ¥15 wpf程序使用过程中异常奔溃
  • ¥15 多目标优化算法在与其他算法数据对比结果判断
  • ¥15 CPTN和EAST,主干网络是VGG16,请问在ICDAR2015数据集上训练之后,CPTN和EAST模型的大小为多少
  • ¥15 按颜色进行点云分割-python
  • ¥15 Matlab如何实现汽车变道切入场景的批量仿真