Wordpress:页面使用类别模板

时间:2012-02-14 23:16:40

标签: wordpress wordpress-theming

我有一个“投资组合”页面。是否可以使用标准的类别模板? (category.php)

如果没有,反过来怎么样?我可以制作一个自定义模板(投资组合页面将使用)并使所有类别请求也在那里吗?

澄清一下:Portfolio页面显示与Category页面相同的内容。但它需要在投资组合的标题下。他们都会显示类别。有没有办法将这些结合起来但保持“投资组合”页面的参与?

2 个答案:

答案 0 :(得分:0)

是的,您可以使用自定义模板。并将该模板分配给投资组合页面。

并在该模板中显示类别后循环。

网址创建模板: - http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates

使用查询帖子循环,您可以显示该投资组合类别的显示帖子。

网址: - http://codex.wordpress.org/Function_Reference/query_posts

答案 1 :(得分:0)

如果您想将您的投资组合页面重定向到特定类别(如上面评论中所述),那么您只需在functions.php中添加一个钩子,如

function redirect_to_category()
{
    //I assumed that your page slug is portfolio,id or page title can be used too
    if(is_page('portfolio'))
    {
        $page_url = "your category url"; //i.e. http://yourdomain/category/anitem
        wp_redirect($page_url);  // you can also redirect to any page/category   
    }
}

add_action('template_redirect', 'redirect_to_category');

如果您将此代码粘贴到functions.php中,这将导致您的用户根据您的is_page返回值重定向到给定类别(在$ page_url变量中)页面。有关自定义模板的详情,请访问http://codex.wordpress.org/Theme_Development#Custom_Page_Templates

相关问题