用自定义数组替换get_the_title和_explpt

时间:2013-10-11 作者:vitod

这是家里的密码。php:

<?php get_header(); ?>


<div class="pikachoose">
    <ul id="pikame" >
        <?php

$cat1 = stripslashes(get_option(\'lx_feat_cat\'));

//The Query
query_posts(\'category_name=\'. $cat1 . \'&showposts=9\');
//The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post();

$link = get_permalink( $post->ID );
?>
        <li>
        <a href="<?php echo $link ?>">
        <?php 
            if ( has_post_thumbnail() ) { // check if the post has a Post Thumbnail assigned to it.
            the_post_thumbnail(\'thumbnail-home\');
            } 
        ?></a>
        <div class="slide">
        <?php $slide_title = get_the_title(); ?>
        <h1 class="title-slider clean"><?php _e($slide_title, lexington-theme); ?></h1>
        <?php the_excerpt(); ?>
        </div>
        </li>



 <?php endwhile; endif;
//Reset Query
wp_reset_query();
?>
    </ul>
</div>  
我想将get\\u the\\u title替换为一个自定义标题和一个自定义的幻灯片标题。我想我可以用我的自定义标题和练习创建两个数组,并从数据库中提取它们,而不是那些:

<?php
$get_the_title() = "Custom title 1";
    $get_the_title() = "Custom title 2";
    $get_the_title() = "Custom title 3";

etc for 9 slides..

    $the_excerpt() = "Custom exerpt 1";
    $the_excerpt() = "Custom exerpt 2";

etc...
我的角度将$get\\u the\\u title()替换为$get\\u the\\u title\\u自定义[$链接],但运气不好。由于对php不太熟练,我无法在不破坏某些东西的情况下想出如何做到这一点。任何帮助都将不胜感激。

1 个回复
SO网友:Charles Clarkson

您可以使用一组数组来保存自定义标题和摘录,这些标题和摘录被键入到帖子ID中。在本例中,11、22、33、44、55、66、77、88和99是示例帖子ID。

$slides = array(
    11 => array(
        \'title\'   => \'Custom title 1\',
        \'excerpt\' => \'Custom excerpt 1\',
    ),
    22 => array(
        \'title\'   => \'Custom title 2\',
        \'excerpt\' => \'Custom excerpt 2\',
    ),
    33 => array(
        \'title\'   => \'Custom title 3\',
        \'excerpt\' => \'Custom excerpt 3\',
    ),
    44 => array(
        \'title\'   => \'Custom title 4\',
        \'excerpt\' => \'Custom excerpt 4\',
    ),
    55 => array(
        \'title\'   => \'Custom title 5\',
        \'excerpt\' => \'Custom excerpt 5\',
    ),
    66 => array(
        \'title\'   => \'Custom title 6\',
        \'excerpt\' => \'Custom excerpt 6\',
    ),
    77 => array(
        \'title\'   => \'Custom title 7\',
        \'excerpt\' => \'Custom excerpt 7\',
    ),
    88 => array(
        \'title\'   => \'Custom title 8\',
        \'excerpt\' => \'Custom excerpt 8\',
    ),
    99 => array(
        \'title\'   => \'Custom title 9\',
        \'excerpt\' => \'Custom excerpt 9\',
    ),
);
而不是使用get_the_title() 使用$slides[$post->ID][\'title\'].
而不是the_excerpt() 使用echo $slides[$post->ID][\'excerpt\'].

结束

相关推荐