WordPress WordPress Theme Development Custom Post Type Templates in WordPress The Portfolio Homepage

Daniel Hernandez
Daniel Hernandez
13,436 Points

My images link me back to my homepage although the link in the url bar is correct

I am working on the create custom wordpress theme and I have run into this problem and don't know how to solve it. It could be because I didn't put the WordPress loop at my homepage. I don't know what could be the problem. My featured images take me back to my index page although the url is correct in the url bar. It appears that my site is just using the index.html page as for what is to show for the custom post type. Why would this be? I have a feeling it is an easy fix but I don't know what to do.

Here is my code.

My functions page

<?php

add_theme_support('menus');
add_theme_support('post-thumbnails');

function namespace_register_menus() {
    register_nav_menus(
        array(
            'primary-menu'  => __( 'Primary Menu')
        )
    );
}

add_action( 'init', 'namespace_register_menus' );


function wpt_theme_styles() {

    wp_enqueue_style( 'googlefont_css', 'https://fonts.googleapis.com/css?family=Roboto'
      );
      wp_enqueue_style( 'style', get_stylesheet_directory_uri() . '/style.css');

}




add_action('wp_enqueue_scripts','wpt_theme_styles');

 ?>

My index page

<?php  get_header(); ?>

<!--    jumbotron image-->
<header class="jumbotron jtron img-fluid">

    </header>

<!--    main container-->
    <button type="button" class="btn btn-info wide-btn">Click here for a free quote</button>

    <div class="container-fluid">


<!--        1st sub container-->
        <div class="container mb-4">
        <p class="pg1">DV Electric is a family-owned company from the Bay-Area that serves the electrical needs of the local community.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. </p>

        <button type="button" class="btn btn-info abt-btn ">About Page</button>


    </div>

<?php get_footer(); ?>

My portfolio page

<?php
/*
  Template Name:Project Page
*/

?>

<?php
    get_header();
?>


<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
        <h1><?php the_title(); ?></h1>
        <?php the_content(); ?>
    <?php endwhile; endif; ?>

  <?php
      $args = array(
        'post_type' => 'portfolio'
      );
      $query = new WP_Query($args);
    ?>


    <section class="row">
      <?php  if($query->have_posts()) : while($query->have_posts()) : $query->the_post(); ?>
        <div class="col">
          <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('medium'); ?></a>
        </div>
      <?php endwhile; endif; wp_reset_postdata(); ?>
    </section>


 <?php
    get_footer();
 ?>

I can include the header and the footer too but I think the problem is being caused by one of the above mentioned pages. Thanks in advance for the support!

2 Answers

Daniel Hernandez
Daniel Hernandez
13,436 Points

So I put the wordpress loop at the index.php page and now it appears to be working although it is still using the content from the index.php page. I didn't expect it to be predicated upon index.php's page data. I was making a wordpress theme for someone else and I wanted the index page to be free from any post data. I suppose I'll have to just make another page and set that as the home page and then use this index.php page as the basis for my projects page. I still cannot see the featured image in the post, the page definitely looks different in the video than what I have, so if anyone can still chime in, that would still be appreciated.

Daniel Hernandez
Daniel Hernandez
13,436 Points

I suppose teacher had built those new pages in the next video. Sorry for the dummy post!