1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.4 "Create Pages for Categories" option for certain categories only

Discussion in 'XenForo Questions and Support' started by WearableTechForums.com, Nov 16, 2014.

  1. Is it possible to enable the "Create Pages for Categories" option for certain categories only, somehow?
     
  2. Brogan

    Brogan XenForo Moderator Staff Member

    No, it's a global setting.
     
  3. Is there a creative way to do this in another way? For example, I tried using route filters to undo the category page link for the categories I didn't want pages for, although the route filter added a / on the end of my redirects and so it was an imperfect fix. Another way might be to remove the link functionality with a template edit.
     
  4. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

    This should be possible with an addon that extends the category route handler.

    Or you can hack it with a file edit.

    Untested, but it should work:

    library/XenForo/Route/Prefix/Categories.php

    Add the red code, and specify the list of node_ids in blue (ids which will have their own pages):

    Code:
    	/**
    	 * Method to build a link to the specified page/action with the provided
    	 * data and params.
    	 *
    	 * @see XenForo_Route_BuilderInterface
    	 */
    	public function buildLink($originalPrefix, $outputPrefix, $action, $extension, $data, array &$extraParams)
    	{
    		// for situations such as an array with thread and node info
    		if (isset($data['node_title']))
    		{
    			$data['title'] = $data['node_title'];
    		}
    
    		if ($data && isset($data['node_id']) && $data['depth'] === 0)
    		{
    			if (!XenForo_Application::get('options')->categoryOwnPage AND !in_array($data['node_id'], array(1,2,3)))
    			{
    				$prefix = XenForo_Link::buildPublicLink('forums', null, $extraParams);
    				$extraParams = array();
    				return new XenForo_Link(
    					$prefix . '#' . XenForo_Link::buildIntegerAndTitleUrlComponent($data['node_id'], $data['title'], true)
    				);
    			}
    		}
    
    		return XenForo_Link::buildBasicLinkWithIntegerParam($outputPrefix, $action, $extension, $data, 'node_id', 'title');
    	}
    
    But a file edit will be overwritten when you upgrade XF.
     
  5. Awesome. I will try it. Thank you!
     
  6. Jake, how hard is it to convert this into add-on form, so that it is not overwritten with an update?
     
  7. Jake Bunce

    Jake Bunce XenForo Moderator Staff Member

  8. RichardKYA

    RichardKYA Well-Known Member

    Did this add-on get created in the end?
     

Share This Page