Make WordPress Core

Opened 17 years ago

Closed 17 years ago

Last modified 5 years ago

#4177 closed enhancement (fixed)

new conditional tag: has_excerpt

Reported by: fekketcantenel's profile FekketCantenel Owned by: rob1n's profile rob1n
Milestone: 2.3 Priority: normal
Severity: trivial Version:
Component: Template Keywords: has-patch commit
Focuses: Cc:

Description

Here is a short suggestion for a new conditional tag in query.php. Before this is added, or in case it never is, I've added a short help to the Conditional Tags documentation.

function has_excerpt () {
	global $post;
	if (empty($post->post_excerpt)) { return false; }
	else { return true; }
}

I know that this appears very simple, but PHP newbies (like myself) wouldn't think of it without help. The function it serves doesn't seem that obscure, so I hope it's worthy of inclusion.

Attachments (1)

4177.diff (448 bytes) - added by rob1n 17 years ago.

Download all attachments as: .zip

Change History (14)

#1 @error
17 years ago

Looks like a good idea for a conditional tag.

#2 @rob1n
17 years ago

  • Keywords has-patch 2nd-opinion added
  • Milestone set to 2.3

Makes sense to me, I guess. +1.

#3 @rob1n
17 years ago

  • Owner changed from anonymous to rob1n

#4 @rob1n
17 years ago

  • Keywords has-patch removed

My bad, it's got no patch. I must be seeing things...

#5 @markjaquith
17 years ago

+1

Theme authors shouldn't have to know about empty()

#6 @rob1n
17 years ago

  • Keywords needs-patch added; 2nd-opinion removed

@rob1n
17 years ago

#7 @rob1n
17 years ago

  • Keywords has-patch commit added; needs-patch removed

#8 @rob1n
17 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [5293]) has_excerpt() template tag. fixes #4177 for 2.3

#9 @FekketCantenel
17 years ago

Just curious, why is the patch code so different from what I wrote? It's in a different file, looks a bit different... I ask for future reference.

#10 @markjaquith
17 years ago

FekketCantenel,

For increased usefulness. Your code would only work with the current post. This function can take any post ID as a parameter. The return line is just simpler... skips the if/else logic block and just returns the opposite of the empty() bool result.

#11 @FekketCantenel
17 years ago

"Your code would only work with the current post. This function can take any post ID as a parameter."

Ahhhhhhhh, I see. So this way, you could write has_excerpt('1') (the post's ID) and find out if that post has an excerpt. It's a good thing you thought of that.

Thanks for the information.

#12 @rob1n
17 years ago

Also, this function was put into post-template.php because it is a template tag that deals with posts. query.php is usually reserved for functions that are directly related to WP_Query (is_page, is_home, etc.).

This ticket was mentioned in Slack in #community-team by francina. View the logs.


5 years ago

Note: See TracTickets for help on using tickets.