• I have several sidebars created with filters for different pages. I have setup a new sidebar with a custom template filter, however it does not show up. Only the standard sidebar shows up.

    I tried using get_template(‘my-sidebar’) in my template but that does not work either.

    Any help much appreciated….

    Thomas Herold

    http://wordpress.org/plugins/content-aware-sidebars/

Viewing 15 replies - 1 through 15 (of 20 total)
  • Thread Starter herold

    (@herold)

    Maybe you could include a special option for pod pages…

    Thread Starter herold

    (@herold)

    It looks like this has to do with being a Pod page. All other pages and filters are working fine. I have a bit of php knowledge. Could you guide me in the right direction on how to program this?

    Thread Starter herold

    (@herold)

    Here is a link with some code from Scott, who is the author of Pod pages. This may help

    http://wordpress.org/support/topic/filter-by-pods-pages?replies=2#post-4887542

    Plugin Author Joachim Jensen

    (@intoxstudio)

    Currently Pods is not supported by the plugin, but it should not be a problem to implement it. The content options in Content Aware Sidebars are each made by a “module” that automatically adds some filters and actions (later being called by the plugin).

    As of version 1.3.5 it is not possible to add a module yourself, unless you add the code to the plugin directory (content-aware-sidebars/modules), but it is possible to use the actions and filters. I recommend using the module-way though.

    All you have to do is
    1. add a new module file (e.g. modules/pods.php)
    2. extend the CASModule. It is required that your filename and class name look the same (e.g. CASModule_pods)
    3. make the module recognize and handle pods pages (see e.g. how the wpml and bp_member modules are created and the link you provided before)
    4. register the module (this does not have to be in the plugin directory):

    add_filter('cas-module-pre-deploy','add_pods_to_cas');
    function add_pods_to_cas($modules) {
    $modules['pods'] = true;
    return $modules;
    }

    It might seem like a lot, and I promise that it will be cleaner in version 2.0. Please let me know if you need more information.

    Thread Starter herold

    (@herold)

    Hello Joachim,

    Thank you for you reply and the helpful instructions. I will add a new module and see how it goes.

    Thread Starter herold

    (@herold)

    I got it as far as listing the Pod pages but I don’t know how to filter or search….please have a look:

    * @package Content Aware Sidebars
     * @author Joachim Jensen <jv@intox.dk>
     */
    
    /**
     *
     * Pods Module
     *
     * Detects if current content is:
     * a) any or specific pods pages
     *
     */
    class CASModule_pods extends CASModule {
    
    	/**
    	 * Constructor
    	 */
    	public function __construct() {
    		parent::__construct();
    		$this->id = 'pods';
    		$this->name = __('Pods Pages',ContentAwareSidebars::DOMAIN);
    
    	}
    
    	/**
    	 * Get pods pages
    	 * @return array
    	 */
    	protected function _get_content() {
    
    		if ( function_exists( 'pods_api' ) ) {
    
        		// Get PodsAPI
        		$api = pods_api();
    
    		    // Get Pod Pages
        		$pod_pages = $api->load_pages();
    
    		    $pod_page_list = array();
    
    		    foreach ( $pod_pages as $pod_page ) {
            		$pod_page_list[] = $pod_page[ 'name' ];
        		}
    		}
    
    		return $pod_page_list;
    
    		/*
    		return array(
    				'Page 1'	=> __('Page 1', ContentAwareSidebars::DOMAIN),
    				'Page 2'	=> __('Page 2', ContentAwareSidebars::DOMAIN),
    				'Page 3'	=> __('Page 3', ContentAwareSidebars::DOMAIN)
    		);
    		*/
    
    	}
    
    	/**
    	 * Determine if content is relevant
    	 * @return boolean
    	 */
    	public function is_content() {
    		return true;
    	}
    
    	/**
    	 * Query where
    	 * @return string
    	 */
    	public function db_where() {
    		return "(bb_profile.meta_value = 'bb_profile' OR bb_profile.meta_value = '".bbp_get_displayed_user_id()."')";
    	}
    
    	/**
    	 * Meta box content
    	 * @global object $post
    	 * @return void
    	 */
    	public function meta_box_content() {
    		global $post;
    
    		echo '<h4><a href="#">'.$this->name.'</a></h4>'."\n";
    		echo '<div class="cas-rule-content" id="cas-' . $this->id . '">'. "\n";
    		$meta = get_post_meta($post->ID, ContentAwareSidebars::PREFIX . $this->id, false);
    		$current = $meta != '' ? $meta : array();
    
    		echo '<ul id="cas-list-' . $this->id . '" class="cas-contentlist categorychecklist form-no-clear">'. "\n";
    		foreach ($this->_get_content() as $id => $name) {
    			echo '<li><label><input type="checkbox" name="' . $this->id . '[]" value="' . $id . '"' . (in_array($id, $current) ? ' checked="checked"' : '') . ' /> ' . $name . '</label></li>' . "\n";
    		}
    		echo '</ul>'. "\n";
    		echo '</div>'. "\n";
    	}
    
    }

    Maybe try this:

    $pod_page_list[ $pod_page[ 'name' ] ] = $pod_page[ 'name' ];

    Thread Starter herold

    (@herold)

    Hello Scott,

    Thank you – not sure where this will go. I think I first have to work on the return array that lists the pod pages. It looks like it needs to be in a certain format. See below:

    /*
    		return array(
    				'Page 1'	=> __('Page 1', ContentAwareSidebars::DOMAIN),
    				'Page 2'	=> __('Page 2', ContentAwareSidebars::DOMAIN),
    				'Page 3'	=> __('Page 3', ContentAwareSidebars::DOMAIN)
    		);
    		*/
    Plugin Author Joachim Jensen

    (@intoxstudio)

    @scott

    That is correct. The function requires a unique key that idenfities a specific item, in this case a pod page. This change should be enough to make it possible to save/remove a pod page to/from a sidebar.

    Does is_pod_page() require a parameter, or will it default to the current pod (the pod in The Loop)?

    If so, this should be used to determine if we are currently viewing a pod page:

    public function is_content() {
    	return is_pod_page();
    }

    Now, in order to get the sidebars that should be displayed with a specific/all pod pages, we need to get the id/name of the current pod page.

    Can it be retrieved by something like get_the_pod()? or similar?

    Thanks for elaborating. It could be nice to include this module as a part of Content Aware Sidebars πŸ™‚

    Thread Starter herold

    (@herold)

    In pods you can add code into a pre code form. Here you can define any variable that can be picked up before calling the sidebar. That could be used as an ID. for example:

    $pod_page_id = 5;

    The pods plugin for Content Aware Sidebars can read this variable and knows that it is a pod page.

    Thread Starter herold

    (@herold)

    I have the pods plugin as far as it works for any pod page selected. This is pretty good so far. Maybe you can help adding the code to expand on selecting sidebars depending on a specific pod page.

    Here is the working code so far:

    <?php
    /**
     * @package Content Aware Sidebars
     * @author Joachim Jensen <jv@intox.dk>
     */
    
    /**
     *
     * Pods Module
     *
     * Detects if current content is:
     * a) any or specific pods pages
     *
     */
    class CASModule_pods extends CASModule {
    
    	/**
    	 * Constructor
    	 */
    	public function __construct() {
    		parent::__construct();
    		$this->id = 'pods';
    		$this->name = __('Pods Pages',ContentAwareSidebars::DOMAIN);
    
    	}
    
    	/**
    	 * Get pods pages
    	 * @return array
    	 */
    	protected function _get_content() {
    
    		if ( function_exists( 'pods_api' ) ) {
    
        		// Get PodsAPI
        		$api = pods_api();
    
    		    // Get Pod Pages
        		$pod_pages = $api->load_pages();
    
    		    $pod_page_list = array();
    
    		    foreach ( $pod_pages as $pod_page ) {
            		$pod_page_list[] = $pod_page[ 'name' ];
        		}
    		}
    
    		return $pod_page_list;
    	}
    
    	/**
    	 * Determine if content is relevant
    	 * @return boolean
    	 */
    	public function is_content() {
    		return is_pod_page();
    	}
    
    	/**
    	 * Where query
    	 * @return string
    	 */
    	public function db_where() {
    		return true;
    
    	}
    
    	/**
    	 * Meta box content
    	 * @global object $post
    	 * @return void
    	 */
    	public function meta_box_content() {
    		global $post;
    
    		echo '<h4><a href="#">'.$this->name.'</a></h4>'."\n";
    		echo '<div class="cas-rule-content" id="cas-' . $this->id . '">'. "\n";
    		$meta = get_post_meta($post->ID, ContentAwareSidebars::PREFIX . $this->id, false);
    		$current = $meta != '' ? $meta : array();
    
    		echo '<ul id="cas-list-' . $this->id . '" class="cas-contentlist categorychecklist form-no-clear">'. "\n";
    		foreach ($this->_get_content() as $id => $name) {
    			echo '<li><label><input type="checkbox" name="' . $this->id . '[]" value="' . $id . '"' . (in_array($id, $current) ? ' checked="checked"' : '') . ' /> ' . $name . '</label></li>' . "\n";
    		}
    		echo '</ul>'. "\n";
    		echo '</div>'. "\n";
    	}
    
    }
    Thread Starter herold

    (@herold)

    Ok, I put another few hours of work in and I have a working version that can now select a sidebar depending on a specific pods page. However the code needs to be cleaned up.

    Here are the things that need to be better coded:
    – Name of pod is url – used (/*) filter ?
    – pods_url_variable(‘first’, uri) may not work is pod is ‘second’

    Here is the code:

    <?php
    /**
     * @package Content Aware Sidebars
     * @author Joachim Jensen <jv@intox.dk>
     */
    
    /**
     *
     * Pods Module
     *
     * Detects if current content is:
     * a) any or specific pods pages
     *
     */
    class CASModule_pods extends CASModule {
    
    	/**
    	 * Constructor
    	 */
    	public function __construct() {
    		parent::__construct();
    		$this->id = 'pods';
    		$this->name = __('Pods Pages',ContentAwareSidebars::DOMAIN);
    
    	}
    
    	/**
    	 * Get pods pages
    	 * @return array
    	 */
    	protected function _get_content() {
    
    		if ( function_exists( 'pods_api' ) ) {
    
        		// Get PodsAPI
        		$api = pods_api();
    
    		    // Get Pod Pages
        		$pod_pages = $api->load_pages();
    
    		    $pod_page_list = array();
    
    		    foreach ( $pod_pages as $pod_page ) {
            		$pod_page_list[] = str_replace("/*", "", $pod_page[ 'name' ]);
        		}
    		}
    
    		return $pod_page_list;
    	}
    
    	/**
    	 * Determine if content is relevant
    	 * @return boolean
    	 */
    	public function is_content() {
    		return is_pod_page();
    	}
    
    	/**
    	 * Where query
    	 * @return string
    	 */
    	public function db_where() {
    		$pods_name = pods_url_variable('first', uri);
    		return "(pods.meta_value IS NULL OR pods.meta_value = '".$pods_name."')";
    
    	}
    
    	/**
    	 * Meta box content
    	 * @global object $post
    	 * @return void
    	 */
    	public function meta_box_content() {
    		global $post;
    
    		echo '<h4><a href="#">'.$this->name.'</a></h4>'."\n";
    		echo '<div class="cas-rule-content" id="cas-' . $this->id . '">'. "\n";
    		$meta = get_post_meta($post->ID, ContentAwareSidebars::PREFIX . $this->id, false);
    		$current = $meta != '' ? $meta : array();
    
    		echo '<ul id="cas-list-' . $this->id . '" class="cas-contentlist categorychecklist form-no-clear">'. "\n";
    		foreach ($this->_get_content() as $id => $name) {
    			echo '<li><label><input type="checkbox" name="' . $this->id . '[]" value="' . $name . '"' . (in_array($name, $current) ? ' checked="checked"' : '') . ' /> ' . $name . '</label></li>' . "\n";
    		}
    		echo '</ul>'. "\n";
    		echo '</div>'. "\n";
    	}
    
    }

    Herold, thanks for writing this and Joachim thank you for your help. I will test it out tomorrow and report back. Is it intended to work for Pods Pages only or should it work with Pods content shown via theme templates as well?

    Thread Starter herold

    (@herold)

    It is for Pods Pages only as they were not working with a dynamic sidebar. Pods via theme templates work fine as they are recognized as WordPress pages.

    I had to dig into this because of SEO issues. If you use dynamic content from Pods via WordPress Theme you can’t have dynamic page titles set, because the title is set by the WordPress page.

    Thread Starter herold

    (@herold)

    Here is a better way to list the Pods Pages:

    foreach ( $pod_pages as $pod_page ) {
       $pod_page_list[$pod_page[ 'slug' ]] = $pod_page[ 'name' ];
    }

    This way we don’t need to filter the ‘/*’ signs, which I mentioned above.

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Sidebar with Costum Template Filter Not Showing’ is closed to new replies.