- This topic is empty.
-
AuthorPosts
-
August 26, 2013 at 7:14 am #148156
luchid
ParticipantHello, 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!August 27, 2013 at 5:25 am #148215luchid
ParticipantHello 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!August 27, 2013 at 8:46 am #148231Alen
ParticipantI’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 pageportfolio
, template responsible for displaying this information would bepage-portfolio.php
whereportfolio
is the slug for that page.See this also: http://codex.wordpress.org/Template_Hierarchy
Hope that helps,
-AlenAugust 27, 2013 at 10:20 am #148244luchid
ParticipantThanks 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. -
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.