Search code examples
phpwordpressarchive

would it be possible to use archive-movies-title.php


I have a custom post type movies and what I am trying to do is list the movie titles in order of initial letter, which works if I create 36 .php files .eg title-a, title-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 #### -->

Is there any way that I can do it all through a single file called .eg archive-movies-title and with a loop containing get_queried_object()->name. I don't know if I am close to the mark or I am fishing without a rod.


Solution

  • From what I understand what you want to do is have a list of links to the same php file and then this php file determines which link the user has pressed.

    To do this you could use query strings i.e. title-list.php?title=0 , title-list.php?title=1 etc.

    The title-list.php file will then recieve query string variable of title. Basically what you will have to do is have a link to the same php file however the querystring will be different for each different movie title that way your title-list.php will be able to determine what link the user has clicked.

    So your original code will be this.

     <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 #### -->
    

    Then in your title-list.php file add this

    <?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              
    ?>
    

    I hope this helps, however your question is still a little unclear to me so I have tried to answer it as best I could.