【问题标题】:WordPress Custom Post Type Event with custom permalink structure具有自定义永久链接结构的 WordPress 自定义帖子类型事件
【发布时间】:2012-08-01 20:42:28
【问题描述】:

我需要一些关于自定义帖子类型的自定义永久链接的帮助。

我创建了一个名为“evento”的自定义帖子类型和 3 个自定义字段,用于存储事件的日期、月份和年份。

我想要一个这样的永久链接结构:

/eventos/2012/07/30

...标准结构是:

/?post_type=evento&ano=2012&mes=07&dia=30

如何在 WordPress 中实现这种魔力?我不太了解.Htaccess =(

提前致谢!!!

【问题讨论】:

    标签: events permalinks custom-post-type


    【解决方案1】:

    这应该做你想做的:

    重写规则 ^eventos/([0-9]+)/([0-9]+)/([0-9]+)$ /?post_type=evento&ano=$1&mes=$2&dia=$3 [L]

    我使用http://htaccess.madewithlove.be/对其进行了测试

    祝你好运。

    【讨论】:

      【解决方案2】:

      问题解决了!!!! =)

      add_action('init', 'evento_add_rewrite_rules');
      function evento_add_rewrite_rules( $wp_rewrite ){
          // Add day archive (and pagination)
          add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]&dia=$matches[3]&paged=$matches[4]','top');
          add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/([0-9]{2})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]&dia=$matches[3]','top');
      
          // Add month archive (and pagination)
          add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]&paged=$matches[3]','top');
          add_rewrite_rule("eventos/([0-9]{4})/([0-9]{2})/?",'index.php?post_type=evento&ano=$matches[1]&mes=$matches[2]','top');
      
          // Add year archive (and pagination)
          add_rewrite_rule("eventos/([0-9]{4})/page/?([0-9]{1,})/?",'index.php?post_type=evento&ano=$matches[1]&paged=$matches[2]','top');
          add_rewrite_rule("eventos/([0-9]{4})/?",'index.php?post_type=evento&ano=$matches[1]','top');
      }
      

      谢谢!

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-06-10
        • 2012-05-05
        • 1970-01-01
        • 2018-10-21
        • 2012-06-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多