wordpress the_excerpt 不工作

发布于 2024-12-27 03:12:09 字数 1500 浏览 2 评论 0原文

我似乎无法让 the_excerpt 函数工作。

这是我正在使用的代码

我没有调用循环吗? 我没有在 Functions.php 中对 the_excerpt 使用任何过滤器。

任何任何都会很棒。

$col = 0;
$col_count = 3;
$cols = array();
// $my_query = new WP_Query( 'category_name=projects&posts_per_page=3');
// while ($my_query->have_posts()) : $my_query->the_post();
global $post;
$args = array( 'numberposts' => 3, 'offset'=> 0, 'category_name' => 'projects' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); 
  if($col >= $col_count) $col = 0;
  ob_start();
  ?>
  <div class="post" id="post-'<?php the_ID(); ?>'">
    <span class="title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></span>
    <div class="descr"><img src="<?php bloginfo( 'template_url' ); ?>/lib/img/clock.png"> <?php the_time('F, jS'); ?>, <span class="author"><?php the_time('Y'); ?> by <?php the_author_posts_link() ?></span></div>
    <div class="entry">
      <?php the_excerpt(); ?>
    </div>
  </div>
  <?php
  $output = ob_get_contents();
  ob_end_clean();
  $cols[$col++] .= $output;
 endforeach; wp_reset_postdata();
?>
<div class="columns">
<?php
foreach($cols as $key => $col)
  echo '<div class="column column' . $key . '">' . $col . '</div>';
?>
</div>

I can not seem to ger the_excerpt function to work.

Here is the code I am using

Am I not calling the loop right?
I am not using any filters in my functions.php for the_excerpt.

Any any would be great.

$col = 0;
$col_count = 3;
$cols = array();
// $my_query = new WP_Query( 'category_name=projects&posts_per_page=3');
// while ($my_query->have_posts()) : $my_query->the_post();
global $post;
$args = array( 'numberposts' => 3, 'offset'=> 0, 'category_name' => 'projects' );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); 
  if($col >= $col_count) $col = 0;
  ob_start();
  ?>
  <div class="post" id="post-'<?php the_ID(); ?>'">
    <span class="title"><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></span>
    <div class="descr"><img src="<?php bloginfo( 'template_url' ); ?>/lib/img/clock.png"> <?php the_time('F, jS'); ?>, <span class="author"><?php the_time('Y'); ?> by <?php the_author_posts_link() ?></span></div>
    <div class="entry">
      <?php the_excerpt(); ?>
    </div>
  </div>
  <?php
  $output = ob_get_contents();
  ob_end_clean();
  $cols[$col++] .= $output;
 endforeach; wp_reset_postdata();
?>
<div class="columns">
<?php
foreach($cols as $key => $col)
  echo '<div class="column column' . $key . '">' . $col . '</div>';
?>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

预谋 2025-01-03 03:12:09

对于循环我始终坚持:

query_posts('cat=6&showposts=10');

while ( have_posts() ) {
    the_post();

    // do stuff
    the_excerpt();

}

For the loop I always stick to:

query_posts('cat=6&showposts=10');

while ( have_posts() ) {
    the_post();

    // do stuff
    the_excerpt();

}
时光磨忆 2025-01-03 03:12:09

对于调用帖子,您可以使用此代码

<?php
global $post;
$args = array( 'numberposts' => 5, 'category' => 3 );


$myposts = get_posts( $args );
foreach( $myposts as $post ) :
setup_postdata($post); ?>

<?php the_title(); ?>
<?php the_content(); ?>

<?php endforeach; ?>

替换 Cat ID 和您要显示的帖子数量。

为了限制后字符,请使用此代码

<a href="<?php the_permalink(); ?>"><?php substr($post->post_content, 0, XY); ?> ...</a>

更改要显示的字符数 (XY)...

For calling post you can use this code

<?php
global $post;
$args = array( 'numberposts' => 5, 'category' => 3 );


$myposts = get_posts( $args );
foreach( $myposts as $post ) :
setup_postdata($post); ?>

<?php the_title(); ?>
<?php the_content(); ?>

<?php endforeach; ?>

Replace the Cat ID and number of post you want to display.

And for limiting the post character use this code

<a href="<?php the_permalink(); ?>"><?php substr($post->post_content, 0, XY); ?> ...</a>

Change the number of character (XY) you want to dispaly...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文