WP Smith

Creating WordPress & Genesis Websites Since 2010

  • Home
  • About
  • Services
  • Blog
  • Contact

Dec 29 2011

How to Remove Specific Posts from Blog Page in Genesis

Recently, I needed to remove a specific post from a blog page. Here's how I did it.

[php]
add_filter( 'genesis_custom_loop_args', 'wps_exclude_post' );
function wps_exclude_post ( $args ) {
$args['post__not_in'] = array(6586); //Post ID
return $args;
}
[/php]

This code adds an argument to the WordPress query called 'post__not_in' which takes an array of post IDs. So, I could just create a laundry list of posts I don't want in; however, in my case I only needed to exclude one.

As always, this code goes in functions.php.

Written by Travis Smith · Categorized: Genesis

Dec 27 2011

Adding Contextual Help Tab to Edit/Add New Post/Page

It is fairly simple and straightforward on how to add contextual help tabs to various admin pages, and with the imminent advent of Genesis 1.8, adding contextual help will be as simple as a help() method. There are also a wide variety of great tutorials on how to add contextual help to admin pages, such as Justin Tadlock's Adding contextual help to plugin and theme admin pages.

However, there aren't any tutorials (at least that I could find) on how to add contextual help to edit/add-new post pages. So while I believe this may not be the best way to do this, it works! Being a pragmatist, it works for me!

[php]
// Add contextual help
add_action( 'add_meta_boxes' , 'wps_help' , 10 , 2 );
function wps_help ( $post_type , $post ) {
if ( 'page' == $post_type ) {
$my_help_tab_content = '<p>' . __( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam varius iaculis dui, eu ultricies velit consectetur pellentesque. Phasellus tortor mi, tempor eget pulvinar eu, sollicitudin ut eros. Quisque fermentum dolor elit. Aenean varius nisi placerat lectus elementum fringilla. Aenean at augue mauris, eu euismod mauris. Integer ac eros in ligula pharetra pretium. Pellentesque vel orci nibh. Pellentesque gravida velit ac lacus egestas eget imperdiet metus egestas. Maecenas tellus ligula, molestie ac pharetra id, tristique eu velit. Phasellus id quam in mi tristique gravida eget in quam. Cras ornare leo sed dui lobortis congue.') . '</p>';

get_current_screen()->add_help_tab( array(
'id' => 'my-help-id',
'title' => __( 'My Help Tab' ),
'content' => $my_help_tab_content,
) );
}
}
[/php]

Written by Travis Smith · Categorized: WordPress

Dec 23 2011

How to Create a Custom Button in Gravity Forms with a Terms of Service Button Example

Written by Travis Smith · Categorized: WordPress

Dec 22 2011

How to Add a Custom Field Shortcode to Use Any Custom Field in Posts

In another tutorial I am writing, one for non-coders, I needed a way to pull in custom fields into the post. Currently (and sadly), in Genesis there is no way to do this; however, Genesis does have a great php function that already does this, genesis_get_custom_field(). So turning that into a shortcode is rather easy. Just add the following to your functions.php code:

[php]
add_shortcode( 'post_field', 'genesis_post_field_shortcode' );
/**
* Returns the value of a custom field.
*
* Supported shortcode attributes are:
* field (field name),
*
* @param array $atts Shortcode attributes
* @return string Shortcode output
*/
function genesis_post_field_shortcode( $atts ) {

$defaults = array(
'field' => '',
);
$atts = shortcode_atts( $defaults, $atts );

return genesis_get_custom_field( $atts['field'] );
}
[/php]
To use the shortcode, you just insert [ post_field field="my_field_name"] (without the space in the front) and boom! It works!

Written by Travis Smith · Categorized: Genesis, Tutorials

Dec 21 2011

How to Use Genesis Featured Widget Amplified to Link to the Image and Add a Lightbox or WordPress's Thickbox (Using Lightbox Evolution) in Genesis Featured Widget Amplified

So recently, someone contacted me to figure out how to make the Genesis Featured Widget Amplified link to the Image, instead of the post. For example, take a Genesis Child Theme like Crystal, Delicious, Manhattan, Minimum, and/or Scribble. Each of these themes have an area of a portfolio or a row of images which link to their respective posts. However, what if you wanted these images to appear in a lightbox/thickbox? What if you wanted these to link to just the image and not the post?

Genesis Featured Widget Amplified

A lot of plugins are built without hooks and filters, which can be rather frustrating for developers because developers love to change things to "improve" them, which really is just making the plugin/widget do what they want instead of what the purpose of the widget/plugin was designed to do. However, the Genesis Featured Widget Amplified plugin has everything, well almost everything, a person would want in a widget of its kind. Furthermore, it has the appropriate hooks and filters to make things happen without having to hack core, hence the beauty of action hooks.

1. Widget Settings

So the first thing we must do is to have the link, link to the image, not the post. So using the Genesis Featured Widget Amplified, you want to ensure that you have selected Show Featured Image and selected Link to Post (being able to change this would be hacking the core of the plugin). We also want to set the instance identification, here, portfolio.

2. Replacing the Linked Image

Now, we want to remove the current function that creates the link and the image, and create one of our own. However, first we want to make sure we are on the home page and that we have the correct instance.

[php]
add_action ( 'gfwa_before_loop' , 'we_check_portfolio' , 10 , 1 );
function we_check_portfolio( $instance ) {
if ( ! is_home() )
return;
elseif ( ( is_home() ) && ( $instance['custom_field'] == 'portfolio' ) ) {

// Remove all GFWA image functions
remove_action( 'gfwa_before_post_content', 'gfwa_do_post_image' , 5 );
remove_action( 'gfwa_before_post_content', 'gfwa_do_post_image' , 5 );
remove_action( 'gfwa_after_post_content', 'gfwa_do_post_image' , 10 );

// Add our custom function
add_action ( 'gfwa_before_post_content', 'gfwa_do_we_post_image', 8, 1 );

// Add functions back
add_action ( 'gfwa_after_loop' , 'we_add_image' , 10 , 1 );
}
}

function gfwa_do_we_post_image ( $instance ) {
if ( $instance['custom_field'] == 'portfolio' ) {
$image = genesis_get_image( array( 'format' => 'html' , 'size' => $instance['image_size'] ) );
$image_id = get_post_thumbnail_id();
$image = sprintf( '<a href="%s" title="%s" class="%s">%s</a>', wp_get_attachment_url( $image_id ), the_title_attribute( 'echo=0' ), esc_attr( $instance['image_alignment'] ), $image );
echo $image;
}
}

function we_add_image ( $instance ) {
add_action( 'gfwa_before_post_content', 'gfwa_do_post_image' , 5 );
add_action( 'gfwa_post_content', 'gfwa_do_post_image' , 5 );
add_action( 'gfwa_after_post_content', 'gfwa_do_post_image' , 10 );
}

function wps_lightbox_js() {
?>
<script>
jQuery(document).ready(function() {
jQuery("img").parent("a").addClass("lightbox");
});
</script>
<?php
}
add_action( 'wp_footer' , 'wps_lightbox_js' );
[/php]

3. Add WordPress's Thickbox

For the plugin, Lightbox Evolution (which is a good lightbox plugin), this person was using the class lightbox was required. However, you can use WordPress's built-in Thickbox, which is used for the Media Library. To use the WordPress Media Library (and not a plugin), replace function wps_lightbox_js() code with the function below:

[php]
function wps_add_thickbox() {
if(!is_admin()){
wp_enqueue_script( 'thickbox' , null , array( ' jquery ' ) );
wp_enqueue_style( 'thickbox.css' , '/' . WPINC . '/js/thickbox/thickbox.css' , null , '1.0' );
}
}
add_action ( 'init' , 'wps_add_thickbox' );

function wps_thickbox_js(){
?>
<script>
jQuery(document).ready(function() {
jQuery("img").parent("a").addClass("thickbox");
});
</script>
<?php
}
add_action( 'wp_footer' , 'wps_thickbox_js' );
[/php]

Word of Caution

You need to make sure that if you use this code, you are inserting images that Link to the File URL, not the Post URL (which I believe is the default).

Here is an example:

Genesis Featured Widget Amplified Insert
Linked to Post
Genesis Featured Widget Amplified Insert
Linked to File URL/Image

Written by Travis Smith · Categorized: WordPress

  • « Previous Page
  • 1
  • …
  • 27
  • 28
  • 29
  • 30
  • 31
  • …
  • 60
  • Next Page »

Need Help?

Please let us know how we can help you!

Get Help

Recommendations

Genesis WordPress Framework
Sucuri Security
Gravity Forms
GetSoliloquy
Get Envira
Scribe SEO
BackupBuddy
WordPress Video User Manuals

Recent Posts

  • Solving WordPress 5XX Server Errors on SiteGround
  • Hiding an User in the WordPress Admin
  • Custom Rewrite Rules for Custom Post Types and Taxonomies
  • WordPress JavaScript Manager Native Functions
  • Causes of WordPress Site Performance Slowdown

About Travis

As a WordPress enthusiast, developer, and speaker, Travis writes about what he learns in WordPress trying to help other WordPress travelers, beginners and enthusiasts with tutorials, explanations, & demonstrations.

  • Twitter
  • Facebook
  • LinkedIn
  • Google+
  • RSS

Copyright © 2025 � WP Smith on Genesis on Genesis Framework � WordPress � Log in