Jump to content


Photo
- - - - -

PHP Snippets


  • Please log in to reply
8 replies to this topic

#1 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 24 July 2011 - 12:28 AM

Starting today, all useful php functions snippets css whatever, add it to this thread so the next mod can find it!

#2 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 24 July 2011 - 12:29 AM

Remove default boxes and features that just keep coming back!

Create file wp-content/mu-plugins/remove_defaults.php

add the following:
 <?php
	/*
	file used to stop creation of pagelines pro default boxes and features which
	were being duplicated by post on a page plugin
	*/
	add_filter('pagelines_default_boxes', create_function( '', 'return array();') );
	add_filter('pagelines_default_features', create_function( '', 'return array();') );
No need to activate files in mu-plugins, they are parsed automagically.

#3 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 26 July 2011 - 02:45 PM

Add featured to pages
 
	add_theme_support( 'post-thumbnails', array( 'post', 'page' ) );
featured stop after 4
 
	add_filter( 'pagelines_feature_autostop', create_function('', 'return 4;' ));
My instant +1 (can be anywhere, just change hook)
 
	add_action( 'wp_head', create_function('','echo "<script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script>";'));
	add_action( 'pagelines_branding_icons_start', create_function('', 'echo "<span class='gp1'><g:plusone></g:plusone></span>";'));


#4 kastelic

kastelic

    Advocate

  • Members

  • 3081 posts
  • Country: Country Flag

Posted 03 August 2011 - 04:34 PM

MASTER LIST OF HOOKS
Feel free to update and correct.

 
	HEADER
	pagelines_before_html
	pagelines_head
	pagelines_before_site
	pagelines_before_page
	before_header
	pagelines_before_main
	
	BRANDING
	pagelines_before_branding
	pagelines_inside_top_branding
	pagelines_inside_bottom_branding
	pagelines_after_branding
	pagelines_before_branding_icons
	pagelines_branding_icons_start
	pagelines_branding_icons_end
	pagelines_after_branding_wrap
	
	NAVIGATION
	pagelines_before_primary-nav
	pagelines_inside_top_primary-nav
	pagelines_inside_bottom_primary-nav
	pagelines_after_primary-nav
	
	SECONDARY NAV
	pagelines_before_secondnav
	pagelines_inside_top_secondnav
	pagelines_inside_bottom_secondnav
	pagelines_after_secondnav
	
	CONTENT
	pagelines_before_maincontent
	pagelines_inside_top_maincontent
	pagelines_inside_bottom_maincontent
	pagelines_after_maincontent
	pagelines_before_columns
	pagelines_before_maincolumn
	pagelines_before_sidebar1
	pagelines_after_sidebar1
	
	MAIN CONTENT
	pagelines_before_theloop
	pagelines_inside_top_theloop
	pagelines_inside_bottom_theloop
	pagelines_after_theloop
	
	POSTLOOP
	pagelines_loop_post_start
	pagelines_loop_page_title_after
	pagelines_loop_post_header_start
	pagelines_before_excerpt
	pagelines_after_excerpt
	pagelines_loop_before_post_content
	pagelines_loop_after_post_content
	pagelines_loop_post_end
	pagelines_loop_clipbox_start
	pagelines_loop_clip_start
	pagelines_loop_clip_excerpt_end
	pagelines_loop_clip_end
	pagelines_loop_clipbox_end
	
	COMMENT FORM
	pagelines_before_pl_comments
	pagelines_inside_top_pl_comments
	pagelines_inside_bottom_pl_comments
	pagelines_after_pl_comments
	
	POST NAVIGATION
	pagelines_before_postnav
	pagelines_inside_top_postnav
	pagelines_inside_bottom_postnav
	pagelines_after_postnav
	
	POST AUTHOR INFORMATION
	pagelines_before_postauthor
	pagelines_inside_top_postauthor
	pagelines_inside_bottom_postauthor
	pagelines_after_postauthor
	
	POSTS INFO
	pagelines_before_postsinfo
	pagelines__inside_top_postsinfo
	pagelines_inside_bottom_postsinfo
	pagelines_after_postsinfo
	
	PAGINATION
	pagelines_before_pagination
	pagelines_inside_top_pagination
	inside_bottom_pagination
	pagelines_after_pagination
	
	CONTENT SHARING TOOL
	pagelines_before_sharebar
	pagelines_inside_top_sharebar
	pagelines_inside_bottom_sharebar
	pagelines_after_sharebar
	
	NOPOSTS
	pagelines_before_noposts
	pagelines_inside_top_noposts
	pagelines_inside_bottom_noposts
	pagelines_after_noposts
	
	
	SIDEBAR
	pagelines_before_sidebar_wrap
	pagelines_after_sidebar_wrap
	
	PRIMARY SIDEBAR
	pagelines_before_sidebar_primary
	pagelines_inside_top_sidebar_primary
	pagelines_inside_bottom_sidebar_primary
	pagelines_after_sidebar_primary
	
	SECONDARY SIDEBAR
	pagelines_before_sidebar_secondary
	pagelines_inside_top_sidebar_secondary
	pagelines_inside_bottom_sidebar_secondary
	pagelines_after_sidebar_secondary
	
	TERTIARY SIDEBAR
	pagelines_before_sidebar_tertiary
	pagelines_inside_top_sidebar_tertiary
	pagelines_inside_bottom_sidebar_tertiary
	pagelines_after_sidebar_tertiary
	
	TWITTERBAR
	pagelines_before_twitterbar
	pagelines_inside_top_twitterbar
	pagelines_inside_bottom_twitterbar
	pagelines_after_twitterbar
	
	UNIVERSAL SIDEBAR
	pagelines_before_sidebar_universal
	pagelines_inside_top_sidebar_universal
	pagelines_inside_bottom_sidebar_universal
	
	FULLWIDTH SIDEBAR
	pagelines_before_fullwidth_sidebar
	pagelines_inside_top_fullwidth_sidebar
	pagelines_inside_bottom_fullwidth_sidebar
	pagelines_after_fullwidth_sidebar
	
	CONTENT SIDEBAR
	pagelines_before_content_sidebar
	pagelines_inside_top_content_sidebar
	pagelines_inside_bottom_content_sidebar
	pagelines_after_content_sidebar
	
	FOOTER
	pagelines_after_footer
	
	BOXES
	pagelines_before_boxes
	pagelines_inside_top_boxes
	pagelines_inside_bottom_boxes
	pagelines_after_boxes
	pagelines_box_inside_bottom
	
	SOAPBOX
	pagelines_before_soapbox
	pagelines_inside_top_soapbox
	pagelines_inside_bottom_soapbox
	pagelines_after_soapbox
	pagelines_soapbox_links
	pagelines_soapbox_inside_bottom
	
	HIGHLIGHT
	pagelines_before_highlight
	pagelines_inside_top_hightlight
	pagelines_inside_bottom_hightlight
	pagelines_after_highlight
	
	CALLOUT
	pagelines_before_callout
	pagelines_inside_top_callout
	pagelines_inside_bottom_callout
	pagelines_after_callout
	
	BRANDNAV
	pagelines_before_brandnav
	pagelines_inside_top_brandnav
	pagelines_inside_bottom_brandnav
	pagelines_after_brandnav
	brandnav_after_brand
	brandnav_after_nav
	
	BREADCRUMB
	pagelines_before_breadcrumb
	pagelines_inside_top_breadcrumb
	pagelines_inside_bottom_breadcrumb
	pagelines_after_breadcrumb
	
	FEATURES
	pagelines_before_feature
	pagelines_inside_top_feature
	pagelines_inside_bottom_feautre
	pagelines_after_feature
	pagelines_feature_before
	pagelines_fcontent_before
	pagelines_feature_text_top
	pagelines_feature_text_bottom
	pagelines_fcontent_after
	pagelines_feature_media_top
	pagelines_feature_after
	pagelines_feature_nav_before
	
	CAROUSEL
	pagelines_before_carousel
	pagelines_inside_top_carousel
	pagelines_inside_bottom_carousel
	pagelines_after_carousel
	pagelines_carousel_list
	
	BANNERS
	pagelines_before_banners
	pagelines_inside_top_banners
	pagelines_inside_bottom_banners
	pagelines_after_banners
	
	PULL QUOTE SECTION
	pagelines_before_pullquote
	pagelines_inside_top_pullquote
	pagelines_inside_bottom_pullquote
	pagelines_after_pullquote
	
	BASE SIDEBAR
	pagelines_before_sidebar_base
	pagelines_inside_top_sidebar_base
	pagelines_inside_bottom_sidebar_base
	pagelines_after_sidebar_base
	
	MOREFOOT SIDEBARS
	pagelines_before_morefoot
	pagelines_inside_top_morefoot
	pagelines_inside_bottom_morefoot
	pagelines_after_morefoot
	
	FOOTER SIDEBARS
	pagelines_before_footcols
	pagelines_inside_top_footcols
	pagelines_inside_bottom_footcols
	pagelines_after_footcols
	
	SIMPLE FOOTER NAVIGATION
	pagelines_before_simple_footer_nav
	pagelines_inside_top_simple_footer_nav
	pagelines_inside_bottom_simple_footer_nav
	pagelines_after_simple_footer_nav
	
	SHAREBAR
	pagelines_before_sharebar
	pagelinse_after_sharebar
	
	TWITTERBAR
	pagelines_before_twitterbar_text
	
	OPTIONS
	pagelines_before_optionUI
	
	DOCUMENT
	pagelines_code_before_head


#5 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 03 August 2011 - 07:21 PM

Change rss url with filters
 
	add_filter( 'pagelines_branding_rssurl', create_function('', 'return "http://myrssurl.com";') );


#6 kastelic

kastelic

    Advocate

  • Members

  • 3081 posts
  • Country: Country Flag

Posted 03 August 2011 - 10:08 PM

Enables custom post types to appear on home page:
 
		// enables any post type
		add_action('pagelines_inside_top_theloop' ,'enable_custom');
		function enable_custom(){
			if (is_home()){
				$args = array(
					'post_type'=> 'any',
				);
				query_posts($args);
			}
		}
	


#7 kastelic

kastelic

    Advocate

  • Members

  • 3081 posts
  • Country: Country Flag

Posted 04 August 2011 - 07:49 PM

Crap, wish I could delete or edit that last post. Its wrong because pagination doesn't work and it enables the post type "page" as well. Its better to specify the post types by name.
Here is the code that fixes both issues (enabling a post type called "hotels"):
 
		//Adds Hotels custom post type to home page loop
		add_action('pagelines_inside_top_theloop' ,'enable_hotels');
		function enable_hotels(){
			if (is_home()){
				$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; //fixes pagination
				$args = array(
					'post_type'=> array('post','hotels'),
					'paged'=> $paged
				);
				query_posts($args);
			}
		}
	


#8 Simon_P

Simon_P

    Messer

  • Administrators



  • 8388607 posts
  • LocationDevon
  • Framework Version:2.1.1
  • Country: Country Flag

Posted 03 September 2011 - 03:42 PM

 
	function my_recent_posts_shortcode($atts){
		extract(shortcode_atts(array('limit' => 5, 'cat' => ''), $atts));
	
		$q = new WP_Query('cat=' . $cat . '&posts_per_page=' . $limit);
	
		$list = '';
	
		while($q->have_posts()) : $q->the_post();
	
			$list .= sprintf( '<a href="%1$s">%2$s</a>', get_permalink(), get_the_title() );
	
		endwhile;
	
		wp_reset_query();
	
		return $list;
	}
	add_shortcode('recent-posts', 'my_recent_posts_shortcode');
usage [recent-posts] returns 5 posts from default cat [recent-posts cat="26"] return 5 from cat 6 [recent-posts limit="3" cat="26"] can you guess? ENJOY

#9 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 03 September 2011 - 06:09 PM

That last one posted by Simon is incredibly helpful in showing a list of recent posts by category. The shortcode may be used in boxes and other locations. I can attest to it as it helped my site incredibly. Thanks so much Simon!