In the blog I have created, there is an edit link at the bottom of each post when you look at the live site whilst logged in as admin.
Website client looking for a way to have that edit link on the 'blogroll' homepage so that it appears underneath each blog post excerpt.
I've looked all over google for an answer but can't find anything. I don't even think it's possible given what I understand about Wordpress codex conditional logic.
Can someone please let me know if it is possible or not and how to approach this problem?
==Update==
Ok with Tim's guidance, I located the content.php where the excerpt logic was being produced for the blog roll. Inserted Tim's proposed code like so:
<?php if ( true == generate_show_excerpt() ) : ?>
<div class="entry-summary" itemprop="text">
<?php the_excerpt(); ?>
<?php
if(is_user_logged_in() && current_user_can("edit_post", get_the_ID())){
edit_post_link("Edit this post");
}
?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content" itemprop="text">
<?php the_content(); ?>
<?php
wp_link_pages( array(
'before' => '<div class="page-links">' . __( 'Pages:', 'generate' ),
'after' => '</div>',
) );
?>
</div><!-- .entry-content -->
<?php endif; ?>
Just had to make sure it was wrapped in a PHP function call ( i.e. ). Seems to work the treat.
I don't even think it's possible given what I understand about Wordpress codex conditional logic.
It most definitely is possible! :)
In your theme, you'll have most likely a home.php
, archive.php
or index.php
file that is running through a loop of your posts. In that file, there'll be code that looks like this:
while(have_posts()): the_post();
// lots of code here to display your post data
endwhile;
You'll need to locate directly where to put this, but somewhere in that while loop will be your excerpts (most likely looking like get_the_excerpt();
or similar). After that, you can place the edit_post_link()
function.
Wrapped in a condition to check that a user is logged in and has permission to view the post, this will print out the 'edit post' link you are looking for:
if(is_user_logged_in() && current_user_can("edit_post", get_the_ID())){
edit_post_link("Edit this post");
}
Where exactly you place this depends on your theme and how it is constructed, but with a bit of looking around hopefully you will be able to locate it. Feel free to edit your question and place in the portion of code you are trying to edit if its not working for you.
If you're using a main theme with a child theme, then you should look for the relevant portion of code in your main theme, and copy the file into your child theme to make changes.