【问题标题】:Extract title and add to post in Wordpress提取标题并添加到 Wordpress 中的帖子
【发布时间】:2014-12-08 00:14:02
【问题描述】:

我有一个包含 500 多个帖子的 Wordpress 网站。我想提取每个帖子的标题,用一些跨度类代码包装它,将标题和代码添加到每个帖子的末尾(提取它的同一帖子),并隐藏它的可见性。我将如何在 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; ?>

我应该将它插入到哪个文件中?函数.php?另外,如何确保此代码在站点范围内运行?

【问题讨论】:

    标签: php css wordpress title


    【解决方案1】:

    您可以使用下面的代码通过 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 span 问题似乎含糊不清,您的意思是隐藏它并在鼠标悬停时显示它吗?

    【讨论】:

    • 我的意思是我想在标题周围插入 span class="class_name" HTML 标签,然后将其隐藏(使用可见性:隐藏 CSS?)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    相关资源
    最近更新 更多