简体   繁体   English

显示帖子仅形成与当前页面同名的类别

[英]Displaying posts only form a category that has same name as the current page

My theme supports different post types - one of those is portfolio posts. 我的主题支持不同的帖子类型-其中之一就是投资组合帖子。 I'm trying to display portfolio posts on a page but only from one specific category - the one that has the same name as the current page. 我正在尝试在页面上显示投资组合帖子,但只能显示一个特定类别-与当前页面同名的类别。

Example: 例:
I have portfolio posts in categories: red, green, blue. 我有以下类别的投资组合职位:红色,绿色,蓝色。
I have pages named: red, green, blue. 我的页面名为:红色,绿色,蓝色。 Now I would like to display on page "red" only post from category "red". 现在,我只想在“红色”页面上显示“红色”类别的帖子。

I'm very new to wordpress and making websites in general. 我刚接触Wordpress和制作网站时非常陌生。

I tried to read a bit about it and found a way to display posts from certain category only: 我尝试阅读一些有关此内容的信息,发现了一种仅显示特定类别帖子的方法:

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

From there I tried to do this but it doesn't work: 从那里,我试图这样做,但是没有用:

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

Here is full code of the page template I'm talking about: http://pastebin.com/LxetTnUz 这是我正在谈论的页面模板的完整代码: http : //pastebin.com/LxetTnUz

Try to use this word press function get the page slug which is basically name of the page 尝试使用此单词按下功能获取页面信息,基本上是页面名称

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

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

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

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