Webdesign/WordPress

Just a couple of very simple WordPress plugins, for which I was unable to locate equivalents in the official repository.

Pagelist plugin

<?php
/*
Plugin Name: FCP Pagelist
Plugin URI: http://felix.plesoianu.ro/index.php/page:WebDesign:WordPress
Description: Shortcode to include a list of pages or posts in another.
Version: 2010-11-05
Author: Felix Pleșoianu
Author URI: http://felix.plesoianu.ro/

If you are asking what license this software is released under,
you are asking the wrong question.
*/

// [pagelist query="posts_per_page=3"]
function pagelist_shortcode($args) {
	global $more;
	
	$defaults = array(
		'query' => '',
		'title_tag' => 'h3',
		'post_before' => '<div class="article">',
		'post_after' => '</div>',
		'more_msg' => 'Read more...');
	$args = shortcode_atts($defaults, $args);

	$query = new WP_Query($args['query']);
	if (!$query->have_posts()) return "";
	
	$output = "";
	while ($query->have_posts()) {
		$output .= $args['post_before'];

		$query->the_post();
		$output .= sprintf('<%s><a href="%s">%s</a></%s>',
			$args['title_tag'],
			get_permalink(),
			get_the_title(),
			$args['title_tag']);
		$more = false;
		$output .= get_the_content($args['more_msg']);

		$output .= $args['post_after'];
	}
	return $output;
}
add_shortcode('pagelist', 'pagelist_shortcode');
?>

Transclude plugin

<?php
/*
Plugin Name: FCP Transclude
Plugin URI: http://felix.plesoianu.ro/index.php/page:WebDesign:WordPress
Description: Shortcode to include the contents of a page or post in another.
Version: 2010-11-03
Author: Felix Pleșoianu
Author URI: http://felix.plesoianu.ro/

If you are asking what license this software is released under,
you are asking the wrong question.
*/

// [transclude page_id="15"]
function transclude_shortcode($args) {
	$args = shortcode_atts(array('id' => '0'), $args);

	$page_id = abs(intval($args['id']));
	if ($page_id > 0) {
		$post = get_post($page_id);
		if (is_object($post))
			return wpautop(wptexturize($post->post_content));
	}
	return "";
}
add_shortcode('transclude', 'transclude_shortcode');
?>

Syntax highlighting courtesy of JUSH.


Last modified: Sat 06 11 2010, 08:21:39 UTC