我不会撒谎——我不懂php,但我喜欢四处挖掘,试图找到自定义主题的方法,以便它们按照我的意愿行事。任何帮助都将不胜感激。
我想做的是:
我使用的wordpress主题中有一个部分,允许您发布公文包。
任何公文包页面的URL都是:
mysite.com/portfolio/example-portfolio
创建新的公文包时,您可以选择分配公文包类别,这与创建新帖子时的方式非常相似。
我希望能够使我的投资组合URL如下所示:
mysite.com/portfolio-category/example-portfolio
我已经强调了一个我怀疑可以编辑的代码区域,以实现这一点,但这就是我的冒险可悲的结局:(
代码如下:
function mysite_post_types() {
register_post_type(\'portfolio\', array(
\'labels\' => array(
\'name\' => _x(\'Portfolios\', \'post type general name\', MYSITE_ADMIN_TEXTDOMAIN ),
\'singular_name\' => _x(\'Portfolio\', \'post type singular name\', MYSITE_ADMIN_TEXTDOMAIN ),
\'add_new\' => _x(\'Add New\', \'portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'add_new_item\' => __(\'Add New Portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'edit_item\' => __(\'Edit Portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'new_item\' => __(\'New Portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'view_item\' => __(\'View Portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'search_items\' => __(\'Search Portfolios\', MYSITE_ADMIN_TEXTDOMAIN ),
\'not_found\' => __(\'No portfolios found\', MYSITE_ADMIN_TEXTDOMAIN ),
\'not_found_in_trash\' => __(\'No portfolios found in Trash\', MYSITE_ADMIN_TEXTDOMAIN ),
\'parent_item_colon\' => \'\'
),
\'singular_label\' => __(\'Portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'public\' => true,
\'exclude_from_search\' => false,
\'show_ui\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'rewrite\' => array( \'with_front\' => false, \'slug\' => \'products\' ),
我已经找到了改变“我的网站”的方法。com公司/
portfolio/示例公文包“到”mysite。com公司/
products/示例公文包”(在示例的最后一行),但我不想就此止步!
由于您可以对公文包进行分类,我想在生成的URL中利用这一点。
这当然是可能的,不需要太多的工作,如果有人比我有更多的php知识,我将非常感激(这不需要太多!)可以让我依靠他们找到解决方案
谢谢
SO网友:Josh
添加
\'rewrite\' => array(\'slug\' => \'portfolio-categories\'),
但一定要删除(不知道为什么会这样,它试图隐藏slug,但同时试图将其重命名为“products”):
\'rewrite\' => array( \'with_front\' => false, \'slug\' => \'products\' ),
看起来是这样的:
function mysite_post_types() {
register_post_type(\'portfolio\', array(
\'labels\' => array(
\'name\' => _x(\'Portfolios\', \'post type general name\', MYSITE_ADMIN_TEXTDOMAIN ),
\'singular_name\' => _x(\'Portfolio\', \'post type singular name\', MYSITE_ADMIN_TEXTDOMAIN ),
\'add_new\' => _x(\'Add New\', \'portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'add_new_item\' => __(\'Add New Portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'edit_item\' => __(\'Edit Portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'new_item\' => __(\'New Portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'view_item\' => __(\'View Portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'search_items\' => __(\'Search Portfolios\', MYSITE_ADMIN_TEXTDOMAIN ),
\'not_found\' => __(\'No portfolios found\', MYSITE_ADMIN_TEXTDOMAIN ),
\'not_found_in_trash\' => __(\'No portfolios found in Trash\', MYSITE_ADMIN_TEXTDOMAIN ),
\'parent_item_colon\' => \'\'
),
\'singular_label\' => __(\'Portfolio\', MYSITE_ADMIN_TEXTDOMAIN ),
\'public\' => true,
\'exclude_from_search\' => false,
\'show_ui\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'rewrite\' => array(\'slug\' => \'portfolio-categories\')
)
);
只要确保register\\u post\\u类型正确关闭,您发布的代码就会在数组的中间结束。我帮你合上了,但我不确定你是否遗漏了什么。这里有一些例子:
http://codex.wordpress.org/Function_Reference/register_post_type