• Hi I’m a noob to WP..

    I have created a custom page that reads data from a mysql table.
    The page was successfully added as a new page and is working.

    Now I want to use this template multiple times but with a parameter.

    More specific: I add a new page named Contestants 2011 and select the template. I also add a new page named Contestants 2012 using the same template.
    Where and how do I put the ?cyear=2011 or for the second page ?cyear=2012

    Is this even possible?

    All help welcome

    Thanks

    Ron

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    You can append url parameters to permalinks:
    example.com/contestants/?cyear=2012
    but it’s sort of ugly. To use a cleaner permalink format like
    example.com/contestants/2012/
    you would use the Rewrite API transform the permalink format into traditional ugly url parameters, without anyone having to look at them.

    Either way, your page template would grab the cyear value with $_GET[‘cyear’] and use that to form a query to display that year’s contestants or whatever.

    Thread Starter rbergh

    (@rbergh)

    Thanks for your response.

    but how do I add the /?cyear=2012
    When i add this at the page setup wordpress automatically removes the
    /? and = characters. I get a permalink like example.com/contestantscyear2012

    Thread Starter rbergh

    (@rbergh)

    Is it even possible to pass this parameter during the page setup without having to do a mod_rewrite?

    Moderator bcworkz

    (@bcworkz)

    Ideally, the links would be auto-generated by script based on which years are available, but that’s getting rather fancy with custom code.

    The page editor has an annoying habit of mangling code you try to put in. Using text mode usually mangles things less than visual mode, but mangles some things all the same. In such cases, the best approach is to develop a custom shortcode. For example you could develop a shortcode that will turn what you type as [contestant cyear="2012"] into a full html link like <a href="https://www.example.com/contestants/?cyear=2012" title="Contestants for 2012">Contestants for 2012</a> . Whatever year you specify in the shortcode would get replicated as needed in the appropriate spots of the html.

    Thread Starter rbergh

    (@rbergh)

    I understand.. (a little bit)

    Just some strange other idea:
    would it be possible in the page editor put a text like cyear=2012 and
    read this text in my custom template?

    meanwhile i will try the shortcode approach. (I need a wordpress training…) (I’m a Siebel/ Oracle developper)

    Moderator bcworkz

    (@bcworkz)

    That could be done, it’s pretty much how shortcodes work, except much more targeted and specialized for your application. Your template could call a custom function to output the content which first searches for “cyear=” and replaces it with appropriate html before the actual output is done.

    As an Oracle developer, you should pick this up pretty fast. My biggest hurdle was just learning where various things happen in core code. Still learning in fact.

    Thread Starter rbergh

    (@rbergh)

    Done and working ??

    In my template code I added:

    if(have_posts()) :
    while(have_posts()) : the_post();
    $event = get_the_content();
    endwhile;
    endif;

    and in the page editor I added the parameter i wanted to pass: 2012

    For other persons looking at this solution. This solution is very specific and was for me the easiest way to do this..

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custum page parameter’ is closed to new replies.