Petr Pabouček
Freelance Web Developer

Prohlédněte si seznam mnou nabízených služeb, podívejte se, co o mě říkají mí klienti, či na jakých projektech jsem se podílel. V případě zájmu o spolupráci, či jakýchkoliv jiných dotazů, mě prosím kontaktujte.

How to allow comments on scheduled posts in WordPress

When working on one project for client of mine I’ve bumped into problem when trying to allow comments on scheduled posts. In this specific case, scheduled posts are used for displaying different type of promotions. WordPress theme then uses a template which allows for displaying scheduled posts on the front-end and once the publication date is reached, promotion is automatically taken off the site.  So far so good.

The problem arrived when I tried to allow comments on the promotions (scheduled posts). Comment form appears as expected, but when the comment is submitted, it never makes it through. I’ve tried to do bit of a research on the Internet, but unfortunately haven’t found any  satisfying solution, which wouldn’t require altering core files.

The reason, why comment never makes it through is caused by this condition in wp-comments-post.php file.

elseif ( ! $status_obj->public && ! $status_obj->private ) {
/**
* Fires when a comment is attempted on a post in draft mode.
*
* @since unknown
* @param int $comment_post_ID Post ID.
*/
do_action( 'comment_on_draft', $comment_post_ID );
exit;
}

Pokračovat »

Adding a CSS class to the all last menu items generated by wp_nav_menu

Today I’ve been working on one WordPress project where I needed to add CSS class  to the all last menu items generated by wp_nav_menu() function.  I’ve done little research on the Internet and found this article ‚Adding a CSS Class to the Last LI Generated by wp_nav_menu()‚. Works great so far, unfortunatelly it adds class just to the very last item of the list.

My task required to add CSS class to the all last menu items as follows:

<ul>
	<li>Item A
        <ul>
	         <li>Item a1</li>
	         <li>Item a2</li>
	         <li class="last">Item a3</li>
        </ul>
    </li>
	<li>Item B
        <ul>
	          <li>Item b1</li>
	          <li>Item b2</li>
	          <li class="last">Item b3</li>
        </ul>
    </li>
	<li class="last">Item C</li>
</ul>

Article mentioned above has been a great inspiration to me and after a while of playing with WordPress, I have come up with this code.

Pokračovat »