因此,我在函数中编写了以下代码。php。我在我的博客帖子中使用它来显示粘性帖子,但我唯一的问题是我不知道如何在HTML中获取永久链接。
此外,如何将帖子指定为粘滞的,但仅在我的短代码中显示?现在,这个短代码显示在我所有的帖子之上,但是粘性帖子会再次发布在顶部(我知道这是正确的功能,但我只想通过短代码显示粘性帖子)。
Thank you in advance!
功能。php
function wpb_latest_sticky() {
$sticky = get_option( \'sticky_posts\' );
$sticky = array_slice( $sticky, 0, 1 );
$the_query = new WP_Query( array( \'post__in\' => $sticky, \'ignore_sticky_posts\' => 1 ) );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
echo "<div class=\'w-100 w-50-m w-third-ns sticky-blog-column fl\'>";
echo "<div class=\'pv5\'>";
echo "<a href = \'get_permalink()\' >";
echo "<div class=\'featured-img\'>"
.get_the_post_thumbnail();
echo "</div>";
echo "<h5 class=\'pt4 pb3\'>"
.get_the_date();
echo "</h5>";
echo "<h3>"
.get_the_title();
echo "</h3>";
echo "<p>"
.get_the_excerpt();
echo "</p>";
echo "</a>";
echo "</div>";
echo "</div>";
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();
return $return;
}
add_shortcode(\'latest_stickies\', \'wpb_latest_sticky\');
博客。php
<?php echo do_shortcode("[latest_stickies]"); ?>
<?php if (have_posts()) : while(have_posts()) : the_post();?>
<!-- start standard column -->
<div class="w-100 w-50-m w-third-ns blog-column fl">
<div class="pv5">
<a href="<?php the_permalink();?>">
<div class="featured-img"><?php the_post_thumbnail();?></div>
<h5 class="pt4 pb3"><?php echo get_the_date();?></h5>
<h3><?php the_title();?></h3>
<?php the_excerpt();?>
</a>
</div>
</div>
<!-- end standard column -->
<?php endwhile;
endif;?>
</div>