Do not edit the Twenty Eleven theme. It is the default WordPress theme and having access to an unedited version of the theme is vital when dealing with a range of site issues. Create a child theme for your changes.
Thread Starter
Tranny
(@tranny)
Oops, I already did some edits to it. Can I still revert it and do the child theme approach?
And when we’re at it – do you know how to add the title tag to the navigation? In single.php the code looks like this:
<span class="nav-previous"><?php previous_post_link( '%link', __( '<span class="meta-nav">←</span> Previous', 'twentyeleven' ) ); ?></span>
<span class="nav-next"><?php next_post_link( '%link', __( 'Next <span class="meta-nav">→</span>', 'twentyeleven' ) ); ?></span>
I really don’t know how to add the title tag there without breaking the whole thing.
Can I still revert it and do the child theme approach?
Absolutely. If you’re not sure if you’ve reverted all of the edits, just re-upload a fresh copy of the Twenty eleven the to wp-content/themes using FTP.
do you know how to add the title tag to the navigation?
It can’t be added via the previous_post_link() or next_post_link() functions but you could just use something like:
<span class="nav-previous" title="Previous post">[...]
<span class="nav-next" title="Next post">[...]
Thread Starter
Tranny
(@tranny)
I forgot to mention – I’d like these tags to be dynamic, so they display the title of the post they link to. Would you know what to replace the text between the double quotes with to have the text added there dynamically based on what the post they link to is about?
Thank you so much for your help, either way.
Have you reviewed:
http://codex.wordpress.org/Template_Tags/previous_post_link
http://codex.wordpress.org/Template_Tags/next_post_link
Perhaps there something in there that would suit your needs. Determining the next & previous post titles by code would probably mean at least 2 secondary loops.
Thread Starter
Tranny
(@tranny)
After checking both those pages, it would seem as though the twenty eleven developers thought of many things, except from title tags. I don’t think the way to achieve it lead through there. What you suggested before seems more viable, if there only was some way to echo the title dynamically. I wish I had more PHP experience to figure it out myself 🙁
Thread Starter
Tranny
(@tranny)
This sounds like it could be a solution, unfortunately this command doesn’t work. Hopefully the developers can fix it so it works in the next update:
http://codex.wordpress.org/Function_Reference/get_adjacent_post
What problem did you have with that function?
Thread Starter
Tranny
(@tranny)
First I wanted to try whether calling a dynamic value between title double quotes would work, and it did:
<span class="nav-previous" title="<?php the_title(); ?>">
But this unsurprisingly calls the title of current post. SO I tried the get_adjacent_post tag, but it does absolutely nothing:
<span class="nav-previous" title="<?php get_adjacent_post($previous); ?>">
No – you need more code yet. something like:
<?php // Get next post title
$adjacent_post = get_adjacent_post(false,'',false);
$next_post = get_post( $adjacent_post->ID );
$next_post_title = $next_post->post_title;
// Get previous post title
$in_same_cat = false;
$excluded_categories = '';
$previous = true;
$previous_post = get_adjacent_post($in_same_cat,$excluded_categories,$previous);
$previous_post_title = $previous_post->post_title;
?>
Then you can use <?php echo $next_post_title;?>
and <?php echo $previous_post_title;?>
in the title attribute of your span tags.
But do bear in mind that I’m writing this off the top of my head, so it’s not tested.
Thread Starter
Tranny
(@tranny)
Where exactly do I add this code?
You could add it to your theme’s single.php file – just before these previous & next post code.