• Hello everyone,

    I’m trying to get this to work, but cannot…!
    Many thanks for any help. Googling was not efficient at all.
    (I want to override some plugins, so please don’t fall me back to anyone robots meta plug. I have to get it hard coded.)

    It says: if single, page, front page, check if custom fields. If, echo the content.
    If is author, search, echo @this
    If is tag, category, echo @this
    If other template, or no custom fields, echo @this

    My working base is:

    <!-- ####### IMPRESSION DES METAS ROBOTS -->
    <?php if(get_post_meta($post->ID, 'crawl-index', true) ||
    	 get_post_meta($post->ID, 'crawl-dir', true) ||
    	 get_post_meta($post->ID, 'crawl-cache', true) ||
    	 get_post_meta($post->ID, 'crawl-snip', true)
    	 ): ?>
    
    <meta name="robots" content=" 
    
    		<?php if(get_post_meta($post->ID, 'crawl-index', true)): ?>
    		<?php echo get_post_meta($post->ID, 'crawl-index', true); ?>
    		<?php endif; ?>
    
    		<?php if(get_post_meta($post->ID, 'crawl-dir', true)): ?>
    		<?php echo get_post_meta($post->ID, 'crawl-dir', true); ?>
    		<?php endif; ?>
    
    		<?php if(get_post_meta($post->ID, 'crawl-cache', true)): ?>
    		<?php echo get_post_meta($post->ID, 'crawl-cache', true); ?>
    		<?php endif; ?>
    
    		<?php if(get_post_meta($post->ID, 'crawl-snip', true)): ?>
    		<?php echo get_post_meta($post->ID, 'crawl-snip', true); ?>
    		<?php endif; ?>
    
     " />
    
    <?php endif; ?>
    <!-- ####### FIN IMPRESSION DES METAS ROBOTS -->

    The extensive one that I cannot get to work:
    (And yes,this version is surely twist/sucked, but just for showing. Complex conditionnals statements are not my…)

    <!-- ####### IMPRESSION DES METAS ROBOTS -->
    <?php if (is_single() || is_page() || is_front_page() || is_home()) : ?>  
    
    <?php if (get_post_meta($post->ID, 'crawl-index', true) ||
    	 get_post_meta($post->ID, 'crawl-dir', true) ||
    	 get_post_meta($post->ID, 'crawl-cache', true) ||
    	 get_post_meta($post->ID, 'crawl-snip', true)
    	 ): ?>
    
    <meta name="robots" content=" 
    
    		<?php if(get_post_meta($post->ID, 'crawl-index', true)): ?>
    		<?php echo get_post_meta($post->ID, 'crawl-index', true); ?>
    		<?php endif; ?>
    
    		<?php if(get_post_meta($post->ID, 'crawl-dir', true)): ?>
    		<?php echo get_post_meta($post->ID, 'crawl-dir', true); ?>
    		<?php endif; ?>
    
    		<?php if(get_post_meta($post->ID, 'crawl-cache', true)): ?>
    		<?php echo get_post_meta($post->ID, 'crawl-cache', true); ?>
    		<?php endif; ?>
    
    		<?php if(get_post_meta($post->ID, 'crawl-snip', true)): ?>
    		<?php echo get_post_meta($post->ID, 'crawl-snip', true); ?>
    		<?php endif; ?>
    
     " />
    <?php elseif (is_author() || is_search() || is_404()) : ?>
       <meta name="robots" content="noindex,noarchive,follow,noodp,noydir" />
    
    <?php elseif (is_tag() || is_category()) : ?>
      <meta name="robots" content="index,noarchive,follow,noodp,noydir" />   
    
    <?php else : ?>
    	<meta name="robots" content="noindex,noarchive,follow,noodp,noydir" />
    <?php endif; ?>
    <?php endif; ?>
    
    <!-- ####### FIN IMPRESSION DES METAS ROBOTS -->

    Hugh 🙂 !

Viewing 1 replies (of 1 total)
  • What doesn’t work?

    Also, you’d be better off with a single call to get_post_meta(...) instead of the several you have there. Like this, from the Codex.

    Maybe it is just me, but I can’t read that alternate control structure syntax. It confuses the crap out of me. If you are having trouble with complex conditionals, try using braces, and indent your code religiously.

Viewing 1 replies (of 1 total)
  • The topic ‘Advanced conditional use of Meta robots/Custom fields’ is closed to new replies.