Jump to content

Archived

This topic is now archived and is closed to further replies.

glennyboy

Pagelines Templates as Registered Wordpress Templates

Recommended Posts

glennyboy    9
glennyboy

Hi

 

Pagelines templates don't seem to register as official Wordpress templates and so can't be referenced for hook/by other plugins etc. If I am correct how can they be registered into Wordpress as official templates?

 

Thanks

 

Glennyboy

Share this post


Link to post
Share on other sites
Simon    247
Simon
What exactly are you trying to do?

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

I'm using ACF Advanced Custom Fields and need to apply custom fields only if the Wordpress template = specific template. It only picks up the Wordpress 'Default' template as the pagelines templates don't register.

Share this post


Link to post
Share on other sites
Simon    247
Simon
Interesting, let me have a look.

Share this post


Link to post
Share on other sites
Simon    247
Simon
Well I had a look. The plugin you mention does not allow for filtering the templates list. Neither does WordPress. The plugin authors may be able to add a filter...

Anyway, if there was a way to filter the templates that appear in that dropdown then adding the PL ones would be pretty straight forward.
Then its just a case of adding a 2nd filter to intercept the call to the page/post_meta to see what template is actually running.

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

Hi Simon_P

 

As I noted it does allow filtering of the template list. When you create a Custom Field Group there is an option for 'Location' and this allows a number of conditional rules. One of which is Page 'Page Template'. As discussed that only shows 'Default Template'.

 

As this is the case any idea what the filter would be?

 

Glennyboy

Share this post


Link to post
Share on other sites
Simon    247
Simon
There isnt a filter for the page templates, i checked the plugins sourcecode, it uses get_page_templates, WP returns and array of templates in the current theme. get_page_templates is NOT filterable, the the plugin author needs to add a filter to allow you to overide that as WP will not add a filter.

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

It also does have a page templates function:-

/*
	*  rule_match_page_template
	*
	*  This function will match a location rule and return true or false
	*
	*  @type	filter
	*  @date	3/01/13
	*  @since	3.5.7
	*
	*  @param	$match (boolean) 
	*  @param	$rule (array)
	*  @return	$options (array)
	*/
		
	function rule_match_page_template( $match, $rule, $options ) {
		
		// vars
		$page_template = $options['page_template'];
		
		
		// get page template
		if( ! $page_template ) {
		
			$page_template = get_post_meta( $options['post_id'], '_wp_page_template', true );
			
		}
		
		
		// get page template again
		if( ! $page_template ) {
			
			$post_type = $options['post_type'];

			if( !$post_type ) {
			
				$post_type = get_post_type( $options['post_id'] );
				
			}
			
			if( $post_type == 'page' ) {
			
				$page_template = "default";
				
			}
		}
	
		// compare
        if( $rule['operator'] == "==" ) {
        
        	$match = ( $page_template === $rule['value'] );
        
        } elseif( $rule['operator'] == "!=" ) {
        	
        	$match = ( $page_template !== $rule['value'] );
        	
        }
        
        
        // return
        return $match;

	}

This is in /core/location.php

 

Cheers

Glennyboy

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

and this is the filter

add_filter( 'acf/location/rule_match/page_template',	array($this, 'rule_match_page_template'), 10, 3 );

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

Can anyone please finish of the function below to "get a list of the page line pages"

add_filter('acf/location/rule_types', 'acf_location_rules_types');
function acf_location_rules_types( $choices )
{
$choices['Page']['pageline'] = 'Pageline Page';

return $choices;
}

// Find pages

add_filter('acf/location/rule_values/pagelinepage', 'acf_location_rules_values_pagelinepage');
function acf_location_rules_values_pagelinepage( $choices )
{
//get a list of the pageline pages

// add a name for the page to choices

return $choices;
}

//Then add the match rule

add_filter('acf/location/rule_match/user', 'acf_location_rules_match_user', 10, 3);
function acf_location_rules_match_user( $match, $rule, $options )
{

// check if is correct pageline page, set match to true if it is

return $match;
}

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

Can someone at Pagelines please advise how to get a list of the page line pages. The ACF developers have done the rest!

Share this post


Link to post
Share on other sites
Simon    247
Simon
$custom_template_handler = new PLCustomTemplates;
 
foreach( $custom_template_handler->get_all() as $index => $t){
 
// $index is template slug
// $t['name'] is template nice name.
}

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

I'm adding that code after "//get a list of the page line pages" is that correct - pulls a blank right now... 

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

Any update please - how do you filter Pagelines Templates?

Share this post


Link to post
Share on other sites
Simon    247
Simon

You want to filter them?

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

I want to fill in the blank area above to pull up a list of current pagelines templates, which from the developer code I would envisage should come below:-

 

//get a list of the pageline pages

Share this post


Link to post
Share on other sites
Simon    247
Simon

//get a list of the pageline pages what does that mean exactly? A list, an array, an object, comma separated? The code i gave you returns an array and the foreach loop loops through that array.

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

Hi Simon_P

 

The code you originally provided did not output the array for the list of Pagelines Pages. The ACG plugin successfully outputs 'normal' Wordpress Templates', Posts Types etc, but due to the make-up of DMS templates these cannot be listed. The author of ACG provided the code above but added the following comment:-

 

"you would have to find a way to identify a pagelines Page.

I am unfarmiliar with the product myself so i don't really have any idea how that could be done.
But once you have that you create your rule."

Share this post


Link to post
Share on other sites
Simon    247
Simon

identify a pagelines page? they will all be pagelines pages??

 

Are you just trying to display post meta on certain pages depending on what template is running on the page?

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

Sorry that was their code - yes I meant display list of pagelines 'templates'. Yes you are correct I only want to show specific custom meta/fields on a page/custom post depending on whether it is a specific pagelines template. ACF provides a filter for this and currently pagelines templates don't show - just default Wordpress ones.

 

Ideally I would need a function to add Pagelines templates into the list of Wordpress templates. That would solve the issue here and also provide a full list of templates for other plugins etc.

Share this post


Link to post
Share on other sites
Simon    247
Simon

Ideally I would need a function to add Pagelines templates into the list of Wordpress templates. That would solve the issue here and also provide a full list of templates for other plugins etc.

As I mentioned earlier, WordPress do not provide any filters to do that, this is why you have to mess about with this plugin.

 

There may be a simpler way to do this, if i knew what you were trying to add and where.

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

Hi Simon_P

 

I'd say I have been pretty clear and in earlier posts I explained about the ACF Location Rules that provide a number of conditional filters for displaying custom fields.

 

http://www.advancedcustomfields.com/resources/tutorials/custom-location-rules/  - please check this out

 

Extending this with a list of Pagelines templates is something they can't assist with, but as far as I asm aware they have provided everything else (a function missing the Pagelines template list bit). I've added the code I provided to my functions.php page and indeed the new location for Pageliens Template shows, but as we don't know how to list pagelines templates then the list is currently blank. 

 

This is something that Pagelines need to fill in the blank on as it's not related to Wordpress and neither is it directly related to ACF.

 

Glennyboy

Share this post


Link to post
Share on other sites
Simon    247
Simon

OK clearly you insist on using this plugin to simply show a post meta field on a certain page if a certain template is showing up.

 

I'll install the plugin and let you know what I find.

Share this post


Link to post
Share on other sites
glennyboy    9
glennyboy

Hi Simon_P

 

I use the plugin not just for the custom fields, but also the great interface that it offers which perhaps you'll find on install.

 

thanks

Glennyboy

Share this post


Link to post
Share on other sites

  • Similar Content

    • DonRicardoRVM
      By DonRicardoRVM+
        First of all, sorry for my bad English.  I am developing an ecommeece with wp, woocommerce, PL5 and quickshop, and I need to do some changes in the simple product grid. I want to change the classes of some divs, but I can't find the templates. 
      Also, I change the grid of the category products pages, but I didn't make it correctly.
      This is the cat archive's: http://globosdemar.com/wp/categoria-producto/camisetas-para-ninos-y-ninas/
      Can you help me?
    • poseyg
      By poseyg+
      Could someone explain exactly how the new template sync works or what it is suppose to do?
    • Anthony King
      By Anthony King+
      I have to say that I like the Layout and the Template based sections. Some of them are really impressive.
      One of the things that I would like to request though is the possibility of being able to dynamically rearrange the layout.
      An example of what I am talking about is take the Agency Section. It's current layout starts with the
      Splash Module then the Portfolio Module then the Service Module and so on and so forth.
      What would be great is if we were able to move these modules around. I.e have the Service Module first
      then maybe the Splash, and then the portfolio.
       
    • flourishdesignstudio
      By flourishdesignstudio
      I am using Jigoshop on a website that also uses PL5 and am running into an issue where the store pages do not allow me to use the PL5 editor. Is anyone else having this problem or know if a solution? 
      When I open the Chrome console I see the following error:
      site.js?ver=b199df:5 Uncaught ReferenceError: PLData is not defined
          at Object.setMasterModel (site.js?ver=b199df:5)
          at Object.init (site.js?ver=b199df:5)
          at HTMLDocument.<anonymous> (site.js?ver=b199df:5)
          at i (jquery.js?ver=1.12.4:2)
          at Object.fireWith [as resolveWith] (jquery.js?ver=1.12.4:2)
          at Function.ready (jquery.js?ver=1.12.4:2)
          at HTMLDocument.K (jquery.js?ver=1.12.4:2)
       
      The problem can be seen here: http://fingerlakesdistilling.com/shop/ where the sidebar, footer, and header do not show up. Any thoughts?
      Thanks so much!
    • Queue-it
      By Queue-it+
      I've created a new post category "Success stories" with Custom Post type UI. (in order to have a different layout for a different post category - blog post one layout, success stories another layout).
      New category "success stories" are "detached" from all the other posts, so they have a different layout, but the problem is that all of the success stories are also having the same exact content.
      So whenever I edit content (e.g. change body text) on one of success story posts, it also changes the content (body text) for all other Success story category posts. 
       
      Question: Is there a way to retain this separate category with it's own layout, and have a different content for each individual post? I'm using Pagelins templates. 
       Thanks in advance.
×