Show only posts with certain custom field in Wordpress

12 May

Today I spent a few hours on trying to figure how the hell should I display only posts with certain custom field. For those who don’t know, a custom field allows you to add some extra information in each post. That information allows you to do various stuff like displaying a custom image on each post and so on. For example, the thing I tried to do today was to make a gender selector for the current project.

The usual way for displaying posts in Wordpress is this:

if (have_posts()) : 
 while (have_posts()) : the_post();

What I did is this:

$gender = htmlentities($_GET['gender'], ENT_QUOTES, 'UTF-8');
switch($gender ){
	case "f":
		query_posts('meta_key=gender&meta_value=f'); 
	break;
 
	case "m":
		query_posts('meta_key=gender&meta_value=m); 
	break;
	default :
 
	break;
}

After that i continued with regular code:

if (have_posts()) : 
 while (have_posts()) : the_post();

That’s all!

Of course, i could use an unlisted tag or category, but i also made a neat custom field manager in the “post.php” page that makes administration of those custom fields a breeze.

Tags: Comments (1)

Bookmark this article!

Del.icio.usDiggStumbleUponFurlRedditTechnorati

SlashDotWindows LiveYahooGoogleFacebookBlogLines

WP-Print – show me the link ONLY!

6 Apr

I had to use a WP-Print for a recent Wordpress project and, because the way i work, i started to search for plugins AFTER the psd was converted into html and a big part of code was already up & running. So, i downloaded latest version of WP-Print and I tried to use a basic setup:

<?php 
 print_link();
?>

The problem is that the plugin display the whole link tag (a href="...") and I only needed the href value. I edited wp-print.php (which is inside of you wp-content/plugins/wp-print folder) and i looked for print_link() function.

I saw the function accept three parameters: with first two you can set some extra text and the third (which is boolean) is for setting the way how function behave. So, you can call the function like the previous example or like this:

<?php 
 echo print_link('', '', false);
?>


For showing the way you want. But, because i wanted only the link to that page, i edited wp-print.php and i changed the return of the function when the last parameter was boolean:

if($echo) {
	echo $output."\n";
} else {
	return $output;
}

Became:

if($echo) {
	echo $output."\n";
} else {
	return $print_link;
}

So now, i can use it like this:

<li><a href="<?php echo print_link('', '', false); ?>" class="myPrint">PRINT !</a></li>

Easy, isn’t it? :)

Tags: Comments (3)

Bookmark this article!

Del.icio.usDiggStumbleUponFurlRedditTechnorati

SlashDotWindows LiveYahooGoogleFacebookBlogLines

Ntz Antispam Wordpress Plugin

2 Mar

Wassup guys?

I’ve worked a LOT lately and i didn’t have time to do too much things. I know i had promised you some free Wordpress themes, but right now I really don’t know when i will launch them.

Anyhow, few months ago i posted a very effective spam trick. Because that method was somehow hard to apply and everytime you update wordpress or change your theme you had to redo some steps, i though is better to make a plugin for this.

Is a small plugin, is free to use and redistribute (even i ask you to do so!).

How to use?

  1. Extract in your wp-content/plugins folder
  2. Activate from your admin area
  3. Watch your spam queue. ZERO. Nothing, NADA!

How effective is this ?

I use this trick for over six months. Before I use this, i had around 50 spams/day catched by Akismet. After i put this, i have MAXIMUM five spams/week. Very impressive, isn’t it?

Dowload from here:


  ntzAntiSpam (738 bytes, 529 hits)

You don’t have to pay a dime. Anyhow, any link love is well appreciated :D

Update:

I also can be found HERE.

Tags: , , Comments (21)

Bookmark this article!

Del.icio.usDiggStumbleUponFurlRedditTechnorati

SlashDotWindows LiveYahooGoogleFacebookBlogLines

Wordpress 2.7 final to be released

3 Dec

If you use wordpress, you may be happy. The 2.7 will go final in two days from now. The good news is this: old browsers are not supported anymore. Yes, IE6 is included in “old browser” category!

I already update this blog to 2.7 RC because i just messed up feed.

What i did? Well.. In my “have more money than Bill Gates” race, i wanted to put some ads in RSS feeds. I set up this in adsense account but… The problem is that i screw things up :( Ads are displayed, but in reader you can see a small excerpt. I spend over two hours to find a fix (including removing the ads!) but with no luck. So… If you know how to fix and you want to help me, be my guest!

Tags: Comments (2)

Bookmark this article!

Del.icio.usDiggStumbleUponFurlRedditTechnorati

SlashDotWindows LiveYahooGoogleFacebookBlogLines

Very *effective* antispam trick on blogs

21 Oct

Most of bloggers have a problem with spam. Of course, there is Akismet, but sometimes Akismet is not good enough because he doesn’t catch all spam messages. So, with this in mind, i wanted only to get rid of all automated messages.

So, look what i did:

First of all, i go with „robots fills ALL fields with something” in my mind. I’ve added only TWO lines of code: one in comments.php from your theme folder and one in wp-comments-post.php from your root folder.

Ok, how you do it?

First of all you need a ftp client and a text editor. E-texteditor is 2 in 1 so you can download a trial version for doing this. Ofcourse, you can use the old and ugly notepad (or whatever your OS has default).

Open comments.php (which is in your wp-content/themes/your_theme_name folder) then find this line:

<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">

Some things can vary (like ID of the form), but 90% in cases you won’t need to look for something else ;)

Just AFTER this line you add:

<p style="position:absolute; left:-9999px;">Don't fill this! <input type="text" name="name2" /></p>

We put a form here and hide it. I didn’t use display:none because i wanted to be sure that field will be showed up, even is on the left side of the screen (you should actually turn you head to left to see it :P ) So the bot will actually SEE that form and will fill. Normal user won’t.

Save and upload (or just save if you work directly on ftp) then open wp-comments-post.php from your root folder. Just after the

<?php
/**
 * Handles Comment Post to WordPress and prevents duplicate comment posting.
 *
 * @package WordPress
 */

beginning part, just add this:

if( $_POST['name2']!= ''){
	die('Spammer!');
}

Save and upload.

Next you need to… Hmm… You don’t need to do anything else ! Now empty your Akismet queue and wait to see if you get any other spam messages ;)

Note that is possible to not catch ALL spams, but those are automated you won’t get it anymore :) Also, when you upgrade wordpress make sure you make those changes again. And finally, BACK UP FIRST!

Update.

READ THIS!

Verry annoying thing that i had recently noticed: even if this small plugin do a great job for spamm *comments*, will NOT work on trackback spam.

Tags: , Comments (11)

Bookmark this article!

Del.icio.usDiggStumbleUponFurlRedditTechnorati

SlashDotWindows LiveYahooGoogleFacebookBlogLines

Older Posts »