lucaBiagini.com

Growing old is not growing up.

Archive for the ‘Wordpress’ Category

Wordpress plugin: the excerpt re-reloaded

Saturday, November 29th, 2008

UPDATED!

The fantastic plugin The Excerpt Reloaded by Kaf Oseo, my trusted companion in dozens of  Wordpress installation, doesn’t work anymore on WP 2.6, so I have written an alternative version to finish the site I’m working on.

It’s a very small thing, not as complete as The excerpt reloaded, but, at least, it works, and it manages better than its inspirator the allowed tags, adding auto close to avoid pagination and validation errors.

It is based on the plain content of the post (like the content_rss in Kaf’s version) and like its predecessor, allowed tags cannot include <p> paragraphs, simply because I don’t need it on the site I’m currently developing, nor usually on any other. BTW, if somebody is interested, it can be easily fixed (or so I hope).

Parameters

  • words (integer): number of words to display before ending the excerpt. Default is 40.
  • link_text (string): defines the text for the link to the full post. Default is “Keep reading this entry »”. Of course it is displayed only if the selected length is less than the full content. It is displayed in a <p> pararaph with its specific class (more), so it can be easily stylized.
  • allowed_tags (string): defines which HTML tags to accept. Use the format ‘<img>’. For multiple tags, enter as single string: ‘<a><img>’. No tag allowed by default. NEW! Set to ‘all’ to accept all tags.
  • NEW! container (string): defines the container of the excerpt: paragraph, span, div, or none. The container has a specific class=”more” to easily customize its layout through css. If you choose a “div” container, an additional “p” tag inside the div is automatically included. Default is “p”, for no container use “plain”.

Examples

<?php the_excerpt_rereloaded(); ?>
//display the excerpt with default settings.

<?php the_excerpt_rereloaded('80','More','<strong><em>','div'); ?>
//display an excerpt of 80 words
//the link to full post is simply "more"
//allowed tags are strong and em
//the link path is <div class="more"><p><a href="#etc">More</a></p></div>

<?php the_excerpt_rereloaded('80','More','all','plain'); ?>
//display an excerpt of 80 words
//the link to full post is simply "more"
//all tags are accepted
//the link path is included in the excerpt paragraph with no additional container

Download

Click here to view, copy, paste und upload as usual in wp-content/plugins folder. Suggestions are welcome.

Previous version is still available.

Customize Wordpress Comments

Sunday, March 16th, 2008

That’s another article I’ve written for Gruppo Modulo after customizing the comments layout on their wordpress powered site. It’s a simple thing to do, but it still attracts enough visitors to gain a place on my personal blog.

Here’s how to have comments number displayed like comment background and to alternate the color of the comments background; it’s pretty simple and works on IE (6,7,8), Firefox (1.5,2,3), Safari (1,2,3), Opera (PC & Mac), and even in IE5 mac.

You have to change only 2 files, so backup them before you start. The file you need to edit are:

  • wp-content/themes/default/comments.php
  • wp-content/themes/default/style.css

First open comments.php and remove the open “ol” tag:

<ol class="commentlist">

Obviously, we remove the close “ol” too.
Now we have to remove the open “li” tag in foreach loop:

<li class="<?php echo $oddcomment; ?>"
id="comment-<?php comment_ID() ?>">

And then remove the “/li” after:

<?php comment_text() ?>

This has been necessary because we must create new numbers for the background; the ones generated from the ol list won’t work for the background, so we removed them to avoid duplications. Now we create the big numbers; edit this line:

<?php foreach ( $comments as $comment ) ?>

to be like this:

<?php $bigNumber = 1; foreach ( $comments as $comment ) ?>

Now, we create the div with the bigNumber before the comment:

<div class="bigNumber"> <?php echo $bigNumber; $bigNumber++ ?></div>

Then we create a div to contain the rest of the comment (date, author, text, ecc.). We open it right after the new bigNumber div:

<div class="theComment">

And we close it where there was the /li, after:

<?php comment_text() ?>

Now we need to create the alternance of divs name, so that we can alternate the background color of the comments. We need to create a div that encloses both bigNumber and theComment. So after foreach we open this new div like this:

<div class="<?=$i%2?"pari":"dispari";$i++;?>">

Then we close this div right before endforeach, after the /div for theComment.
Now we just have to add few lines to our css as follows:

.dispari { background: #ccc; }
.pari { background: #999; }
.bigNumber {
          font-size: 6em;
          color: #fff;
          width: 450px;
          text-align: right;
          position: absolute;
          margin-top: 20px;
          z-index: 10;
}
.theComment { position: relative; z-index: 20; }

That’s all!

Wordpress plugin: random subpages

Friday, February 22nd, 2008

This is the very first plugin I’ve written for wordpress. It’s so simple and could be easily optimized, but it works and it’s still having success, with a large number of viewers where I have originally posted it on Gruppo Modulo (where is also available in italian version).

Wordpress Plugin Random SubPages lets you show a customizable number of random child pages (or just some elements of them) of a parent page.

It can be used to display random services of a parent service page, i.e.:

+ web solutions
- xhtml + css
- php scripting
- webcommerce tools
- seo and sem
- web adv
- dem marketing
- ecc

Or it can be used to show the members of a team:

+ XYZ Football Team
- player 1
- player 2
- player 3
- players 4
- etc

Download Random Subpages and unzip the folder on your pc.
Then upload random_subpages.php in wp-content/plugin and activate it from admin panel.

Then recall it, outside the loop, in the page you wish with this code:

<?php

/* edit first row to set the number of
pages to show and the parent page */

// as set right now,it will show 3 pages, child of page 4

$randompages = gruppo_modulo_rsp('numberposts=3&parentpage=4′);
foreach($randompages as $post) : // do not edit this line
setup_postdata($post); // do not edit this line

/* now it will be shown what you want to show from the selected pages
(for example title, content, meta, ecc), see example below.
you can add additional formatting using echo.
n the example we have placed the title between h3 tags */

echo "<h3>";
the_title();
echo "</h3>";
the_excerpt();
the_content();
the_meta();

// end of the customizable part; do not edit below

endforeach;

?>