Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

My work.php file redirects me to single.php instead of single-work.php

Hi, I'm following How to build a wordpress theme and since I want to make my own Wordpress site I customized it more to me.

My problem is this:

When I click on a single project from my work.php, Wordpress redirects me to single.php instead of single-work.php.

Dose anyone have a solution for my problem?

Here is the code:

work.php

<?php
/*
    Template Name: Work Page
*/
?>

<?php get_header(); ?>

            <div class="row main-content container">
                <h1>Þetta er work.php</h1>

                <?php
                    $args = array(
                        'post_type' => 'verkefnin'
                    );
                    $the_query = new WP_Query($args);
                ?>

                <?php if(have_posts()) : while ($the_query->have_posts()) : $the_query->the_post(); ?>

                        <div class="project-container" data-link="<?php the_permalink(); ?>">
                            <h3>
                                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            </h3>
                            <p>Vefsíða</p>
                            <div class="project-overlay">
                                <div class="overlay">
                                    <a class="more" href="<?php the_permalink(); ?>">Skoða verk</a>
                                </div>
                                <img src="<?php the_field('image'); ?>">
                            </div>
                        </div>

                <?php endwhile; else: ?>

                    <p>There are no posts or pages here</p>

                <?php endif; ?>

            </div>

<?php get_footer(); ?>

single-work.php

<?php get_header(); ?>

            <div class="row main-content">
                <h1>Þetta er single-work.php</h1>

                <?php if(have_posts()) : while (have_posts()) : the_post(); ?>

                    <h3><?php the_title(); ?></h3>
                    <?php the_field('description'); ?>
                    <hr>

                <?php endwhile; else: ?>

                    <p>There are no posts or pages here</p>

                <?php endif; ?>

            </div>

<?php get_footer(); ?>

I hope this is enough to make some sence Best regards: Bergur Ingi

1 Answer

Shaker Advertising
Shaker Advertising
5,395 Points

So you've set up your custom post type to be 'verkefnin' correct?

If that's the case you need to rename single-work.php to single-verkefnin.php in order to have Wordpress understand that this is the single post template for that specific post type.

Check out the codex for custom post type template: http://codex.wordpress.org/Post_Type_Templates

Thanks, that did the job :)