WordPress.org

Ready to get started?Download WordPress

Forums

Twenty Eleven
(3 posts)

  1. Hugh
    Member
    Posted 1 year ago #

    I have created several custom taxonomies. I have even gotten them to display in the post single page (generally following this tutorial) using my child theme. (See it in a screenshot here: http://d.pr/i/EghK.)
    But:

    1. Not every post contains a term from one of my custom posts.
    2. And some posts contain more than one term from one of my custom taxonomies. So I would like to have "and" inserted before the last term of the list if the list is greater than 1 term. eg. term1, term2, and term3

    So, I need to do some magic with an if{ elseif{ kind of stuff but I am not sure exactly what the syntax should be or how to get it there.

    Currently I have

    [ Moderator note: fixed code snippet ]

    <?php
            // We need to tell WordPress to look for our custom taxonomy lists
            $hp3_topic_lang_text = "";
    	// Then we need to tell it which one we want in particular and store it for use in our code.
                                            $hp3_top_lang_list = get_the_term_list( $term->ID, 'hp3_top_lang', 'and contains information about ', ', ', '' );
                                            if ( '' != $hp3_top_lang_list ) {
                                              $hp3_topic_lang_text .= "$hp3_top_lang_list\n";
                                            }
            // Now we need to tell WordPress exactly how we want to display the tag
                                            if ( '' != $hp3_topic_lang_text ) {
                                            ?>
    <!--// This just let's WordPress know that there's an else argument. It will remove the 'In this post' if no artists have been tagged.  -->
    <?
        }
    ?>
    <?php
            // We need to tell WordPress to look for our custom taxonomy lists
            $hp3_content_lang_text = "";
    // Then we need to tell it which one we want in particular and store it for use in our code.
                                            $hp3_cont_lang_list = get_the_term_list( $term->ID, 'hp3_cont_lang', '<!-- <strong>This entry has content written in:</strong> --> ', ', ', '' );
                                            if ( '' != $hp3_cont_lang_list ) {
                                              $hp3_content_lang_text .= "$hp3_cont_lang_list\n";
                                            }
            // Now we need to tell WordPress exactly how we want to display the tag
                                            if ( '' != $hp3_content_lang_text ) {
                                            ?>
    <div class="entry-utility">
    This entry is written in <?php echo $hp3_content_lang_text; echo $hp3_topic_lang_text; ?>.
    </div>
    <!--// This just let's WordPress know that there's an else argument. It will remove the 'In this post' if no artists have been tagged.  -->
    <?
        }
    ?>

    But this code I have used above seems really inefficient because it is basically two times the same thing instead of 1 time of one statement with two clauses... but maybe I need two statements I don't know...

    When I look at the standard code which comes in the twentyeleven theme and it has some pretty cool magic but I am not sure I understand it. I have pasted the above code and the standard code from twentyeleven in a pastebin here and is the same code found here in the codex.

      There are several things I am not understanding:

    1. the use of variables like this: %3$s ; where or how they are defined?
    2. How $utility_text is defined. - in my examples I have had to define my $hp3_topic_lang_text, but I do not see where this is getting its definition.
    3. What is the role of the printf( statement if there are several if-elseif statements?
    4. Since there are three statements, if - elseif - esleif, which cases do I need to account for in my additional statements? (assuming that I wanted to add more elseif statements to add my custom taxonomies.)
      It looks to me like the code in the theme reads; " if tag list is not empty, then set to clause #1, but if it is empty but category list is not empty then set to clause #2, but alas if both tag list and category list are empty then set to clause #3. This makes me ask 2 more questions:

      • What happens if there are tags but no categories, what is placed in the category variable's slot?
      • how many more else if statement do I need to add if of my two new taxonomies either one is optional and they can co-occur?
    5. Lastly, can someone help me understand this phrase:
      $categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) ); especially __( part, why is this different than what I am doing above here:
      $hp3_cont_lang_list = get_the_term_list( $term->ID, 'hp3_cont_lang', '<!-- <strong>This entry has content written in:</strong> --> ', ', ', '' );?

      The way I currently understand the $categories_liststatement to read is: set the variable categories_list to the value of get_the_category_list(..... and that is where I lose it.

    Thanks in advance.
    http://wordpress.org/extend/themes/twentyeleven/

  2. Hugh
    Member
    Posted 1 year ago #

    @ moderator, Thanks for fixing that code I have tried to get it to print to the screen properly but I wasn't figuring it out... frustrating. Do I have to put backticks on every line?

  3. Do I have to put backticks on every line?

    Nooo, that would be horrible and punitive. ;)

    I find that putting a backtick by itself on a line above and a line below your code will format it correctly. Doing it in the middle works but the formatting is different.

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic