I think CSS would work fine.
I’m interested in others answers on this one.
you will need to add html and css classes to the code in the loop, using a conditional to add a distinct css class to published posts only, then style this with css.
review
http://codex.wordpress.org/Function_Reference/get_post_status
http://codex.wordpress.org/The_Loop
http://codex.wordpress.org/Class_Reference/WP_Query
for any more detailed suggestions, please post the full code of the query with its loop.
Thanks alchymyth i know i have to add html & CSS but i dont know where to put it and i need it to be dynamic so a different style for each different post status
heres full code
<?php
/* Template Name: View Posts */
if ( !current_user_can('publish_posts')) {
include('reject-view-posts.php');
exit(0);
}
?>
<?php get_header(); ?>
<?php
$query = new WP_Query( array(
'post_type' => 'post',
'posts_per_page' => '-1',
'post_status' => array(
'publish',
'pending',
'draft',
'private',
)
) );
?>
<div id="content">
<div id="inner-content" class="wrap clearfix">
<table id="view-posts-table">
<tr id="view-posts-table-top">
<th width="25%" >Post Title</th>
<th width="35%">Post Excerpt</th>
<th width="15%">Post Status</th>
<th width="15%">Actions</th>
</tr>
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<tr>
<td class="insert-posts-title"><?php echo get_the_title(); ?></td>
<td><?php echo substr(get_the_excerpt(), 0,170); ?></td>
<td><?php echo '<div id="posts-status">' . get_post_status( get_the_ID() )?></td>
<td><?php $edit_post = add_query_arg( 'post', get_the_ID(), get_permalink( 74 + $_POST['_wp_http_referer'] ) ); ?>
<a href="<?php echo $edit_post; ?>">Edit</a> <?php if( !(get_post_status() == 'trash') ) : ?>
<a class="confirm-dialog" href="<?php echo get_delete_post_link( get_the_ID() ); ?>">Delete</a>
<?php endif; ?></td>
</tr>
<?php endwhile; endif; ?>
</table>
</div>
</div>
<?php get_footer(); ?>
Thank you
add a style to publish to make the background green or pending to make the background red?
the background of what?
are you referring to this line:
<td><?php echo '<div id="posts-status">' . get_post_status( get_the_ID() )?></td>
this has some syntax errors;
depending on what you want to generate, try:
<td><?php echo '<div class="posts-status-' . get_post_status( get_the_ID() ) . '"></div>'; ?></td>
this would generate a div with the css class .post-status-whateverstatus
Thanks alot i had to edit the code to make it this
<td><?php echo '<div class="posts-status-' . get_post_status( get_the_ID() ) . '';?>"><?php echo get_post_status( get_the_ID() ) ?></div> </td>
one more question when it outputs the post status as ones that are published do you have any idea of why it says publish instead of published, as this is not right as the post is published and not publish and fixes for this would be great,
Thanks Again
why it says publish instead of published
just is so.
maybe start a topic in the‘Requests and Feedback’ sub forum about it.
ok, thanks for your help really appreciate it thanks i have started another post here http://wordpress.org/support/topic/add-posts-from-frontend?replies=1 maybe you coulde help here if you have nothing else to do.
Thanks again
Also just thaught ide let you know that i have figured a way for it to say PUBLISHED instead of publish, its a bit of a bodge job but it works heres the php
<td><?php echo '<div class="posts-status-' . get_post_status( get_the_ID() ) . '';?>"><?php echo get_post_status( get_the_ID() ) ?> <span>ed</span> </div></td>
i added ED into a span at the end
and the CSS (LESS CSS)
.posts-status-pending {
span{
display:none;
}
background-color: #F00;
text-align: center;
width: 100px;
margin:0 auto;
.border-radius(3px);
text-transform:uppercase;
}