cedmax.net

pink is the new black

So you want to style a post depending on its author?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
/*
Plugin Name: Add Author Class
Plugin URI: http://cedmax.net
Description: extends post_class() to add author class
Version: 1
Author: cedmax
Author URI: http://cedmax.net
*/
function add_author_class($class) {
	array_push($class, 'author-'.get_the_author_meta('user_nicename'));
	return $class;
}
 
add_filter("post_class", "add_author_class" );
?>

you’re welcome

One of the most awful things I found out in a lot of wordpress themes is the hardcoded text.

I found out that with Simple Shortcodes it is possible to centralize in the admin part text content without editing themes.
download, install and activate it.

Go to the plugin admin page and you can add the content you need to use in your theme (in this case I’m also using qTranslate, that’s why I use <!–:it–> and <!–:en–>)

simpleshortcode

Then in your theme you can write the content of your shortcode simply calling a function named like the shortcode + ‘_shortcode’ for example

1
2
3
if(function_exists('collaboration_title_shorcode')){
	_e(collaboration_title_shorcode())
}

This could be surely useful in order to let someone manage site content without giving him permission on theme editor.

EDIT
a step forward:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
/*
Plugin Name: Labelize Simple Shortcodes
Plugin URI: http://cedmax.net
Description: use simple shortcodes plugin to delete hardcoded text in themes
Version: 1
Author: cedmax
Author URI: http://cedmax.net
*/
 
 
function get_label($shorcode, $echo=true, $before, $after) {
	$myfunc = $shorcode . '_shortcode';
	if(function_exists($myfunc)){
		$output = $myfunc();
		if ($before) $output = $before . $output;
		if ($after) $output = $output . $after;		
		if ($echo) {
			_e($output);
		}else{
			return __($output);
		}
	} 
}
?>

a simple plugin, quick and dirty, to be used like this:

1
get_label('collaboration_title');

optional parameters:
$echo: use it as boolean (true or false) to have the label printed or returned as php string (default = true)
$before: if you want something before your label (markup for example)
$after: as before, but after the label

hope it could be useful

wordpress cheat sheet
wordpress sample content for theme development
setting opacity to ie8 (and other filters as well)

I was trying to integrate wordpress and sweetcron to have a “lifestream” section on my wordpress based website.

First of all I created a folder named sweet (you can use everything you like)
then I tryed to integrate wordpress dynamic data (header, footer, sidebar and style) in sweetcron template.

that was pretty easy: I added this line of code:

1
require("../wp-blog-header.php");

on the top of index.php in sweetcron root

Now I was able to use every template tag I needed (as well as widgets and everything else in use in wordpress) in sweetcron theme pages..

The problem was that wordpress was returning a 404 error in http headers and page title was "Page not Found"

So i created a wordpress page named Life Stream with sweet as slug.

Sweetcron homepage was safe but every internal sweetcron link (for example this) had the same 404 problem.

so I wrote this really tiny plugin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
/*
Plugin Name: Sweetcron integration
Plugin URI: http://cedmax.net
Version: 0.1
Description: Manage Sweetcron wordpress integration 
Author: cedmax
*/
 
 
function sweetcheck() {
	$pagename='sweet';
	$isStream =  substr_count(str_replace($_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']).'/', '/'.$pagename.'/');
	if ($isStream>0) query_posts('pagename='.$pagename);
}
 
 
add_action('init', 'sweetcheck');
?>

change sweet with yoursweetcroninstallationfolder and everything should be fine.

edit I had to remove my sweetcron installation: some problems with some of the feeds I was importing and no time to fix it, but the integration is still working

Something about me

Javascript Pirate, father of two, meteoropathic and with an insane passion for lo-fi music. cedmax.com more

Something About Karma


Something About Friends