douyi3833 2017-07-15 01:43
浏览 51
已采纳

在wordpress中向模板添加值

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. But what I don't understand is how do I get the value/destination of a hyperlink to change two values on the 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

  • 写回答

1条回答 默认 最新

  • doushenyi9104 2017-07-15 03:44
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码