使用javascript显示Wordpress查询中的多组内容项a
Display multiple sets of content items a from a Wordpress query with javascript
我正试图用java脚本让我最近的帖子显示在一个渐隐的内容列表中。我想提取12个最新的帖子,然后一次显示4个,从最近到最少。
以下是我的查询详细信息:
<?php
$my_query = new WP_Query('showposts=12');
while ($my_query->have_posts()) : $my_query->the_post();
?>
<?php
if (strlen(the_title('','',FALSE)) > 80) {
$title_short = substr(the_title('','',FALSE), 0, 80);
preg_match('/^(.*)'s/s', $title_short, $matches);
if ($matches[1]) $title_short = $matches[1];
$title_short = $title_short.'...';
}
else
{
$title_short = the_title('','',FALSE);
}
?>
我希望他们能正确地出现在这个脚本中:
<script>
var $items = $('#marquee li'),
i = 0;
function slide() {
var index = i % $items.length;
$items.hide().removeClass('curr').slice(index, index +4).show('fade').addClass('curr');
i += 4;
setTimeout(slide, 4000);
};
slide();
</script>
这就是我的上下文组织方式:
<div id="mholder">
<ul id="marquee">
<li><div class="marquee" style="height: auto">
<a title="<?php echo the_title() ?>" href="<?php the_permalink() ?>"><?php echo $title_short ?></a><span><small><br/><?php the_time('F jS, g:i a') ?></small></span>
</div></li>
</ul>
</div>
<head>
<script data-require="jquery@*" data-semver="2.1.1" src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<div class="newsblock">
<ul id="newgall">
<?php
//display 10 posts with title and date
$args=array(
'post_type' => 'post',
'post_status' => 'publish',
'post_category' => '123',
'posts_per_page' => 12,
'caller_get_posts'=> 1
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
?>
<li>
<p>
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
<br/><?php the_time('F jS, g:i a') ?>
<br/>
</p>
</li>
<?php
endwhile;
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
</ul>
</div>
<script>
var $items = $('#newgall li'),
i = 0;
function slide() {
var index = i % $items.length;
$items.hide().removeClass('curr').slice(index, index +4).show('fade').addClass('curr');
i += 4;
setTimeout(slide, 400);
};
slide();
</script>
</body>
确保通过插件启用PHP。此代码有效。
相关文章:
- 如果函数返回True,则显示Javascript按钮
- 背景图像前显示Javascript警报
- 为我的rails应用程序显示javascript弹出消息
- 如何在Javascript中显示Javascript变量
- 如何在colorbox中显示JavaScript变量
- Xamarin iOS WKWebView显示JavaScript警报
- GoogleMapsV3api只显示Javascript循环中的一些标记
- 如何在Asp.net标签控件中显示Javascript函数值
- 如何在对话框中显示javascript变量
- 在asp.net页面中显示javascript执行过程中的加载图标
- 在html中显示javascript变量won'不起作用
- 如何使用按钮在对话框上显示 Javascript 函数的结果
- 打开新窗口进行打印时不显示 JavaScript 图像
- 显示javascript控制台中的消息
- 在加载html网页时显示JavaScript表
- 在Notepad++中更好地突出显示Javascript语法
- 通过php显示javascript内容
- 文本字段未显示javascript函数中的变量
- 显示Javascript表单验证消息
- VB.NET-WebBrowser没有't在html源代码中显示javascript创建的html元素