Support » Fixing WordPress » Removing a divider line after last post/widget

  • Hi guys,
    On my web-site, on template of home page i show last N posts of my site.
    After each post i’ve created divide block with image in background.
    How can i remove this block after the post on home page.
    Exaclty the same situation i have on sidebar.
    Part of code from home page:

    <?php while ( have_posts() ) : the_post(); ?>
    /*body of my post*/
    <div class="divide"></div>
    <?php endwhile; ?>

    Part from style.css:

    .divide-sidebar{
    	background-image: url(images/someimage.png);
    	width: 100%;
    	background-repeat: repeat-x;
    	margin: 27px 0 0;
    }

Viewing 10 replies - 1 through 10 (of 10 total)
  • I’m assuming that the class divide is going to be the same in the css instead of divide-sidebar.

    How about:

    <ul>
    <?php while ( have_posts() ) : the_post(); ?>
    <div class="divide">
    /*body of my post*/
    <li></li>
    </div>
    <?php endwhile; ?>
    </ul>

    css:

    .divide li{
    	background-image: url(images/someimage.png);
    	width: 100%;
    	background-repeat: repeat-x;
    	margin: 27px 0 0;
    }
    
    .divide li:last-child{
    	display: none;
    }

    Thread Starter crowbar4ik

    (@crowbar4ik)

    Hi man,
    Actually i also thought about some tricks, using list and last-child for it.
    But i don’t sure that your example is correct.
    Is it normal to put whole cycle into list?
    Is it normal to put whole content into divide div?
    I think the result of your code will be divide div in the top of each post and that’s all.

    The css is targeting li not just the div so it should show at the bottom of the post but you should try it and then let us know what issues you may have or better yet, a link to an example of it.

    using php; example:

    <?php if( $wp_query->current_post != $wp_query->post_count-1 ) echo '<div class="divide"></div>'; ?>
    Thread Starter crowbar4ik

    (@crowbar4ik)

    Thanks a lot, alchymyth. That is good and correct solution.
    But have one more question about such situation in sidebar (widget) zone.
    I use such sidebar.php:

    <?php if ( is_active_sidebar( 'sidebar1' ) ) : ?>
    	<div id="sidebar" class="site-sidebar">
    		<?php dynamic_sidebar( 'sidebar1' ); ?>
    	</div>
    <?php endif; ?>

    And such in functions.php:

    <?php
    function mysite_widgets_init() {
    	register_sidebar(array(
    		'name' => __( 'Main sidebar' ),
    		'id' => 'sidebar1',
    		'before_widget' => '<div id="posts" class="posts">',
    		'after_widget' => '</ul></div><div class="divide-sidebar"></div></div>',
    		'before_title' => '<div class="sidebar-title"><p>',
    		'after_title' => '</p></div><div class="links"><ul class="links">',
    	) );
    }?>

    So first question, how not to show <div class=”divide-sidebar”> after last widget (how define current widget in wordpress)?
    And the second one, is it normal to use such code in fuctions.php or i need trying to avoid putting a lot of html code into parameters of mysite_widgets_init function?

    there was a recent article about how to add specific classes to the first and last widget in a sidebar;

    http://wordpress.org/support/topic/how-to-first-and-last-css-classes-for-sidebar-widgets?replies=9

    or as plugin http://wordpress.org/plugins/widget-css-classes/

    what theme are you working with?

    Thread Starter crowbar4ik

    (@crowbar4ik)

    Yes, i found that one.
    I’m working on this template: http://bestwebsoft.com/wp-content/uploads/2013/08/home4.jpg

    please contact the developer of your theme with any further theme specific questions.

    commercial themes are not supported in this forum; http://codex.wordpress.org/Forum_Welcome#Commercial_Products

    Thread Starter crowbar4ik

    (@crowbar4ik)

    Actually, i can just send you another example, if it is make sence for u. I just work with wordpress and try to do my best to make all things i need there. (i mean i am developer of theme, so it is not commercial)

    How can I set like this, If a previous post/newer post link is not available then css class will not show up. Look this http://awesomescreenshot.com/0c339j4ff9

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Removing a divider line after last post/widget’ is closed to new replies.