最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

friendly url - Xenforo custom topic URLs - Stack Overflow

programmeradmin3浏览0评论

I want to change topics urls in xenforo to this format example/f8/tapatalk-2/

8 is Id forums, and 2 is topic id

i create an addon "CustomThreadRoute" my addon.json codes is:

{
    "title": "Custom Thread Route",
    "version_id": 1000000,
    "version_string": "1.0.0",
    "dev": "Your Name",
    "dev_url": ";,
    "description": "A custom listener to change thread URLs",
    "actions": [
        {
            "action": "XF\AddOn\AbstractAddOn::install",
            "execute_order": 10
        }
    ],
    "listeners": [
        {
            "event": "router_public",
            "action": "CustomThreadRoute\Listener::routerPublic"
        },
        {
            "event": "router.build_link",
            "action": "CustomThreadRoute\Listener::generateUrl"
        }
    ]
}

and Listener.php is

<?php

namespace CustomThreadRoute;

use XF\Mvc\RouteBuiltLink;
use XF\Mvc\Router;

class Listener
{
    // اصلاح مسیرها
    public static function routerPublic(Router $router, array &$routes)
    {
        $routes['custom-route/{thread_id}-{title}'] = 'threads/view';
    }

    // تولید لینکهای جدید
    public static function generateUrl(RouteBuiltLink $link, $route, array &$data, array &$parameters)
    {
        if ($route === 'threads' && isset($data['thread_id'])) {
            $link->route = 'custom-route';
            $link->params = [
                'thread_id' => $data['thread_id'],
                'title' => $data['title']
            ];
        }
    }
}

also i add code event listener

enter image description here

but not working and urls not change why?

i try to create an addon for custom urls

发布评论

评论列表(0)

  1. 暂无评论