WordPress.org

Ready to get started?Download WordPress

Forums

how i can show part of the page without GET method ? (6 posts)

  1. B A R T A R E E N
    Member
    Posted 1 year ago #

    Greetings to all
    I raised the issue that I think a lot of searches and I can not find the right thing.

    Well friends, I'll explain with an example, say the address and the site has a page on the site:
    http://www.foo.com/this-is-sample-post/
    This page shows information like maps, descriptions and pictures are. By entering this page address, all the content is displayed.

    I use php and get method to show part of the post:

    http://www.foo.com/this-is-sample-post/?part=maps

    And

    http://www.foo.com/this-is-sample-post/?part=info

    And

    http://www.foo.com/this-is-sample-post/?part=photo

    This is the way different parts of the detailed display. But the problem is that the page address not user friendly. What can I do to different parts of address? The above examples come in the form below:

    http://www.foo.com/this-is-sample-post/maps

    And

    http://www.foo.com/this-is-sample-post/info

    And

    http://www.foo.com/this-is-sample-post/photo

    Friends I not need to plugin. I am looking for a functional code. Thank you.

  2. bcworkz
    Member
    Posted 1 year ago #

    The Rewrite API does exactly this, takes user friendly urls and rewrites them into usable url parameters.

  3. B A R T A R E E N
    Member
    Posted 1 year ago #

    Thank bcworkz, I think rewrite is usage for pages with custom template, I cant use this for posts !

  4. bcworkz
    Member
    Posted 1 year ago #

    Well the code has to reside somewhere, template, functions.php, or plugin, regardless. If the rewrite output results in an url usable by WP without customization, no special template is required.

    Unless your theme supports partial post segments you will need custom code somewhere, even with just url parameters.

  5. B A R T A R E E N
    Member
    Posted 1 year ago #

    thank you BcWorkz :) rewrite rules is useful for my problem, but I have some little problem. I have posts in custom post type, I want use a custom query in their post and paginate it, but i cant. this is my sample codes:

    1- in single post type (city-single.php):

    $type = 'city';
      $args=array(
        'post_type' => $type,
        'post_status' => 'publish',
        'paged' => $paged,
        'posts_per_page' => 10,
        'caller_get_posts'=> 1
      );
      $temp = $wp_query;
      $wp_query = null;
      $wp_query = new WP_Query($args);
    ?>
    <?php if($wp_query->have_posts()) : while($wp_query->have_posts()) : $wp_query->the_post(); ?>
    <?php the_title();?><br />
    <?php endwhile; else : ?>
    <?php endif; ?>
    <?php it_pages($pages = '', $range = 5);?>

    2- In my Functions.php I have this code for rewrite rules and paginate:

    $virtualCityPages = array(
            'photos' => 'Photos',
            'info' => 'Info',
            'maps' => 'Maps',
        );
        add_filter('rewrite_rules_array', 'it_insertrules');
        add_filter('query_vars', 'it_insertqv');
        function it_insertrules($rules)
        {
            global $virtualCityPages;
             $newrules = array();
            foreach ($virtualCityPages as $slug => $title)
            $newrules['city/([^/]+)/' . $slug . '(/page/([0-9]+)?)?/?$'] = 'index.php?city=$matches[1]&vpage=' . $slug.'&pages=$matches[3]';
            return $newrules + $rules;
        }
        function it_insertqv($vars)
        {
            array_push($vars, 'vpage');
            return $vars;

    with this codes I cant paginate the content. :(

  6. bcworkz
    Member
    Posted 1 year ago #

    There's no technical reason you shouldn't be able to paginate. WP_Query supports it, and knows nothing of the rewrite API. There must be a glitch somewhere. Unfortunately, I've no idea what it might be from the code you posted.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.