【问题标题】:How to add query string/params to url in WordPress?如何在 WordPress 中向 url 添加查询字符串/参数?
【发布时间】:2016-04-16 12:45:10
【问题描述】:

我创建了一个自定义页面模板,其中列出了“分类”中的帖子。

当您单击帖子时,我希望将分类法和术语作为查询字符串作为 url 中的参数传递,以便我可以在单个帖子页面上获取分类法。

感谢任何帮助。

谢谢

【问题讨论】:

标签: javascript php jquery html wordpress


【解决方案1】:

你可以使用add_query_arg,这里是the example。希望对你有帮助

【讨论】:

  • 嗨@Duc Doan,感谢您的建议。我将研究 add_query_arg 示例
【解决方案2】:

我使用以下代码将该值作为查询字符串传递给分类中的标题:

<?php
  $theTaxonomy = get_taxonomy( get_query_var( 'taxonomy' ) ); 
  $getTaxonomy = $the_tax->labels->name;

  function to_slug($string){
      return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
  }

  $getTaxonomy;
  $getTaxonomySlug = to_slug($getTaxonomy);
  $getPermalink = esc_url(get_permalink());
  $taxonomyUrl = '?'.'type'.'='.$getTaxonomySlug;
?>

<a href="<?php echo $getPermalink.$taxonomyUrl ?>"></a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-01
    • 2021-12-24
    • 2015-02-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多