我想在循环中的post元数据中显示一个图标。php,对于每个帖子都有一个特定的meta\\u值!
更具体地说,我使用此代码在发布新帖子时显示一个图标,该图标持续24小时:
<?php if( date(\'U\') - get_the_time(\'U\', $post->ID) < 24*60*60 ) : ?>
<span class="new-post"></span>
<?php endif; ?>
下面是风格代码。css:
.item-list span.new-post {
padding-left: 20px;
width: 20px;
height: 18px;
background: 0px 0px url(http://www.e-win.gr/wp-content/themes/e-win/images/new-post.png) no-repeat;
}
我真正想要的是,当一篇文章有一个特定的meta\\u值时,显示一个图标。以下是我试图获取的代码,但没有结果:
<?php $icon = get_post_meta(apaitei_logariasmo_facebook); ?>
<?php if( ! $icon == attr_esc(Ναι) ) ?>
<span class="facebook-badge"></span>
<?php endif; ?>
这是我在风格上使用的代码。css插入图标:
.item-list span.facebook-badge {
padding-left:20px;
width: 20px;
height: 14px;
background: 0px 0px url(http://www.e-win.gr/wp-content/themes/e-win/images/facebook-badge.png) no-repeat;
}
要使代码正常工作并显示特定meta\\u值的图标,我必须做些什么?
P、 我在用这个attr_esc(Ναι)
因为我在meta\\u值中使用希腊字符。此外,我正在使用“高级自定义字段插件”创建和管理自定义字段。
这就是整个循环。php:
<?php if ( ! have_posts() ) : ?>
<div id="post-0" class="post not-found post-listing">
<h1 class="post-title"><?php _e( \'Not Found\', \'tie\' ); ?></h1>
<div class="entry">
<p><?php _e( \'Apologies, but no results were found for the requested archive. Perhaps searching will help find a related post.\', \'tie\' ); ?></p>
<?php get_search_form(); ?>
</div>
</div>
<?php else : $count = 0;?>
<div class="post-listing <?php if( tie_get_option( \'blog_display\' ) == \'2col\' ) echo"archives_2col" ?>">
<?php while ( have_posts() ) : the_post(); $count++; ?>
<?php if( tie_get_option( \'blog_display\' ) != \'full_thumb\' ): ?>
<article class="item-list <?php echo\'item_\'.$count; ?>">
<h2 class="post-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'tie\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<p class="post-meta">
<?php
if( get_field( "hmeromhnia_lhkshs" ) ): ?>
<span class="date"><?php the_field(\'hmeromhnia_lhkshs\'); ?> </span>
<?php endif;
?>
<?php
if( get_field( "wra_lhkshs" ) ): ?>
<span class="time"><?php the_field(\'wra_lhkshs\'); ?></span>
<?php endif;
?>
<?php tie_get_time() ?>
<span class="category-label">
<?php
$caturls = array();
foreach( (get_the_category()) as $cat ):
$caturls[] = \'<a href="\' . get_category_link( $cat->cat_ID ) . \'">\' . $cat->cat_name . \'</a> \';
endforeach;
echo implode( \', \', $caturls ); ?></span>
<span class="post-comments"><?php comments_popup_link( __( \'0\', \'tie\' ), __( \'1 Comment\', \'tie\' ), __( \'% Comments\', \'tie\' ) ); ?></span>
<?php if( date(\'U\') - get_the_time(\'U\', $post->ID) < 24*60*60 ) : ?>
<span class="new-post"></span>
<?php endif; ?>
<?php $icon = get_post_meta( $post->ID, \'apaitei_logariasmo_facebook\', true); ?>
<?php if( !empty($icon) ) : ?>
<span class="facebook-badge"></span>
<?php endif; ?>
</p>
<?php if( tie_get_option( \'blog_display\' ) == \'content\' ): ?>
<div class="entry">
<?php the_content( __( \'Read More »\', \'tie\' ) ); ?>
</div>
<?php else: ?>
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="post-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'tie\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark">
<?php tie_thumb(\'\',200,200); ?>
<?php tie_get_score( true ); ?>
</a>
</div><!-- post-thumbnail /-->
<?php endif; ?>
<div class="entry">
<p><?php tie_excerpt() ?></p>
<a class="more-link" href="<?php the_permalink() ?>"><?php _e( \'Read More »\', \'tie\' ) ?></a>
</div>
<?php endif; ?>
<?php tie_include( \'post-share\' ); // Get Share Button template ?>
<div class="clear"></div>
</article><!-- .item-list -->
<?php if( $count == 2 && tie_get_option( \'blog_display\' ) == \'2col\' ): $count = 0; ?>
<div class="sep"></div>
<?php endif; ?>
<?php else: ?>
<article class="item-list">
<?php if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) : ?>
<div class="post-thumbnail single-post-thumb archive-wide-thumb">
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'tie\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php tie_thumb(\'\', 620 , 330 ); ?><?php tie_get_score( true ); ?></a>
</div>
<?php endif; ?>
<h2 class="post-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( \'Permalink to %s\', \'tie\' ), the_title_attribute( \'echo=0\' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<p class="post-meta">
<?php tie_get_time() ?>
<span class="post-comments"><?php comments_popup_link( __( \'0\', \'tie\' ), __( \'1 Comment\', \'tie\' ), __( \'% Comments\', \'tie\' ) ); ?></span>
<?php echo tie_views(); ?>
</p>
<div class="entry">
<p><?php tie_excerpt() ?></p>
<a class="more-link" href="<?php the_permalink() ?>"><?php _e( \'Read More »\', \'tie\' ) ?></a>
</div>
<?php tie_include( \'post-share\' ); // Get Share Button template ?>
<div class="clear"></div>
</article><!-- .item-list -->
<?php endif; ?>
<?php endwhile;?>
</div>
<?php endif; ?>