Embed a Block (created from a view) in a Node – Drupal 7

You need to embed a block (created from a view) in a node. It’s relatively easy to embed blocks in nodes, it just requires a bit of php. Use the following PHP snippet (don’t forget to enable the PHP text format):

<?php
  $block = module_invoke('module_name', 'block_view', 'block_delta');
  print render($block);
?>

Change module_name to views (for blocks indeed created from a view).
Change block_delta to the id of your block. Go to Structure > Blocks and hover/click the “configure” link next to your block. The block delta is the string before the /configure line of the url. In my case it was news_feed-block.


Tweet It Out!

A recent joke at work has turned into a little creation we like to call “Tweet it Out”. It takes enormous chunks of text and tweets it out for you! Try it out here: Tweet it Out!

I built it in about 45 minutes using HTML, CSS, and good ‘ol PHP. It’s actually quite simple. Let me know what you think!


Comments in html, php, and css

* 1 Comment

This is just a quick tip on how to create comments in html, php, and css. Every language is different, so hopefully this can clear it up if you’re always forgetting:

HTML

<!--- comments go here --->

PHP

// comments go here

CSS

/* comments go here */

Note that with HTML and CSS you can do multi-line comments using the start and end tags, but with php you’ll need to use the // every time you start a new line of comments. Hope that helps!


Change the length of the WordPress Excerpt

Add this code in the “functions.php” file of your theme:

function new_excerpt_length($length) {
	return 23;
}
add_filter('excerpt_length', 'new_excerpt_length');

WordPress + Nextgen Gallery: Load Lightbox Gallery From One Image

* 24 Comments

This is an explanation of how to have multiple galleries on a page, yet only show one thumbnail, and that thumbnail shows all of the images in the gallery…in the lightbox view. Phew, it’s hard enough just to write out. But after trawling through the internet looking for the answer, I’ve jimmy-rigged it myself. I don’t know that I’d call it a hack…but at least your page load time isn’t affected. So here goes!

##UPDATE: I’ve just recorded a screencast for this tutorial, click here.

1. Install the NextGen Gallery plugin (I assume if you’re having the same problem I did!)
2. Create a new page, and call galleries into it like this:
[nggallery id=1 template=one]
[nggallery id=2 template=one]
[nggallery id=3 template=one]

3. Create a new subfolder in your theme folder called “nggallery”.
4. Create a blank php file in the subfolder called “gallery-one.php” (this is the template you called in step 2.
5. Read my explanations and then copy the code and see how it works for you.

(This first bit is copied from gallery.php in the NextGen plugin folder)

<?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
<?php if (!empty ($gallery)) : ?>

Next we have to set our iterator (to find out where we are in the loop…not The Loop though).

<?php $i=1; ?>

Then let’s put our holder (with the ID of the gallery appended in the class) that will wrap each gallery.

<div class="holder<?php echo $gallery->ID; ?>">

And then our foreach statement. Here you can see I’ve added an IF statement that says, “if this is the first image, then show me the thumbnail linked to the lightbox slideshow…otherwise just give me a link (no image, but you need the a tag), and set its display to none”. After that is done, but before the FOREACH statement is finished, make sure and increment our iterator with $i++;

<?php foreach ($images as $image) : ?>
	<?php if ($i < 2) : ?>
		< a href="<?php echo $image->imageURL ?>" <?php echo $image->thumbcode ?> title="<?php echo $gallery->title ?>">
			<img src="<?php echo $image->thumbnailURL ?>" /></ a>

<?php else : ?> < a style="display:none" href="<?php echo $image->imageURL ?>" <?php echo $image->thumbcode ?>>link</ a> <?php endif; $i++; ?> <?php endforeach; ?>

Finally, close out your wrapping div, and close out the IF statement from the top:

</div>
<?php endif; ?>

Here’s the full code

<?php
/**
Template Page for the gallery overview

Follow variables are useable :

	$gallery     : Contain all about the gallery
	$images      : Contain all images, path, title
	$pagination  : Contain the pagination content

 You can check the content when you insert the tag <?php var_dump($variable) ?>
 If you would like to show the timestamp of the image ,you can use <?php echo $exif['created_timestamp'] ?>
**/
?>
<?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
<?php if (!empty ($gallery)) : ?>

<?php $i=1; ?>

<div class="gallery-holder gal<?php echo $gallery->ID; ?>">
<?php foreach ($images as $image) : ?>

	<?php if ($i < 2) : ?>
		<div style="display:none;">
			<img src="<?php echo $image->imageURL ?>" />
		</div>
		<a href="<?php echo $image->imageURL ?>" <?php echo $image->thumbcode ?> title="<?php echo $gallery->title ?>">
			<img src="<?php echo $image->thumbnailURL ?>" /></a>
	<?php else : ?>
		<a style="display:none" href="<?php echo $image->imageURL ?>" <?php echo $image->thumbcode ?>>link</a>
<?php endif; $i++; ?>

<?php endforeach; ?>
</div>

<?php endif;?>

The Perfect Text Editor: TextMate

I code in html, css, php, javascript, the list goes on. The most important feature of an editing program to me is speed. For several years I have used Textwrangler, but this week I have switched. In fact…I paid actual money for a text editor. The features it has are great. Here is my synopsis of TextMate (for mac).

1. lightweight. loads very fast, no frills
2. powerful. it understands many many languages. autocomplete tags, auto-close brackets.
3. shortcuts. for end tags, forward and backwards indent, selecting whole lines, typing MULTIPLE LINES at the same time (think large list of ‘li’ tags you want to setup)
4. ability to open a folder structure in the program and keep the folder structure visible and in place as you flip between pages to edit. Very useful for editing themes in wordpress & drupal. in fact, you can save that folder structure as a project for re-opening.
5. pasting from history. that’s right, there is a clipboard history that will allow you to copy things from multiple places in the document, then iterate through your clipboard to paste them one by one elsewhere.

I work for a school, meaning I was able to get the educational discount. But I think with the time that this is going to save me would be well worth the investment even of the full price version.

Download your copy at Macromates.com

Happy coding!