• Resolved markross67

    (@markross67)


    Hello,
    In a previous template, I have a bit of code using a category array, and some conditional statements. I would like to do something similar with my current Template: Twenty Twelve (Child), but I’m not having much luck making it work.

    I would like to include this code in my content.php file:

    if ( in_category( array('Political Cartoons', 'Political Statements' ) )) {
    
    <?php the_time('F jS, Y') ?>
    
    elseif ( in_category( array('Scripture', 'Biblical', 'Biblical Resources', 'Quotes', 'Holidays/Anniversaries', 'Article', 'Political', 'Political Literature', 'Political Terms', 'Admin') )) {
    
    Posted by <?php the_author_posts_link(); ?> | <?php the_time('F jS, Y') ?>
    
    else {
    
    Written by <?php the_author_posts_link(); ?> | <?php the_time('F jS, Y') ?>
    
    endif;

    The problem is, I’m not sure how to make all of the condition statements work correctly. If someone could help me tweak it so that it will work correctly, I would really appreciate it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello markross67,

    here it is.

    <?php if ( in_category( array('Political Cartoons', 'Political Statements') ) ) : ?>
    
    <?php the_time('F jS, Y') ?>
    
    <?php elseif ( in_category( array('Scripture', 'Biblical', 'Biblical Resources', 'Quotes', 'Holidays/Anniversaries', 'Article', 'Political', 'Political Literature', 'Political Terms', 'Admin') ) ) : ?>
    
    Posted by <?php the_author_posts_link(); ?> | <?php the_time('F jS, Y') ?>
    
    <?php else : ?>
    
    Written by <?php the_author_posts_link(); ?> | <?php the_time('F jS, Y') ?>
    
    <?php endif; ?>

    Make sure you have always a closing ?> tag, before opening a new <?php one.

    I hope this helps you.

    Thread Starter markross67

    (@markross67)

    Thank you so much, implenton! It worked perfectly!!! ??

    Here is the final result:

    <!-- Custom: If single post... -->
    <?php if ( is_single() ) : ?>
      <h1 class="entry-title"><?php the_title(); ?></h1>
    
      <?php if ( in_category( array('Political Cartoons', 'Political Statements') ) ) : ?>
    
         <u>Posted <?php the_time('F jS, Y') ?></u>
    
      <?php elseif ( in_category( array('Scripture', 'Biblical', 'Biblical Resources', 'Quotes', 'Holidays/Anniversaries', 'Article', 'Political', 'Political Literature', 'Political Terms', 'Admin') ) ) : ?>
    
        <u>Posted by <?php the_author_posts_link(); ?> | <?php the_time('F jS, Y') ?></u>
    
      <?php else : ?>
    
        <u>Written by <?php the_author_posts_link(); ?> | <?php the_time('F jS, Y') ?> </u>
    
      <?php endif; ?>  
    
    <?php endif; // is_single() ?>
    
    <!-- Custom: If not single post... -->
    <?php if (! is_single() ) : ?>  
    
      <h1 class="entry-title">
      <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
      </h1>
      <u>Posted <?php the_time('F jS, Y') ?></u>  
    
    <?php endif; // is_single() ?>

    Hello @markross67,

    no problem.

    Glad to help!

    Thread Starter markross67

    (@markross67)

    ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Trying to make my Category Array work’ is closed to new replies.