NEW FIX! Works for custom post type loops.
-
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/
- The topic ‘NEW FIX! Works for custom post type loops.’ is closed to new replies.