• 0

DMS 2 Pagelines Templates as Registered Wordpress Templates


Question

Posted · Report post

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

37 answers to this question

  • 0

Posted · Report post

What exactly are you trying to do?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

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
  • 0

Posted · Report post

Interesting, let me have a look.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

$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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

Any update please - how do you filter Pagelines Templates?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

You want to filter them?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

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
  • 0

Posted · Report post

//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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

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
  • 0

Posted · Report post

The code they supplied would never have worked, here is a working version:

 

https://gist.github.com/Pross/6fc49eeb6cd5064d2909

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now