onethousandseas
Member
Posted 2 years ago #
I'm trying to write a search.php template that, when returning both pages and posts, would only return the date if the post_type was a post. Otherwise it would do nothing.
I've tried using post_class or quest_posts but I couldn't very far with them. Anyone have any ideas on how I can make this work?
TY.
<?php if($post->post_type == 'post') :
echo the_date();
endif;?>
onethousandseas
Member
Posted 2 years ago #
Thanks for replying to my question esmi :-)
I inserted the code into my page and here's what I have:
http://onethousandseas.org/testblog?s=lorem
It works well for the first few posts, but I'm not sure why it wouldn't show up for the next 2 that are posts but not pages (only the last article is a page which contains "lorem") which means there should be dates on the rest as well.
Here is the code I have for the page right now:
http://wordpress.pastebin.ca/1506364
I'm not seeing any dates on that page of search results...
onethousandseas
Member
Posted 2 years ago #
Got it! Customized it a little:
<?php
if($post->post_type == 'post') {
echo the_time('Y');
echo the_time('M');
echo the_time('j');
echo the_time('H:i');
}
else {print "Page";}
?>
But does anyone know how I can fit new lines in there? I'd like it to be something like this:
<?php
if($post->post_type == 'post') {
echo the_time('Y'); [NEWLINE]
echo the_time('M'); [NEWLINE]
echo the_time('j'); [NEWLINE]
echo the_time('H:i');
}
else {print "Page";}
?>
onethousandseas
Member
Posted 2 years ago #
Found my answer, here's how it looks, marking it resolved :-)