是否可以使用archive-movies-title.php

时间:2017-08-10 03:05:11

标签: php wordpress archive

我有一个自定义的帖子类型电影,我想要做的是按照首字母的顺序列出电影标题,如果我创建36个.php文件,则可行。例如标题-a,标题-b ....

<div class="row pbot ptop" style="color: #fff;"><!-- #### ROW #### --> 
<div class="align_Center">
<?php
    $args = array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","ALL");
?>
<?php
    for($x = 0; $x < 36; $x++) {
?>
<span style="color: #777;">|</span>
<a href="title-<?php echo $args[$x]; ?>" class="m_headr"><?php echo $args[$x]; ?></a>
<?php
    }
?>
<span style="color: #777;">|</span>
</div>
</div><!-- #### / ROW #### -->

有什么方法可以通过名为.eg archive-movies-title的单个文件以及包含get_queried_object() - &gt; name的循环来完成所有操作。我不知道我是否接近标记,或者我是在没有钓竿的情况下钓鱼。

1 个答案:

答案 0 :(得分:0)

根据我的理解你想要做的是有一个指向同一个php文件的链接列表,然后这个php文件决定了用户按下了哪个链接。

为此,您可以使用查询字符串,例如title-list.php?title = 0,title-list.php?title = 1等。

title-list.php文件将接收title的查询字符串变量。基本上你要做的就是有一个链接到同一个php文件但是每个不同的电影标题的查询字符串会有所不同,这样你的title-list.php就可以确定用户点击了什么链接。

所以你原来的代码就是这个。

 <div class="row pbot ptop" style="color: #fff;"><!-- #### ROW #### --> 
    <div class="align_Center">
    <?php
        $args = array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","ALL");

    ?>
    <?php
        for($x = 0; $x < 36; $x++) {
    ?>
    <span style="color: #777;">|</span>
    <a href="title-list.php?title=<?php echo $args[$x]; ?>" class="m_headr"><?php echo $args[$x]; ?></a> <!--This line has changed-->
    <?php
        }
    ?>
    <span style="color: #777;">|</span>
    </div>
    </div><!-- #### / ROW #### -->

然后在你的title-list.php文件中添加这个

<?php
   /* 
    * header("Location: http://www.yourwebsite.com/". $_GET['title'] . ".php" );//if you want to redirect to the php file uncomment this
    */
   echo $_GET['title'];  //this will output the movie title              
?>

我希望这会有所帮助,但是你的问题对我来说仍然有点不清楚,所以我尽力回答它。