-2

I want to know if it's possible to display specific posts when I click on a link from a specific page to the (ex: gallery page).

Example: Let's say I have 3 posts with 3 different galleries. (post 1=wedding pictures / post 2=food pictures / post 3=dogs pictures) and I also have 3 pages.

When I'm on Page 1 and click on the gallery page link, I want to only show post 1 content (only wedding pictures). When I'm on Page 2 and click on the gallery page link, I want to display only the post 2 content.

If It's possible what would be the most simple solution?

Thank you!

Kalnode
  • 9,386
  • 3
  • 34
  • 62
Alina Ali
  • 39
  • 1
  • 8
  • 1. You should show what you've tried so far. 2. There are TONS of tutorials on this stuff out there. Try those first. 3. People shouldn't just down vote without leaving feedback. – Difster Jan 20 '19 at 20:13
  • I only searched for informations but did not find what i needed . I found that i need to create a template for this page but not the specific information that I am searching. – Alina Ali Jan 20 '19 at 20:17
  • Maybe you could help me with a tutorial because I am new to this and I don't really know how to search the exact thing that I need. So far I did not find anything to suits my needs. – Alina Ali Jan 20 '19 at 20:20

2 Answers2

1

You can first assign each photo (or post containing a photo) a category e.g. Wedding, food etc. Once that is done, create a custom menu and add the categories to it. Place this menu on an area of your page and give it a try. It should only show the required images/posts.

For more info, you can have a look at the link below: https://en.support.wordpress.com/category-pages/

Note: You may need a plugin to allow you to place categories on images. Have a look at an example at the link below: https://wordpress.org/plugins/categories-images/

1

To show specific posts based on type, category, tag or any other property, your best bet is to use a shortcode, which gives you lots of versatility in how to render the items (in a post, page, widget, template file, etc).

The shortcode could be generated by a plugin such as Bill Erickson's Display Posts, Content Views or 10's of other plugins.

Or do it manually by building your own "show some posts" shortcode and get a much better understanding of WP. You'll have to build your own html output, filters and paging, but you will end up with less plugins gumming up your installation. There's lots of tutorials for this, search for "Wordpress display posts shortcode functions.php".

E.g. Placing the following in your theme's (ideally, a child theme) functions.php file, here is a way to show a specific number of posts from a specific content type:

Place in functions.php:

function show_some_posts($atts) {

  $a = shortcode_atts([
    'post_type' => 'post',
    'posts_per_page' => 3
  ], $atts);

    $the_query = new WP_Query( $a );

    if ( $the_query->have_posts() ) {

        $string .= '<ul>';

        while ( $the_query->have_posts() ) {
            $the_query->the_post();

            $string .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';


        }

        wp_reset_postdata();
        $string .= '</ul>';

    } else {
        $string .= 'no posts found';
    }

    return $string;
}

function shortcodes_init()
{
  add_shortcode('get-posts','get_some_posts');
}

add_action('init', 'shortcodes_init');

And to render the actual list, place this shortcode in your page or post:

[get-posts posts_per_page="3"]
Kalnode
  • 9,386
  • 3
  • 34
  • 62