Who to add a line break in wordpress 'the_date'? - wordpress

I have this line:
<?php the_date(' F j Y')?>
this ends up with June 13 2012 (the current date). I would like to have the year on another line. I have tried this:
<?php the_date(' F j <br /> Y')?>
But it does not work. is there a way to get that break in between.
Thanks

You can separate the components of the date when you call the function. The 'f', 'j', 'Y', et. al essentially get replaced by the date, so omitting the 'Y' will allow you to specify it in another function call after the line break.
echo get_the_date('F j');
echo '<br />';
echo get_the_date('Y');
Wordpress actually has a nice guide explaining format characters: http://codex.wordpress.org/Formatting_Date_and_Time
EDIT: Fixed to use get_the_date instead.

I'm not too familiar with the date function but you can use substr() to break out what you want here's an example;
$date = the_date(' F j Y'); // in your example it should return : "June 13 2012"
echo substr($date,0,(count($temp)-5)); //this will echo just "June 13"
echo "<br />";
echo substr($date,-4,4); //This will echo just the year
Which will display;
June 13
2012

Related

echo number format round

in word press I am trying to echo price like round last 3 digit.
Example
$price= 15.786.625;
I whant after echo price like this
price=15.786.000
How I can do it?
I find a way do it this.
Say
$price=4,316,028
$pricecarp=round($price/1000)*1000;
<?php
echo number_format($pricecarp, 0, '.', ',');
?>
Result= 4,316,000

How to use Wordpress Trim Words Function

i want to trim a single word i.e, Monday in wordpress, how can i trim this word?
$my_title = get_the_title();
echo wp_trim_words($my_title, 1, null );
the title coming from database Monday So i want to trim Monday to Mo or M.
wp_trim_words() will works easily without any problems. You can use it with below sample code:
echo wp_trim_words( get_the_title(), 1, '' );
But do note that it will trim the first character in whole post/page title, not regconize the date in your example.
I don't know that wp_trim_words() works that way. I'd recommend just using regex and preg_match():
$my_title = get_the_title();
to get the first character:
$regex = '/(.?)/';
or to get the first two characters, change the variable to this:
$regex = '/(.?)./';
Then get the matches for the regex pattern:
preg_match($regex, $my_title, $matches);
Echo out the first one:
echo $matches[0];

Concatenate three integer value UNIX

hi i am trying to concatenate three integer value in UNIX OS(SunOS 5.10). But it is not working for me .
Below is the code
a=2016
b=11
c=21
result="$a$b$c"
echo "$result"
OUTPUT-:
2016
11
21
Can anyone help???
browserDate="2016-11-21"
dateConversion="${browserDate//'-'}
echo "$date Conversion"
You need tho use printf instead of echo:
a=2016
b=11
c=21
result="$a\n$b\n$c"
printf $result

Query is ordered correctly in SQL but not in Drupal

I have a query that takes a string 'noticeDate' and converts it to a date to order it by. The query works perfectly when I run it in phpmyadmin but not in drupal
Here's my query
<h3 style="text-align: center;">Public Notices</h3>
<?php
$query="SELECT `noticeTitle`, `noticeDate`, `filename`, STR_TO_DATE(`noticeDate`, '%m/%d/%Y') as filedate, `filepath`
FROM `public_notice`
ORDER BY filedate DESC
LIMIT 5";
$results = db_query($query);
while ($row = db_fetch_array($results)) {
echo '<tr>';
echo '<td><u><a href=http://website.com/'. $row["filepath"] . '>' .$row["noticeDate"].'</u>- '.$row["noticeTitle"]. '</a></td><br />';
echo '</tr>';
}
?>
In phpmyadmin, it orders 5 dates perfectly- but in drupal it looks like this.
08/04/2009- sometext
09/14/2009- sometext
01/28/2009- sometext
01/23/2009- sometext
02/25/2009- sometext
I think the problem is with the way Drupal substitutes arguments / named parameters. See the second parameter for db_query.
You should really refactor your code to use a db_select. https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_query/7
https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_select/7
To add the STR_TO_DATE functionality, use the AddExpression functionality. https://api.drupal.org/api/drupal/includes!database!select.inc/function/SelectQuery%3A%3AaddExpression/7
Using these two will definitely solve your problem. Good luck.

WordPress how to split month and day date into two pieces

How can I split the "month" and "day" date into two seperate pieces so I can place them under each other like this:
To obtain the current day you can:
echo date('d');
and for current month:
echo date('m');
in a short textual representation of a month, three letters:
echo date('M');
But if you have the date already in a string variable you can for day:
echo date('d',strtotime('11/26/2011'));
and for month:
echo date('M',strtotime('11/26/2011'));
For complete references of the functions:
date()
strtotime()
<p class="month"><?php echo get_the_date('M'); ?></p>
<p class="day"><?php echo get_the_date('d'); ?></p>

Resources