Category Archives: Views

Conditional output if post body is empty

There is a bug in views related to conditional output based on post content so this is a work around.

In themes functions file:

 HTML |  copy code |? 
01
// Views test for post content
02
add_shortcode ( 'wpv-post-getcontent', 'wpv_getcontent' );
03
 function wpv_getcontent() {
04
global $post;
05
 if(get_the_content() != '') :
06
 return 1;
07
else :
08
 return 0;
09
endif;
10
wp_reset_query();
11
 }

Then in view template:

 HTML |  copy code |? 
1
[wpv-if evaluate="'[wpv-post-getcontent]' = '1'"]Conditional output here[/wpv-if]

Original post here:

https://wp-types.com/forums/topic/testing-for-empty-post-body/

Posted in Views | Leave a comment

Use blog_info data in Views

For instance to show blog_info(‘url’) field in a view:

 HTML |  copy code |? 
1
[wpv-bloginfo show='url']

Posted in Views | Leave a comment

Conditional Featured Image Present

To show the featured image if it is present:

 HTML |  copy code |? 
1
[wpv-if image="_thumbnail_id" evaluate="!empty($image)"]
2
<div class="my_featured_image">[wpv-post-featured-image size="full"]</div>
3
[/wpv-if]

Posted in Views | Leave a comment

Display Sibling Posts using WP Views

This is based on this tutorial:

http://wp-types.com/documentation/user-guides/displaying-brother-pages/

But I couldn’t get it working until by trial and error I found that the following worked:

  1. Create a view that pulls the child post using the filter
    Select related posts that are a child of the post where this View is inserted.“eg: “Further Works by Artist”
  2. Create a View Template that uses this Vieweg: “Further Works” which uses [wpv-view name="Further Works by Artist"]
  3. Insert the View Template in the View template used to show a single childeg: View Template “Work Details” shows the details of a child artwork and within it we insert the view “Further Works” to show other works by the same artist:

    [wpv-post-body id="$artist" view_template="Further Works"]

    where $artist is the slug of the post type or the parent.

Posted in Views | Leave a comment

Get Link to Featured Image for use in View

In functions.php create function and shortcode

 PHP |  copy code |? 
01
/** ***************************************************
02
 * get image src for featured image of post (large version)
03
 */
04
/* Register our short code at the appropriate time during the WordPress Boot process. */
05
add_action( 'init', 'wpk_register_shortcodes');
06
 
07
function wpk_register_shortcodes(){
08
   add_shortcode('my_get_thumbsrc', 'my_get_thumbsrc');
09
}
10
/* Function to return the source url for the featured image of a post */
11
function my_get_thumbsrc($id) {
12
   global $post;
13
    // Here we check if an ID was specified, if not, we use the ID of the current post
14
   $id = ($id) ? $id : $post->ID;
15
   if ( has_post_thumbnail($id)) {
16
//We're getting the url of the large version of the image here, options are 'thumbnail', 'medium', 'large' or 'full'
17
      $image_url = wp_get_attachment_image_src( get_post_thumbnail_id($id), 'large');
18
//  $image_url is an array; It holds url, width and height. See wp_get_attachment_image_src at the WP codex
19
      return $image_url[0]; // return just the url
20
  }
21
}

This shortcode can be used in a View to give link to the image file:

 PHP |  copy code |? 
1
<a href="[my_get_thumbsrc]">[wpv-post-featured-image size="medium"]</a>

Add modal viewer to link:

 PHP |  copy code |? 
1
<a href="[my_get_thumbsrc]" rel="lightbox[post-[wpv-post-id]]">[wpv-post-featured-image size="medium"]</a>

Original post http://wp-types.com/forums/topic/wpv-post-featured-image-as-a-link/

Posted in Code, Plugins, Views, Wordpress 3 | Leave a comment

Conditional Fields in View – show if not empty

Fields can be hidden if they are empty as follows:

 HTML |  copy code |? 
1
[wpv-if contact="wpcf-contact" evaluate="empty($contact)" condition="false"]
2
[types field="contact" class="" style=""][/types]
3
[/wpv-if]

Other conditional statements are detailed here:

http://wp-types.com/documentation/user-guides/conditional-html-output-in-views/

Useful example to show value if the field is not empty or a “NULL” string

 HTML |  copy code |? 
1
[wpv-if framed="wpcf-framed" evaluate="($framed != 'NULL') AND (!empty($framed))"]<br />
2
DO SOMETHING HERE<br />
3
[/wpv-if]

Posted in Views | Leave a comment

Views Featured Image Size

Specify featured image size using WP Views field:

 HTML |  copy code |? 
1
[wpv-post-featured-image size="full"]

Can define new image sizes in functions.php and use them for specific instances

Posted in Views, Wordpress 3 | Leave a comment

No Posts Found Text Shortcode

Shows text within shortcode tags when no rows are returned by the view

 HTML |  copy code |? 
1
[wpv-no-posts-found]<strong>No posts found</strong>[/wpv-no-posts-found]

Posted in Views | Leave a comment

Views using URL parameters for filters with spaces in the name

When using URL parameters to specify a filter use the Taxonomy name and use %20 in place of spaces.

 HTML |  copy code |? 
1
/12/latest-reviews/?wine=Sauvignon%20Blanc&vintage=2010

Posted in Views | Leave a comment