Forum Replies Created

Viewing 8 replies - 16 through 23 (of 23 total)
  • Thread Starter Franklyn Monk

    (@maintainer)

    I may have it.

    Hopefully the following will be useful to someone down the line.

    But it’s not all that elegant, if a master stumbles along and can improve on it I would love to hear of a better way.

    I put in a lot of if/else statements, testing for version existing or not existing along with tags and categories. I’m wondering if instead I should go with a single loop with two branches, one if the custom field exists and one in the case it doesn’t. I’m unsure if that would be any better, quicker, easier for me to parse when I go back to it in the future. (a poem, and gratitude for the one that answers!)

    Here’s the apparently working code:

    <?php
    	/* translators: used between list items, there is a space after the comma */
    	$versionNum = get_post_custom_values("version");
    	if (isset($versionNum[0])) {
    		$testPrintVer = get_post_meta($post->ID, 'version', true);
    	}
    
    	$categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) );
    
    	/* translators: used between list items, there is a space after the comma */
    	$tag_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );
    
    	if ( ( '' != $testPrintVer ) && ( '' != $tag_list ) ) {
    		$utility_text = __( 'This entry is in revision %7$s and was posted in %1$s and tagged %2$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    	} elseif ( ( '' != $testPrintVer ) && ( '' != $categories_list ) ) {
    		$utility_text = __( 'This entry is in revision %7$s and was posted in %1$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    	} elseif ( '' != $testPrintVer ) {
    		$utility_text = __( 'This entry is in revision %7$s and was posted by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    	} elseif ( '' != $tag_list ) {
    		$utility_text = __( 'This entry was posted in %1$s and tagged %2$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    	} elseif ( '' != $categories_list ) {
    		$utility_text = __( 'This entry was posted in %1$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    	} else {
    		$utility_text = __( 'This entry was posted by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    	}
    
    	printf(
    		$utility_text,
    		$categories_list,
    		$tag_list,
    		esc_url( get_permalink() ),
    		the_title_attribute( 'echo=0' ),
    		get_the_author(),
    		esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    		$testPrintVer
    	);
    ?>
    Thread Starter Franklyn Monk

    (@maintainer)

    I think I got it!
    But I’m not really sure.

    Here’s what I did I added a conditional statement to make sure both the version and tag were not untrue???—what, it’s weirding me out— if ( ( '' != $testPrintVer ) && ( '' != $tag_list ) ) then to print the version number and category and tags if present

    It seems to be working as expected, I think it’ll probably fail if a post doesn’t have a category, but all mine do.

    If anyone is following this and can help clarify what’s going on, or give me the words to express what’s going on I would write you a poem!

    Here is the current code that seems to be working.

    Update, it’s not working. If there’s not a tag it won’t print the version number. What do I do?

    Is the question how do I write if version and tag print everything, if version and no tag print everything but tag? What is the answer?

    <?php
    
    			$versionNum = get_post_custom_values("version");
    			if (isset($versionNum[0])) {
    				$testPrintVer = get_post_meta($post->ID, 'version', true);
    	  		}
    
    			/* translators: used between list items, there is a space after the comma */
    			$categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) );
    
    			/* translators: used between list items, there is a space after the comma */
    			$tag_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );
    
    			if ( ( '' != $testPrintVer ) && ( '' != $tag_list ) ) {
    				$utility_text = __( 'This entry is in revision %7$s and was posted in %1$s and tagged %2$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    
    			} elseif ( '' != $tag_list ) {
    				$utility_text = __( 'This entry was posted in %1$s and tagged %2$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    			} elseif ( '' != $categories_list ) {
    				$utility_text = __( 'This entry was posted in %1$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    			} else {
    				$utility_text = __( 'This entry was posted by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    			}
    
    			printf(
    				$utility_text,
    				$categories_list,
    				$tag_list,
    				esc_url( get_permalink() ),
    				the_title_attribute( 'echo=0' ),
    				get_the_author(),
    				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    				$testPrintVer
    			);
    		?>
    Thread Starter Franklyn Monk

    (@maintainer)

    I’m making progress, but hit a stumbling point. I have the post-footer on a single page displaying a custom field value, but it breaks if a post has no tags.

    The if/else statements are confusing me. I know they are filling a variable called $utility_text with a predetermined text string depending on whether a post has defined categories and/or tags. I’m having the hardest time translating what’s going on though— it seems like it’s asking “If blank is not the tag list load the string with both categories and tags, but if not then if blank is also not the category…”

    My code is below, I would also include a link to the twenty-eleven content-single.php file, but I can’t find one.

    Can anyone help me understand what’s going on here or point me to a good starting point?

    Thanks

    The current state of my code (the letters at the beginning of $utility_text were tests to help me understand when a line would print):

    <?php
    
    			$versionNum = get_post_custom_values("version");
    			if (isset($versionNum[0])) {
    				$testPrintVer = get_post_meta($post->ID, 'version', true);
    	  		}
    
    			/* translators: used between list items, there is a space after the comma */
    			$categories_list = get_the_category_list( __( ', ', 'twentyeleven' ) );
    
    			/* translators: used between list items, there is a space after the comma */
    			$tag_list = get_the_tag_list( '', __( ', ', 'twentyeleven' ) );
    
    			if ( '' != $testPrintVer ) {
    				$utility_text = __( 'This entry is in revision %7$s and was posted in %1$s and tagged %2$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    
    			} elseif ( '' != $tag_list ) {
    				$utility_text = __( 'a. Vers %7$s . This entry was posted in %1$s and tagged %2$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    			} elseif ( '' != $categories_list ) {
    				$utility_text = __( 'b. Vers %7$s . This entry was posted in %1$s by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    			} else {
    				$utility_text = __( 'c. Vers %7$s . This entry was posted by <a href="%6$s">%5$s</a>. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'twentyeleven' );
    			}
    
    			printf(
    				$utility_text,
    				$categories_list,
    				$tag_list,
    				esc_url( get_permalink() ),
    				the_title_attribute( 'echo=0' ),
    				get_the_author(),
    				esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
    				$testPrintVer
    			);
    		?>

    I am having the same issue.

    Thread Starter Franklyn Monk

    (@maintainer)

    That was the most awesome thing I have experienced.
    Thank you!

    Thread Starter Franklyn Monk

    (@maintainer)

    Ok. I’m not sure what I did. I tried to comment out sections dealing with archives and search and when that didn’t work <!– I guess I used the wrong comment syntax –> I just started deleting lines that seemed to deal with the excerpted items. It seems to be working now. I wish I had the patience and time and knowledge to pursue it more, but I’m gonna let it alone for now.

    Thread Starter Franklyn Monk

    (@maintainer)

    So, I see now that the Twenty Ten theme pulls the loop out into it’s own file and I’m trying to figure out what’s going on. It seems that it gives only excepts for Archive, Category, and Tag pages. I’m having trouble figuring out the syntax on those routines.

    A suggestion to the developers—it would be awesome if you included an options pane for showing full posts or excepts on those pages.

    Heya my sweet cosmicjellybaby

    I’m so very happy you posted the info it worked wonderfully.

Viewing 8 replies - 16 through 23 (of 23 total)