【问题标题】:Displaying posts only form a category that has same name as the current page显示帖子仅形成与当前页面同名的类别
【发布时间】:2014-02-06 10:22:55
【问题描述】:

我的主题支持不同的帖子类型 - 其中之一是投资组合帖子。我正在尝试在页面上显示投资组合帖子,但仅来自一个特定类别 - 与当前页面同名的类别。

示例:
我有以下类别的投资组合帖子:红色、绿色、蓝色。
我的页面名为:红色、绿色、蓝色。 现在我想在“红色”页面上仅显示“红色”类别的帖子。

我对 wordpress 和一般网站制作非常陌生。

我尝试阅读了一些关于它的内容,并找到了一种仅显示某些类别的帖子的方法:

<?php $the_query = new WP_Query( 'portfolio_category=red' );?>

从那里我尝试这样做,但它不起作用:

<?php $the_query = new WP_Query( 'portfolio_category=$pagename' );?>

这是我正在谈论的页面模板的完整代码: http://pastebin.com/LxetTnUz

【问题讨论】:

  • pastebin 链接不起作用...

标签: php wordpress categories posts


【解决方案1】:

尝试使用这个word press函数来获取page slug,它基本上是页面的名称

<?php echo get_page_template_slug( $post->ID ); ?>

https://codex.wordpress.org/Function_Reference/get_page_template_slug

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-06
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多