WordPress.org

Ready to get started?Download WordPress

Forums

dynamically retrieving a single post from the url variable (3 posts)

  1. laurim
    Member
    Posted 8 years ago #

    I am using WP as a CMS for a DJ site. He will have a Videos page with a list of videos. I have defined a Videos category for posts that have the code to display each movie. The Video page displays the most recent video and then has a list of links to the older videos. The links are in the form of "/video.php?p=12" I'd like for a person to be able to click the link, the page refreshes or goes to a video2.php page or popup that shows that video and the list of other videos. I added code to Request the variable 'p' from the url. that works. But I can't insert that value into the query string to pull a certain post from the database. The query works if I use

    <?php query_posts('p=13');?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_title(); ?><br />
    <?php the_content(); ?>
    <?php endwhile;?>

    But doesn't if I try

    <?php $video = $_REQUEST['p']; echo $video; $page = "'p=".$video."'";?>
    <?php query_posts("'p=".$video."'");?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_title(); ?><br />
    <?php the_content(); ?>
    <?php endwhile;?>

    or

    <?php $video = $_REQUEST['p']; echo $video; $page = "'p=".$video."'";?>
    <?php query_posts($page);?>
    <?php while (have_posts()) : the_post(); ?>
    <?php the_title(); ?><br />
    <?php the_content(); ?>
    <?php endwhile;?>

    Is there a way to get a single post dynamically based on the url without using a template system? I tried the get single post plugin but it didn't work for me and wouldn't be dynamic either.

  2. Michael Bishop

    Posted 8 years ago #

    not sure when you say page, but you can define specific category pages as well, and have custom code for them. You may want to pull the permalink as well as title, that will provide a clickable link to the single page view of that post.

  3. laurim
    Member
    Posted 8 years ago #

    I guess I could go on the template system just for Videos, make a category-7.php template and use an if (is_category (7) ) statement to serve a special single_video.php page for single video pages. Is this what you mean? Sure would be easier if I could just get the post from the url variable and keep reusing the same main page. I suppose if I knew MySQL better I could extract the data from the database without WP.

Topic Closed

This topic has been closed to new replies.

About this Topic