• Hi guys,

    Just dropping by a message to let you know i’ve modified the default.php file on my local install to now work with custom post type loops.

    Previously, each time you’d loop through custom posts, it would get the definitions for each content block, set them in the defitioner, but then the next content block definitions would override them, and so on, so the only definitions output in the definitioner were from the last post in the loop.

    Previous version:

    function add_explanatory_dictionary_words() contained the following snippet of code…

    //Add the matched definitions
    			$defs = '
    				<aside id="explanatory-dictionary-page-definitions">
    					<h2> ' . __( 'Definitioner', self::$plugin_slug ) . ' </h2>
    					<dl>
    			';
    
    			foreach( $definitions as $definition ) {
    				$defs .= '
    					<dt class="explanatory-dictionary-definition-' . $definition['id'] . '">' . $definition['word'] . '</dt>
    					<dd class="explanatory-dictionary-definition-' . $definition['id'] . '">' . do_shortcode( $definition['explanation'] ) . '</dd>
    				';
    			}
    			// Add the definitions to the end of the_content
    			$defs .= '
    					</dl>
    				</aside>
    			';
    
    			$this->definitioner = $defs;

    function add_definitioner() looked like so…

    public function add_definitioner() {
    		if( !empty( $this->definitioner ) ) {
    			echo $this->definitioner;
    		}
    	}

    New version:

    I have updated to now look like the following, so the previous definitons are not overridden, just appended.

    //Add the matched definitions
                global $defs;
    
    			$defs .= '';
    
    			foreach( $definitions as $definition ) {
    				$defs .= '
    					<dt class="explanatory-dictionary-definition-' . $definition['id'] . '">' . $definition['word'] . '</dt>
    					<dd class="explanatory-dictionary-definition-' . $definition['id'] . '">' . do_shortcode( $definition['explanation'] ) . '</dd>
    				';
    			}
    
    			$this->definitioner = $defs;

    function add_definitioner() now looks like…

    public function add_definitioner() {
    		if( !empty( $this->definitioner ) ) {
                $definitioner = '
    				<aside id="explanatory-dictionary-page-definitions">
    					<h2> ' . __( 'Definitioner', self::$plugin_slug ) . ' </h2>
    					<dl>
    			';
    
                $definitioner .= $this->definitioner;
    
                // Add the definitions to the end of the_content
                $definitioner .= '
    					</dl>
    				</aside>
    			';
    
    			echo $definitioner;
    		}
    	}

    I feel this could be useful for the plugin going forward and i’m sure there are other developers out there who’ve maybe experienced similar problems and walked away from using it. It’s a simple fix, and maybe something you look at implementing in the next version?

    Cheers,

    Nick

    https://www.ads-software.com/plugins/explanatory-dictionary/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor rjvandoesburg

    (@rjvandoesburg)

    Hey Nick,

    Thanks for the information, looks good!
    I will see if I can implement this in an upcoming update.

    Cheers,
    RJ

    Great fix.We were really struggling with this issue.

    Thread Starter nicholas.fish.fwm

    (@nicholasfishfwm)

    No worries, always good to help out ??

    It had us baffled for a while! Hopefully it will help others in the future.

    Nick

    It would be great if Custom Post Type were supported natively, as I was looking for something like this for a site that heavily uses CPTs for it’s main content.

    Thanks,
    Michael

    Thread Starter nicholas.fish.fwm

    (@nicholasfishfwm)

    Hi Michael,

    I’m glad to see it can be of use to others, it took me a while to figure out what was going on and why it wasn’t working with custom posts, then just dug a little deeper into the plugin and found this.

    Rjvandoesburg, I’ve set up a pull request on github if that will help you, although you might want to test out the changes yourself first of course.

    https://github.com/misfist/misfist/pull/1

    I hope this helps ??

    Cheers,

    Nick

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘NEW FIX! Works for custom post type loops.’ is closed to new replies.