Wordpress 插件事件日历 - 列出一年的所有事件
Wordpress Plugin The Events Calendar - Listing All Events For One Year
我一直在努力(我是新手)如何让事件日历打印指定年份内所有事件的列表。我在网上大量研究了这一需求,令我惊讶的是关于该主题的信息有限。这份名单真的很简单。它只需要是一个 linked 标题,将用户发送到实际的事件页面。
我的方法是在 functions.php 中创建自定义 [简码],这样我就可以将列表放在任何 WordPress 页面或我需要的 post 上。
自定义简码 PHP 如下。
add_shortcode('yearList', 'yearList');
function sayHello()
{
echo '<h1>Hello World</h1>';
}
我将其添加到 Genesis child 主题根目录中的 functions.php 文件中。文本回显良好,因此该部分很好。
在研究了 Modern Tribe 的论坛后,我发现了一个有用的页面,其中介绍了 tribe_get_events 功能。 Here's the page for those wondering。
无论如何,此页面中的代码让我很接近,所以我知道我在正确的轨道上。
我在创建的短代码函数中使用的 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.
}
}
我有两个问题。
- 为什么当我有超过 80 个标题时循环只显示九个标题
2014 年?
- 如何使每一行成为日历事件实际事件的 link
页?我试过使用它,但没有成功。
感谢您对此的任何帮助。
对于第一个问题,请尝试在 $events = tribe_get_events( array( ... );
语句中添加 posts_per_page => -1
。默认限制必须在某处设置为 9 个帖子。如果这不起作用,请尝试用大数字替换 -1
。
对于输出问题,您不能在php 中echo
一个echo
。试试这个:
$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);
我一直在努力(我是新手)如何让事件日历打印指定年份内所有事件的列表。我在网上大量研究了这一需求,令我惊讶的是关于该主题的信息有限。这份名单真的很简单。它只需要是一个 linked 标题,将用户发送到实际的事件页面。
我的方法是在 functions.php 中创建自定义 [简码],这样我就可以将列表放在任何 WordPress 页面或我需要的 post 上。
自定义简码 PHP 如下。
add_shortcode('yearList', 'yearList');
function sayHello()
{
echo '<h1>Hello World</h1>';
}
我将其添加到 Genesis child 主题根目录中的 functions.php 文件中。文本回显良好,因此该部分很好。
在研究了 Modern Tribe 的论坛后,我发现了一个有用的页面,其中介绍了 tribe_get_events 功能。 Here's the page for those wondering。
无论如何,此页面中的代码让我很接近,所以我知道我在正确的轨道上。 我在创建的短代码函数中使用的 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.
}
}
我有两个问题。
- 为什么当我有超过 80 个标题时循环只显示九个标题 2014 年?
- 如何使每一行成为日历事件实际事件的 link 页?我试过使用它,但没有成功。
感谢您对此的任何帮助。
对于第一个问题,请尝试在 $events = tribe_get_events( array( ... );
语句中添加 posts_per_page => -1
。默认限制必须在某处设置为 9 个帖子。如果这不起作用,请尝试用大数字替换 -1
。
对于输出问题,您不能在php 中echo
一个echo
。试试这个:
$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);