• Resolved Dan Petty

    (@dpetty)


    Hi,

    I couldn’t find anything that quite related to this on the forums, and I am fairly limited in my coding knowledge. I’m looking to set up some sort of condition such that if the author of a post is “admin” then a custom field I have designated as “hpbyline” is displayed. Otherwise, the designated author is displayed.

    I have something close already, that works this way: If the author is “admin”, then NOTHING is displayed. How would I modify it so that
    <?php echo c2c_get_custom(‘hpbyline’); ?> is displayed instead?

    Thanks for the help!

    <?php
                                   $auth = get_the_author();
                               if ($auth != 'admin') :
                               ?>
                      <div class="byline">
                               By <?php if(function_exists('coauthors_posts_links'))
                                       coauthors_posts_links();
                               else
                                  the_author_posts_link(); ?>
                      </div>
    
                      <div class="bytitle">
                                <?php echo c2c_get_custom('Bytitle'); ?>
                      </div>
                                <?php endif; ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • <div class="byline">
    <?php
    $auth = get_the_author();
    if ($auth == 'admin') { ?>
      echo c2c_get_custom('hpbyline');
    } else {
      the_author_posts_link();
    ?>
    </div>
    
    <div class="bytitle">
        <?php echo c2c_get_custom('Bytitle'); ?>
    </div>

    correction:

    <div class="byline">
    <?php
    $auth = get_the_author();
    if ($auth == 'admin') {
      echo c2c_get_custom('hpbyline');
    } else {
      the_author_posts_link();
    ?>
    </div>
    
    <div class="bytitle">
        <?php echo c2c_get_custom('Bytitle'); ?>
    </div>
    Thread Starter Dan Petty

    (@dpetty)

    Thanks for the reply, stvwif, but it doesn’t seem to be working. Here’s what it spits back.

    Parse error: syntax error, unexpected T_ENDWHILE in /home1/thecolm1/public_html/wp-content/themes/revolution_news-21/archive.php on line 44

    I was also wondering whether it was possible to integrate the “Co-authors” plugin I have activated into your solution. Essentially, if the post author IS NOT “admin” go through these commands (below). There are a lot of if/else statements in this, and I don’t know how to properly code it.

    <?php if(function_exists('coauthors_posts_links'))
                                       coauthors_posts_links();
                               else
                                  the_author_posts_link(); ?>
    Thread Starter Dan Petty

    (@dpetty)

    Can anyone build on stvwif’s response?

    <?php
    if (!$auth == 'admin') {
       if(function_exists('coauthors_posts_links')) {
          coauthors_posts_links();
       } else {
          the_author_posts_link();
       }
    } ?>
    Thread Starter Dan Petty

    (@dpetty)

    Here’s the final solution, after some messing around with code. I’ve tested and it works. Thanks for the help, stvwlf.

    <?php
    $auth = get_the_author();
    if ($auth == 'admin') {
      echo c2c_get_custom('hpbyline');
    } else {
          if(function_exists('coauthors_posts_links')) {
               coauthors_posts_links();
          } else {
               the_author_posts_link();
         }
       }
    ?>
Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Conditional tag question’ is closed to new replies.