• I am attempting to write a plugin which will display a dynamic page based on a GET request. For example:

    https://mydomain.com/?showme=thisitem

    would display a page with information about “thisitem”.

    I would also like to make this theme independent so I would like to not require a special template. I’m not sure of the best way to do this.

    I thought this would be the approach to take but I can not figure out how to bulldog my page content into the page. This, of course, doesn’t work but it demonstrates what I’m trying to do:

    add_action('init', 'show_item');
    
    function show_item() {
      $showme = $_GET['showme'];
      if ( !empty($showme) ){
        $post="My Dynamic Page Content";
        include(TEMPLATEPATH . '/page.php');
        exit;
      }
    }

    how do I go about getting my own page content to display like normal page content?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Tom Penney

    (@blots)

    Can anyone point me in the right direction here?

    Thread Starter Tom Penney

    (@blots)

    As a side note, how does one post in the advanced forum?

    This is what I ended up doing although I can’t help but think there is a much better way to do this. Please, any comments welcome, abusive or otherwise ??

    what this does is gets one post then modifies it to contain my content:

    add_action('init', 'show_item');
    
    function show_item() {
      $showme = $_GET['showme'];
      if ( !empty($showme) ){
         add_filter('the_content', 'replace_content');
         add_filter('the_title', 'replace_title');
         add_filter('post_limits', 'limit_1_post' );
         //addfilter([other filters to remove other stuff you dont want to display]);
         add_action('template_redirect', 'replace_template');
      }
    }
    
    function replace_content($text) {
      //do somthing to generate content with $_GET['showme']
      $mycontent = "My Dynamic Content";
      return $mycontent;
    } 
    
    function replace_title($text) {
      return "My Title";
    }
    
    function limit_1_post($limit) {
      return 'LIMIT 1';
    }
    
    function replace_template() {
      include(TEMPLATEPATH . '/page.php');
      exit;
    }

    I don’t know… that seems to make sense to me.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘creating dynamic pages’ is closed to new replies.