php


Return post date in specific format wordpress


I am trying to display the post date in a special format in WordPress. I succeeded in doing this but the dates are not corresponding to the posts. It seems like my while loop takes only the first date of the post and applies this to the other posts. Ex: I have 3 posts in a grid (post1, post2, post3), the most recent post is published today 10/feb, the other 2 have different dates. My grid will display the date of the most recent post with all posts. The while loop is in a file that gets called when generating every post.
Here is my code:
$check = 1;
while (have_posts()) : the_post();
if ($check == 1) {
echo "<div class='vc-datewrapper'>";
echo "<div class='vc-datebox'>";
echo "<span class='vc-date'>";
$day = the_time('d');
echo "</span>";
echo "<span class='vc-month'>";
$day2 = the_time('M');
echo "</span>";
echo "</div></div></div>";
$check = 0;
}
endwhile;
The output on my page is : 10 feb / 10 feb / 10 feb. Now my question is how do I get the date from each post specifically and not the most recent of the 3?
The whole code (visual composer template: vc_gitem_post_data.php)
<?php
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
/**
* Shortcode attributes
* #var $atts
* Shortcode class
* #var $this WPBakeryShortCode_VC_Gitem_Post_Data
*/
$output = $text = $google_fonts = $font_container = $el_class = $css = $google_fonts_data = $font_container_data = $link_html = '';
extract( $this->getAttributes( $atts ) );
extract( $this->getStyles( $el_class, $css, $google_fonts_data, $font_container_data, $atts ) );
$data_source = $this->getDataSource( $atts );
if ( isset( $atts['link'] ) && '' !== $atts['link'] && 'none' !== $atts['link'] ) {
$link_html = vc_gitem_create_link( $atts );
}
$use_custom_fonts = isset( $atts['use_custom_fonts'] ) && 'yes' === $atts['use_custom_fonts'];
$settings = get_option( 'wpb_js_google_fonts_subsets' );
$subsets = '';
if ( is_array( $settings ) && ! empty( $settings ) ) {
$subsets = '&subset=' . implode( ',', $settings );
}
$content = '{{ post_data:' . esc_attr( $data_source ) . ' }}';
if ( ! empty( $link_html ) ) {
$content = '<' . $link_html . '>' . $content . '</a>';
}
$css_class .= ' vc_gitem-post-data';
if ( $data_source ) {
$css_class .= ' vc_gitem-post-data-source-' . $data_source;
}
if ( $use_custom_fonts && ! empty( $google_fonts_data ) && isset( $google_fonts_data['values']['font_family'] ) ) {
wp_enqueue_style( 'vc_google_fonts_' . vc_build_safe_css_class( $google_fonts_data['values']['font_family'] ), '//fonts.googleapis.com/css?family=' . $google_fonts_data['values']['font_family'] . $subsets );
}
$output .= '<div class="' . esc_attr( $css_class ) . '" >';
$style = '';
if ( ! empty( $styles ) ) {
$style = 'style="' . esc_attr( implode( ';', $styles ) ) . '"';
}
$output .= '<' . $font_container_data['values']['tag'] . ' ' . $style . ' >';
$output .= $content;
$output .= '</' . $font_container_data['values']['tag'] . '>';
$output .= '</div>';
$check = 1;
while (have_posts()) : the_post();
if ($check == 1) {
echo "<div class='vc-datewrapper'>";
// $categories = get_the_category();
// if ( ! empty( $categories ) ) {
// $vc_cat = esc_html( $categories[0]->name );
// echo "<div class='" . $vc_cat . "'>";
// }
echo "<div class='vc-datebox'>";
echo "<span class='vc-date'>";
get_the_date('d');
echo "</span>";
echo "<span class='vc-month'>";
the_time('M');
echo "</span>";
echo "</div></div></div>";
$check = 0;
}
endwhile;
echo $output;
Thanks for any clues in advance!
I solved it by looking for a function that called the date in the Visual Composer wordpress plugin.
It looked like this:
function vc_gitem_template_attribute_post_datetime( $value, $data ) {
/**
* #var null|Wp_Post $post ;
*/
extract( array_merge( array(
'post' => null,
), $data ) );
return get_the_time( 'F j, Y g:i', $post->ID );
}
And here you can adjust the display of the date. Closing the question again, thanks for the answers.

Related Links

jquery .post() not working properly with PHP to check for username availability
How I could modify webservice according to mysql modification
How to check value of input type image in php or smarty?
Data is saved Twice to the database when ajax is used in yii
Gracefully close ReactPhp app
How can I set the MySQL date with string like 2015-07-30 18:32:18 [duplicate]
How to log a user out properly in the controller?
function to convert EDT to system time [duplicate]
Nothing display after a form and can't see the source code using browser
Cant insert Data into my Mysql Database?
display image after selecting the filename in codeigniter
Laravel - Order by pivot value in Many to Many table relationship
CURL POST with file - not working on Windows
Codeigniter admin route [closed]
Single query SELECT propagate to childs
How do I populate Laravel/Blade checkboxes from json in a db

Categories

HOME
nam
libgdx
freeradius
facebook-messenger
jms
out-of-memory
celery
dronekit-python
qooxdoo
google-sheets-query
drag-and-drop
firebase-database
native-base
timber
roku
elastic-load-balancer
migrate
fbloginview
sslhandshakeexception
jquery-file-upload
pywinauto
pinterest
mixpanel
playframework-2.0
office-ui-fabric
xsl-fo
http-authentication
codefluent
multiple-tables
adminlte
bluemix-mobile-services
android-permissions
el
fluent-migrator
perfino
vuforia
jpa-2.1
plyr
unrar
beego
spring-annotations
unmarshalling
es6-modules
memory-fences
markov-chains
adminer
cloudera-quickstart-vm
assert
jacoco-maven-plugin
secure-coding
1wire
yoast
latexml
flume-twitter
visual-format-language
dynamics-crm-4
email-injection
ternary-operator
controllers
metabase
java-2d
between
deferred-rendering
uibinder
json-spirit
ambiguity
android-handler
wicked-gem
nssortdescriptor
password-recovery
wicket-1.5
iplimage
back
loginview
zend-search-lucene
mod-perl
sensormanager
progress-db
tnt4j
objective-c-runtime
.net-remoting
void-pointers
chartfx
tfs-sdk
contextswitchdeadlock
xcode4.5
workflow-manager-1.x
websphere-6.1
fitch-proofs
wcf-callbacks
gwt-celltable
servercontrol
radscheduler
filelock
mongrel2
turbine
formal-semantics
ccl
j2mepolish
rational-unified-process
gtktextview
activex-exe

Resources

Encrypt Message