Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End make permalink go to a custom single.php file in WordPress

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #148156
    luchid
    Participant

    Hello, hope somebody can help me because I am stuck with this.
    So, I want to use two single.php, one to display posts and another to display some work samples images. I created the second single.php and named it with the category id like single-21.php, but when clicking to the work sample image, it links to the default single.php. Is there a way to link it to the custom single.php using permalinks?
    Thank you very much!

    #148215
    luchid
    Participant

    Hello all, I solved a part of my problem by adding in my function.php this function:
    add_filter(‘single_template’, create_function(
    ‘$the_template’,
    ‘foreach( (array) get_the_category() as $cat ) {
    if ( file_exists(TEMPLATEPATH . “/single-{$cat->slug}.php”) )
    return TEMPLATEPATH . “/single-{$cat->slug}.php”; }
    return $the_template;’ )
    );
    and naming my second single.php with the slug name, in my case single-portfolio.php. But it is not exactly what I hoped to achieve. I need all my categories to use the new template I created. Can I do that or I have to create a template for each category? Thank you very much!

    #148231
    Alen
    Participant

    I’m not exactly sure what you’re trying to do but shouldn’t you be creating pages and not blog posts. single.php is responsible for displaying specific blog post, if you are adding portfolio page you should be using WordPress admin to create the page, then create the associated template file. So if you named your page portfolio, template responsible for displaying this information would be page-portfolio.php where portfolio is the slug for that page.

    See this also: http://codex.wordpress.org/Template_Hierarchy

    Hope that helps,
    -Alen

    #148244
    luchid
    Participant

    Thanks a lot for replying me, Alen. Instead of pages, I used categories to show work samples (ex. cat 1-Logo, cat 2-Photo&Image Editing, cat 3-Animation, so on…) and from category.php,I needed to link this work samples to a custom single.php.
    I created the template, using that function I mentioned and it works just fine for me, but I need to use that template for all my categories. So, l was asking if it possible to use the same template, or I have to create templates for each category.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.