提取标题并添加到Wordpress中的帖子

时间:2014-12-08 00:14:03

标签: php css wordpress title

我有一个包含500多个帖子的Wordpress网站。我想提取每个帖子的标题,用一些span类代码包装它,将标题和代码添加到每个帖子的末尾(从中提取它的相同帖子),并隐藏其可见性。我将如何在Wordpress / PHP中执行此操作?

谢谢!

编辑:@unixmiah,会这样实现吗?

<?php
global $post;
$args = array( 'numberposts' => 500, 'offset'=> 0, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); ?>
    <li span class="name hidden"><?php the_title();?></li>
<?php endforeach; ?>

我将哪个文件插入?的functions.php?另外,如何确保此代码在站点范围内运行?

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码通过wordpress内部函数完成此操作,以便在循环中获取该信息。

例如

<?php
global $post;
$args = array( 'numberposts' => 500, 'offset'=> 0, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :  setup_postdata($post); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>

你的javascript范围问题看起来很模糊,你的意思是隐藏它并在鼠标悬停时显示它吗?