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

标签 php wordpress list plugins

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

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

自定义简码 PHP 如下。

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

我将其添加到 Genesis 子主题根目录中的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.

}
}

我有两个问题。

  1. 当我有超过 80 个标记时,为什么循环只显示 9 个标题 2014 年?
  2. 如何使每一行都成为日历事件实际事件的链接 页?我尝试过使用它,但没有成功。

感谢您对此提供的任何帮助。

最佳答案

对于您的第一个问题,请尝试在您的 $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);

关于php - Wordpress 插件 事件日历 - 列出一年内的所有事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28859326/

相关文章:

php - flock 处理时会发生什么?

php - 如何使用别名从两个表中获取计数值

wordpress - 如何获取 woocommerce 的所有产品?

wordpress - 将用户帐户商务服务器集成到 wordpress

python - 为列表中的每个值生成嵌套列表

javascript - Sublime Text 3 Linter 问题

php - 使用 PHP openssl 进行应用内购买签名验证

mysql - 如何使用 WP 标题解决更复杂的 wp_query meta_query

python - TLE 计算列表中指定范围内的元素数量

java - 支柱2 : Displays table of Songs - null gets printed