Strict Standards: Redefining already defined constructor for class bbdb in /home/themes/public_html/forums/bb-includes/db-mysql.php on line 12

Strict Standards: Declaration of BB_Walker_Blank::start_lvl() should be compatible with BB_Walker::start_lvl($output) in /home/themes/public_html/forums/bb-includes/classes.php on line 1127

Strict Standards: Declaration of BB_Walker_Blank::end_lvl() should be compatible with BB_Walker::end_lvl($output) in /home/themes/public_html/forums/bb-includes/classes.php on line 1127

Strict Standards: Declaration of BB_Walker_Blank::start_el() should be compatible with BB_Walker::start_el($output) in /home/themes/public_html/forums/bb-includes/classes.php on line 1127

Strict Standards: Declaration of BB_Walker_Blank::end_el() should be compatible with BB_Walker::end_el($output) in /home/themes/public_html/forums/bb-includes/classes.php on line 1127
Add post_meta custom field data only when fields are true « ThemeShaper Forums

ThemeShaper Forums » Thematic

[closed]

Add post_meta custom field data only when fields are true

(3 posts)
  • Started 3 years ago by candregg
  • Latest reply from candregg
  • This topic is resolved

  1. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 440

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 510

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 512


    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 440

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 510

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 512
    candregg

    Member

    I'm a relative noob trying to filter post content selectively.

    In my installation, only posts in one category include the custom fields "sponsor text" and "sponsor link".

    If I create a custom category loop by category, the custom fields do not show up in single posts; if I apply it globally, then the special div to hold the meta data appears on ALL posts, even where the custom field data doesn't exist.

    Here is the global function:

    //  Custom Category Loop 
    
    function remove_category_loop(){ //  first remove the thematic action
        remove_action('thematic_categoryloop', 'thematic_category_loop');
        remove_action('thematic_archiveloop', 'thematic_archive_loop');
    }
    add_action('init','remove_category_loop');
    
    function child_category_loop() { // now rebuild your version of the action
    
     while (have_posts()) : the_post();
    
    	 global $post;
         $sponsortext = get_post_meta($post->ID , 'sponsor', true);
    	 $sponsorlink = get_post_meta($post->ID , 'sponsorlink', true);
    	 ?>
    
            <div id="post-<?php the_ID(); ?>" class="<?php thematic_post_class(); ?>">
               <?php thematic_postheader(); ?>
               <div class="entry-content">
                 <?php thematic_content(); ?>
                 <div id="sponsor">
    	<p><?php echo $sponsortext; ?></p>
        <p>For more information visit the website, <a href="http://<?php echo $sponsorlink; ?>" target="_blank">http://<?php echo $sponsorlink; ?></a></p>
        </div>
               </div>
               <?php thematic_postfooter(); ?>
            </div><!-- .post -->
    
         <?php endwhile;
    }
    
    add_action('thematic_categoryloop', 'child_category_loop');
    add_action('thematic_archiveloop', 'child_category_loop');

    This code works great for the one category page, http://seacliffmm.com/prod/centurion/category/clients-testimonials/,
    But not for the general blog category page, http://seacliffmm.com/prod/centurion/category/news/

    I'm sure the answer is an if-else construction,but so far I haven't been able to code one that works.

    Please advise, if possible.

    Posted 3 years ago #

  2. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 440

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 510

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 512


    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 440

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 510

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 512
    helgatheviking

    Moderator

    "if I apply it globally"

    does that mean you tried filtering the_content()?

    which is what i'd do and just add in a condition to test if $sponsortext exists

    function add_after_content($content) {
    
      global $post;
      $sponsortext = get_post_meta($post->ID , 'sponsor', true);
      $sponsorlink = get_post_meta($post->ID , 'sponsorlink', true);
    
      if($sponsortext && $sponsorlink){
        $sponsor = '<div id="sponsor">';
        $sponsor .= '<p>'. $sponsortext.'</p>';
        $sponsor .= '<p>For more information visit the website, <a href="http://'.$sponsorlink.'>" target="_blank">http://'.$sponsorlink.'</a></p>';
        $sponsor .= '</div>';
    
        $content .= $sponsor ;
      }
      return $content;
    }
    add_filter('the_content', add_after_content);

    totally untested, you might need to escape the backslashes... i'm not sure, but i think the concept is right.

    ps- you can now use

    function childtheme_override_category_loop()

    and you don't need to add or remove any actions. it's magic.

    Posted 3 years ago #

  3. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 440

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 510

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 512


    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 440

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 510

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/themes/public_html/forums/bb-includes/kses.php on line 512
    candregg

    Member

    For the most part, that worked like a charm: http://seacliffmm.com/prod/centurion/clients-testimonials/build-a-bear-workshop/. One remaining issue is that the &sponsorlink call is generating an extra character string, %3e, that is messing up the actual sponsor's links. Any idea where that's coming from?

    Other than that, it's beautiful. I knew some kind of conditional test was the answer; I just kept messing up the syntax for so many hours that I got frustrated. Thanks for demonstrating it so clearly.

    Yes, I've seen the function childtheme_override_category_loop() in the newer version of thematic, but have not (until now) had occasion to use it.

    Will file your magic and tips for future use.

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.


Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method GA_Filter::spool_analytics() should not be called statically in /home/themes/public_html/forums/bb-includes/wp-functions.php on line 586

Strict Standards: Non-static method GA_Filter::spool_this() should not be called statically in /home/themes/public_html/forums/my-plugins/googleanalytics.php on line 183