dougu4704 2014-07-03 18:27
浏览 56
已采纳

Wordpress - 在不使用循环的情况下显示页面内容

Confusing title, I know. Let me explain.

Currently, I have this little guy set up in my Wordpress theme:

<?php 
    $id=7; 
    $post = get_post($id); 
    $content = apply_filters('the_content', $post->post_content);
    echo $content;  
?>

What this does is it displays the content from a certain page of my choice.

Works great! Bravo! Fantastic! The only problem is that I'd like to only show the content before the read more-tag, not ALL of it. And that is where I'm at a loss.

My research (incessant googling, cursing and hammering om my keyboard) has lead me to understand that I could achieve this within a loop. But as I am only going to display the one page that seems a bit redundant.

Also, I'd rather not use the_excerpt as that means the end user won't be able to change the content later on.

Thanks for reading and I hope you can help! Cheerio!

  • 写回答

1条回答 默认 最新

  • dswm97353 2014-07-03 18:57
    关注

    Use the WordPress function get_extended($post_content) to retreive text in content before the <!--more--> tag.

    For example:

    $id=7; 
    $post = get_post($id); 
    $content_arr = get_extended($post->post_content);
    echo apply_filters('the_content', $content_arr['main']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧