Products
GG网络技术分享 2025-03-18 16:12 7
I have 22 genres in my movie page that I am designing in Wordpress and with some PHP. Basically rather than me typing out 22 different taxonomy pages e.g. taxonomy-genre-action.php
to taxonomy-genre-western.php
I am going to use a template genre-template
.
genre-template
page e.g. <?php$args = array(
\'post_type\' => \'movies\',
\'orderby\' => \'name\',
\'order\' => \'ASC\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'genre\',
\'field\' => \'slug\',
\'terms\' => \'action\' // [CHANGE HERE]
)
)
);
?>
<h2 style=\"color: white\">action movies</h2> <!-- [CHANGE HERE] -->
Change the \'action\' value to whatever hyperlink to the other 21 genres are.
<a href=\"/wordpress/genre/<?php echo $args[$termCount]; ?>\"><?php echo $args[$termCount]; ?></a>
How would I add the $args[$termcount]
value to the genre-template.php
图片转代码服务由CSDN问答提供
感谢您的意见,我们尽快改进~
功能建议我在电影页面中有22种类型,我在Wordpress中设计并使用一些PHP。 基本上而不是我输入22个不同的分类页面,例如 taxonomy-genre-action.php </ code> to
taxonomy-genre-western.php </ code>我将使用模板
genre-template </ code>。
但是什么 我不明白如何获取超链接的值/目的地来更改 genre-template </ code>页面上的两个值,例如 </ p>
&lt;?php $ args = array(
\'post_type\'=&gt;\'movies\',
\'orderby\'=&gt;\'name\' ,
\'order\'=&gt;\'ASC\',
\'posrs_per_page\'=&gt; -1,
\'tax_query\'=&gt;数组(
数组(
\'taxonomy\'=&gt;\'genre\',
\'field\'=&gt;\'slug\',
\'terms\'=&gt;\'action\'// [CHANGE HERE]
)
)
);
?&gt;
&lt; ; h2 style =“color:white”&gt;动作片&lt; / h2&gt; &lt;! - [CHANGE HERE] - &gt;
</ code> </ pre>
将“action”值更改为指向其他21种类型的超链接。</ p>
&lt; a href =“/ wordpress / genre /&lt;?php echo $ args [$ termCount];?&gt;”&gt;&lt;?php echo $ args [$ termCount] ; ?&gt;&lt; / a&gt; </ code> </ pre>
如何将 $ args [$ termcount] </ code>值添加到类型 -template.php </ code> </ p>
</ div>
网友观点:
So, you want to create a general archive page for your custom taxonomy (genre) terms, right?
I\'ll suggest you read, understand and practice WordPress Template Hierarchy in depth.
If WordPress can\'t find taxonomy-{taxonomy}-{term}.php
then it\'ll fallback to taxonomy-{taxonomy}.php
. So, in your case, you can just create one archive file named taxonomy-genre.php
and you\'ll be good to go.
Also, you don\'t even need to construct a query
in the archive file. WordPress will know that it\'s an archive call and will prepare query
for that term
automatically.
Now, to get the current term\'s data, use get_queried_object();
to your advantage. For example, to get the term name,
get_queried_object()->name;
Demand feedback