Skip to:
Content
Pages
Categories
Search
Top
Bottom

Can I add custom permalink option


  • jomontvm
    Member

    @jomontvm

    I would like to have separate categories for forums in English and Arabic with slug ‘en’ and ‘ar’ respectively. Also I want to create forums with corresponding language under these categories.

    I would like to have my fourm URLs look as follows.

    mysite.com/fourm/ar/forum-arabic-1

    mysite.com/fourm/ar/forum-arabic-2

    mysite.com/fourm/en/forum-english-1

    mysite.com/fourm/en/forum-english-2

    I tried changing the permalink option to “name based”, but gives the URLs as follows.

    mysite.com/forum/forum/forum-arabic-1

    mysite.com/forum/forum/forum-arabic-2

    Is there any way to get the URLs as I mentioned above?

    Or is there any way to add a custom permalink option so as to get the permalink in the below format?

    mysite.com/forum/[category_slug]/[forum_slug]

    Thanks in advance

Viewing 4 replies - 1 through 4 (of 4 total)

  • Pagal
    Member

    @pagal

    I’m also searching the same solution!!!

    anybody wants to help us?


    jomontvm
    Member

    @jomontvm

    Hi Pagal,

    I have customized the permalink for bbpress, and it works fine. It’s still on the testing stage, though you can try this. The following is the modifications I have done.

    Step 1:


    Open ‘bb-admin/options-permalinks.php’

    You will find a permalink options declaration. Add one more option as shown below, it will add one more option in the permalink options in the backend. You can make the custom option with a text field, in order to customize in your own way (I have done in a predefined format in order to make it simple).


    $permalink_options = array(
    'mod_rewrite' => array(
    'title' => __( 'Permalink type' ),
    'type' => 'radio',
    'options' => array(
    '0' => sprintf( __( '<span>None</span> %s' ), bb_get_uri( 'forum.php', array( 'id' => 1 ), BB_URI_CONTEXT_TEXT ) ),
    '1' => sprintf( __( '<span>Numeric</span> %s' ), bb_get_uri( 'forum/1', null, BB_URI_CONTEXT_TEXT ) ),
    'slugs' => sprintf( __( '<span>Name based</span> %s' ), bb_get_uri( '/forum/first-forum', null, BB_URI_CONTEXT_TEXT ) ),
    'custom' => sprintf( __( '<span>Custom</span> %s' ), bb_get_uri( '/forum/%parent_slug%/%forum_slug%', null, BB_URI_CONTEXT_TEXT ))
    )
    )
    );

    Step 2:


    Now we have to create the custom format of permalinks for forums and topics.

    Open ‘bb-includes/functions.bb-template.php’

    We have to modify two functions ‘get_forum_link’ and ‘get_topic_link’. See the changes I have done for the custom permalink option.


    function get_forum_link( $forum_id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) {
    $forum = bb_get_forum( get_forum_id( $forum_id ) );

    if (!$context || !is_integer($context)) {
    $context = BB_URI_CONTEXT_A_HREF;
    }

    $rewrite = bb_get_option( 'mod_rewrite' );

    if ( $rewrite ) {
    $page = (1 < $page) ? '/page/' . $page : '';
    if ($rewrite === 'custom') {
    if ($forum->forum_parent > 0) {
    $parent = bb_get_forum($forum->forum_parent);
    $parent_slug = $parent->forum_slug;
    $custom_link = $parent_slug . '/' . $forum->forum_slug;
    } else {
    $custom_link = $forum->forum_slug;
    }
    $link = bb_get_uri('forum/' . $custom_link . $page, null, $context);
    } else {
    if ( $rewrite === 'slugs' ) {
    $column = 'forum_slug';
    } else {
    $column = 'forum_id';
    }
    $link = bb_get_uri('forum/' . $forum->$column . $page, null, $context);
    }
    } else {
    $query = array(
    'id' => $forum->forum_id,
    'page' => (1 < $page) ? $page : false
    );
    $link = bb_get_uri('forum.php', $query, $context);
    }

    return apply_filters( 'get_forum_link', $link, $forum->forum_id, $context );
    }

    function get_topic_link( $id = 0, $page = 1, $context = BB_URI_CONTEXT_A_HREF ) {
    $topic = get_topic( get_topic_id( $id ) );
    if (!$context || !is_integer($context)) {
    $context = BB_URI_CONTEXT_A_HREF;
    }

    $args = array();

    $rewrite = bb_get_option( 'mod_rewrite' );
    if ( $rewrite ) {
    $page = (1 < $page) ? '/page/' . $page : '';
    if ($rewrite === 'custom') {
    $custom_link = '';
    if ($topic->forum_id > 0) {
    $forum = bb_get_forum($topic->forum_id);
    if ($forum->forum_parent > 0) {
    $parent = bb_get_forum($forum->forum_parent);
    $custom_link = $parent->forum_slug;
    }
    $custom_link .= '/' . $forum->forum_slug;
    }
    if (!empty($custom_link)) {
    $custom_link .= '/topic/' . $topic->topic_slug;
    } else {
    $custom_link .= 'topic/' . $topic->topic_slug;
    }
    $link = bb_get_uri($custom_link . $page, null, $context);
    } else {
    if ( $rewrite === 'slugs' ) {
    $column = 'topic_slug';
    } else {
    $column = 'topic_id';
    }
    $link = bb_get_uri('topic/' . $topic->$column . $page, null, $context);
    }
    } else {
    $page = (1 < $page) ? $page : false;
    $link = bb_get_uri('topic.php', array('id' => $topic->topic_id, 'page' => $page), $context);
    }

    return apply_filters( 'get_topic_link', $link, $topic->topic_id, $context );
    }

    Step 3:


    Now we have to define the htaccess rules.

    Open ‘.htaccess’ file in bbpress root folder, and add following two lines just above the code line – RewriteRule ^topic/?$ /forums/ [R=302,L,QSA].


    RewriteRule ^(.+)/topic/(.+) /forums/topic.php?id=$2 [L,QSA]
    RewriteRule ^forum/(.+)/(.+) /forums/forum/$2/ [L,QSA]

    Here is how my URLs looks after making these modifications:

    Forum URL: mysite.com/forums/forum/en/first-forum-in-english

    Topic URL: mysite.com/forums/en/first-forum-in-english/topic/the-ipad-developers-challenge


    Pagal
    Member

    @pagal

    @ jomontvm thank you so much…

    I’ll try it soon and tell you what happened…

    Thanks again.. :)


    Ulrik Hvide
    Member

    @ulrik-hvide

    jomontvm said what I wanted to say, bahh next time I better read the other replies before writing one myself. Anyway, follow jomontvm’s instructions and you dont have to risk duplicate content problems.

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.