Wordpress插件事件日历-列出一年内的所有事件


Wordpress Plugin The Events Calendar - Listing All Events For One Year

我一直在努力(我是个新手)如何让事件日历打印指定年份内所有事件的列表。我在网上大量研究了这一需求,我很惊讶关于这一主题的信息有限。清单真的很简单。它只需要是一个链接的标题,将用户发送到实际的事件页面。

我的方法是在functions.php中创建一个自定义的[shortcode],这样我就可以把列表放在我需要的任何WordPress页面或帖子上。

自定义的PHP短代码如下。

add_shortcode('yearList', 'yearList');
function sayHello()
{
echo '<h1>Hello World</h1>';
}

我将其添加到Genesis子主题根目录中的functions.php文件中。文本的回声很好,所以这部分很好。

在研究了Modern Tribe的论坛后,我发现了一个有用的页面,它评论了Tribe_get_events功能。这是那些想知道的人的页面。

无论如何,这个页面中的代码让我很接近,所以我知道我走在了正确的轨道上。我在创建的shortcode函数中使用的PHP如下。

// Setting up custom function called yearList
add_shortcode('yearList', 'yearList');
function yearList()
{
// Ensure the global $post variable is in scope
global $post;
// Retrieve all events desired year. Only eight printed out of 80.
$events = tribe_get_events( array(
'eventDisplay' => 'custom',
'start_date'   => '2014-01-01 00:01',
'end_date'     => '2014-12-31 23:59'
) );
// Loop through the events: set up each one as
// the current post then use template tags to
// display the title and content
foreach ( $events as $post ) {
setup_postdata( $post );
// prints the title for each event.
echo '<br><br>'; 
//  WRONG WRONG - This is below is what's throwing me. 
echo '<a href="<?php echo tribe_get_event_link() ?>" title="<?php the_title() ?>"></a>';
//the_title();
// echo tribe_get_start_date();  This shows the start date and time after the event title I slept this for now.
}
}

我有两个问题

  1. 当我有80多个印章时,为什么循环只显示9个标题2014年
  2. 如何使每一行都成为日历事件实际事件的链接页我试着用这个,但运气不好

谢谢你在这方面的帮助。

对于第一个问题,请尝试在$events = tribe_get_events( array( ... );语句中添加posts_per_page => -1。默认限制必须设置为某个位置的9个帖子。如果这不起作用,请尝试用一个大数字替换-1

对于输出问题,您不能在php中使用echoecho。试试这个:

$ev_link = tribe_get_event_link();
$ev_title = get_the_title();
printf('<a href="%1$s" title="%2$s">%2$s</a>', $ev_link, $ev_title);