WordPress:自定义部件内的摘录
问题描述:
我希望能够通过删除read more
链接自定义the_excerpt
输出,但前提是它位于小部件内部。WordPress:自定义部件内的摘录
使用的情况是这样的:
在我的网站,用户可以发布他们的旅行报告。我以两种方式显示这些报告 - Published
和Future
。 Published
列表报告出现在我不想在excerpt
中进行任何更改的页面,但Future
帖子出现在自定义插件的侧栏中。我想要excerpt
这里,但没有连接到它的read more
链接。
以下功能functions.php
删除read more
链接通过检查post_type
,但从无处不在!我希望这个链接在普通列表中可见。
function custom_excerpt_more_link($more){
global $post;
if($post->post_type == 'travelog') {
return '..';
} else {
return '<a href="' . get_the_permalink() . '" rel="nofollow"> [more]</a>';
}
}
是否有一个选项,会告诉WordPress的冒了出来只有当excerpt
正在呈现一个小工具里面这个链接?
希望以下屏幕截图可能有助于解释我正在尝试完成的工作。
的excerpt
与标题后我第一次白色圣诞 - 2013年12月至马拉里之旅应该有read more
链接,而我不希望它为那些在右侧栏中列出。这可能吗?
UPDATE:
修改后的代码:
function custom_excerpt_more_link($more){
if(dynamic_sidebar('upcoming-stories-sidebar')) {
global $post;
if ($post->post_type == 'travelog') {
return '..';
} else {
return '<a href="' . get_the_permalink() . '" rel="nofollow"> [more]</a>';
}
}
else {
return '<a href="' . get_the_permalink() . '" rel="nofollow"> [more]</a>';
}
}
add_filter('excerpt_more', 'custom_excerpt_more_link');
答
如果使用CSS显示性能没有这将是更好。首先找到后包装;假设自定义帖子类型的包装为.custom
,其CSS将为
.custom a {
display:none
}
感谢您的回复。代码实际上在我的内容区域内创建了无限循环的即将到来的故事!侧栏不可见。用新的截图和更新的代码编辑我的文章。 –
您正在使用什么插件或代码来生成侧边栏发布内容? –
我没有使用任何现成的插件。这是一个使用WP_Query的自定义插件:'$ q = new WP_Query(array( 'post_type'=>'travelog', 'posts_per_page'=> 6, 'orderby'=>'date', 'post_status'=> array('future') ));' –