0

I have created a nice homepage where the posts are organized into two columns. Only somehow, in creating this, I must have erased the actual code that tells the posts to link to the corresponding post. So right now, the posts are all showing up on the homepage, but there is no way to go to the post - the post previews are unlinked to the actual posts.

I looked around some first, thinking this might be a common issue, but I haven't found the answer yet. If anyone can assist, i would greatly appreciate it!

The site is at internalcompass.us/castle. It's a twentytwelve child theme.

here is the code i have in content.php

    <?php
    /**
     * The default template for displaying content. Used for both single and     index/archive/search.
 *
 * @package WordPress
 * @subpackage Twenty_Twelve
 * @since Twenty Twelve 1.0
 */
?>

        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <?php if ( is_sticky() && is_home() && ! is_paged() ) : ?>
                <div class="featured-post">
                        <?php _e( 'Featured post', 'twentytwelve' ); ?>
                </div>
                <?php endif; ?>
                <header class="entry-header">
                        <?php the_post_thumbnail(); ?>
                        <?php if ( is_single() ) : ?>
                        <h1 class="entry-title"><?php the_title(); ?></h1>
                        <?php else : ?>
                        <h1 class="entry-title">
                                </a> <h1 class="entry-title"><?php the_title(); ?><br><small class="time"><?php the_date('F j, Y'); ?></small></h1>
                        </h1>
                        <?php endif; // is_single() ?>
                </header><!-- .entry-header -->

                        <?php edit_post_link( __( 'Edit', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?>
                        <?php if ( is_singular() && get_the_author_meta( 'description' ) && is_multi_author() ) : // If a user has filled out their description and this is a multi-author blog, show a bio on their entries. ?>
                                <div class="author-info">
                                        <div class="author-avatar">
                                                <?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'twentytwelve_author_bio_avatar_size', 68 ) ); ?>
                                        </div><!-- .author-avatar -->
                                        <div class="author-description">
                                                <h2><?php printf( __( 'About %s', 'twentytwelve' ), get_the_author() ); ?></h2>
                                                <p><?php the_author_meta( 'description' ); ?></p>
                                                <div class="author-link">
                                                        <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
                                                                <?php printf( __( 'View all posts by %s <span class="meta-nav">&rarr;</span>', 'twentytwelve' ), get_the_author() ); ?>
                                                        </a>
                                                </div><!-- .author-link -->
                                        </div><!-- .author-description -->
                                </div><!-- .author-info -->
                        <?php endif; ?>
        </article><!-- #post -->

2 Answers 2

0

If you want that the featured image is clickable replace:

<?php the_post_thumbnail(); ?>

with

<a href="<?php the_permalink(); ?>" rel="bookmark"><?php <?php the_post_thumbnail(); ?></a>

For the title and date replace this:

<h1 class="entry-title"><?php the_title(); ?><br><small class="time"><?php the_date('F j, Y'); ?></small></h1>

whit this:

<a href="<?php the_permalink(); ?>" rel="bookmark"><h1 class="entry-title"><?php the_title(); ?><br><small class="time"><?php the_date('F j, Y'); ?></small></h1></a>

Remove that </a> at the beginning of the row, is useless.

1

I don't know that this is 100% answerable without seeing your code, but in TwentyTwelve the links, at least in one place, look like this:

<h1 class="entry-title">
    <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
</h1>

The key function is the_permalink(), which echos the link URL. The rest is standard HTML.

Edit:

Now that you have posted your code, I can see what is happening. You simply have no anchor tags (though you have spurious </a>) around your titles.

 <?php if ( is_single() ) : ?>
                    <h1 class="entry-title"><?php the_title(); ?></h1>
                    <?php else : ?>
                    <h1 class="entry-title">
                            </a> <h1 class="entry-title"><?php the_title(); ?><br><small class="time"><?php the_date('F j, Y'); ?></small></h1>
                    </h1>
                    <?php endif; // is_single() ?>

What you would need is this:

if ( is_single() ) { ?>
  <h1 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h1>
} else { ?>
  <h1 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a><br><small class="time"><?php the_date('F j, Y'); ?></small></h1><?php 
} // is_single() ?>

The only significant change is on the <h1 lines but you had nested <h1> so I corrected that and I converted the alternate syntax-- if (...) : endif;-- to brackets because I find that alternate syntax impossible to read and prone to error probably because it seems to encourage poorly indented code, but you can keep that hard to read prone to error syntax if you like. :)

2
  • thank you. yes, that is the right track. i just don't know how to combine it with what i have. if i paste that exactly, it shows two titles, and only one of them is linked, and if i use only your code, i lose the dates, which i need to display. i tried to just add the permalink part to the entry-title code i have already in content.php, but that didn't work. how can i combine the code above with what i have? thank you!
    – kelly
    Commented Jul 29, 2013 at 14:42
  • Do no replace whole line but only the <?php the_title(); ?> with <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a> I am also seeing misplaced tags atleast </a> in else part of if(is_single())
    – M-R
    Commented Jul 29, 2013 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.