Skip to content
WJunction - Webmaster Forum

CSS Help required

Status
Not open for further replies.
Hi Guys,

I am new to CSS/PHP world. But doing a little research I have implemented couple of links to call Previous Post and Next Post on single-post.php just next to Post Meta information. Please see image.
ScreenHunter_15%20Apr.%2014%2013.39.jpg


This is the php code I've inserted in that php file (highlighted in red):

Code:
<?php global $theme; ?>

    <div <?php post_class('post post-single clearfix'); ?> id="post-<?php the_ID(); ?>">
    
        
        
        <h2 class="title"><?php the_title(); ?></h2>
     
<div class="postmeta-primary">
    
            <span class="meta_date"><?php echo get_the_date(); ?></span>
           &nbsp; <span class="meta_categories"><?php the_category(', '); ?></span>
    
                <?php if(comments_open( get_the_ID() ))  {
                    ?> &nbsp; <span class="meta_comments"><?php comments_popup_link( __( 'No comments', 'themater' ), __( '1 Comment', 'themater' ), __( '% Comments', 'themater' ) ); ?></span><?php
                }
                
                if(is_user_logged_in())  {
                    ?> &nbsp; <span class="meta_edit"><?php edit_post_link(); ?></span><?php
                } ?> 
[B][COLOR="Red"]<span><?php previous_post(); ?></span>&nbsp; <span><?php next_post(); ?></span>[/COLOR][/B]     

  </div>



        <div class="entry clearfix">
            
          
              
            <?php
                the_content('');
                wp_link_pages( array( 'before' => '<p><strong>' . __( 'Pages:', 'themater' ) . '</strong>', 'after' => '</p>' ) );
            ?>
    
        </div>
        
        <?php if(get_the_tags()) {
                ?><div class="postmeta-secondary"><span class="meta_tags"><?php the_tags('', ', ', ''); ?></span></div><?php
            }
        ?> 
        
    
    </div><!-- Post ID <?php the_ID(); ?> -->
    
    <?php 
        if(comments_open( get_the_ID() ))  {
            comments_template('', true); 
        }
    ?>

I would actually want to call for the same function but with buttons/images.

Please help me on how to implement this with proper CSS to call for it.

Thanks in anticipation.
 

2 comments

Change the red part to:

PHP:
<span class="prev-post"><?php previous_post(); ?></span>&nbsp; <span class="next-post"><?php next_post(); ?></span>

Then add the styes to your CSS file:

PHP:
.prev-post {
     background: url("path/to/image.png") no-repeat scroll 0 0 transparent;
}
.next-post {
     background: url("path/to/image.png") no-repeat scroll 0 0 transparent;
}

You'll need to set the width/height and probably use display block as well. If you would post your site's URL, I can check it my self and give you the full code.
 
Last edited:
Random post code

Hi RT, thank you for your quick reply. I tried playing with the code you've suggested. However, this code worked for me better:

PHP:
<span><?php next_post_link('%link', '<img src="http://localhost:62329/wp-content/uploads/2013/04/nextbtn.png" align="right" alt="Next Pic"/>') ?></span> &nbsp;

<span><?php previous_post_link('%link', '<img src="http://localhost:62329/wp-content/uploads/2013/04/prebtn.png" align="right"  alt="Previous Pic" />') ?></span>

The only problem I'm facing is, the buttons are stuck to each other and I actually want it to have a little space in between. Can that be achieved?

Also, could you please suggest me a code (similar to the above) to generate random post (single post) on a image/button click?

Once again, thanks a lot for your support.

Cheers.

Imran
 
Status
Not open for further replies.

About the author

T
New Member · Joined
2
Messages
0
Reactions
1
Points
Grow your business

Advertise on WJunction

Connect with an established international community of webmasters, hosting providers, developers and online entrepreneurs.

  • Premium & Premium+ Sticky
  • Dedicated section banners
  • Site-wide banner advertising
Explore advertising options
Back
Top Bottom