Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End [Solved] Show posts with same category name as page name

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #28197
    dryan1144
    Member

    I’m trying to come up with a solution for a photography site I am working on using WP.

    Here’s what I’m up to:

    1) I have a Gallery page, with lots of different sub-pages.
    2) Each of these sub-pages is a gallery.
    3) For example the New York sub-page will show all posts with a category name of New York.
    4) I want to use only ONE page template for each of these gallery sub-pages. So I need a way to dynamically show all posts with a category name equal to the name of the sub-page that is showing those posts.

    Does that make sense? Maybe there’s a better way of going about this? Custom fields? Bottom line is I don’t want to have to create a new page template every time a new photo gallery is added.

    The following piece of code worked for me, displaying all posts from category three, but of course means that I will have to create a new page template each time I want to add a photo gallery. Not ideal.

    Code:


    I tried using wp-title to grab the name of the gallery and find posts that have that same name:

    Code:
    ‘); if (have_posts()) : while (have_posts()) : the_post(); ?>

    …but it didn’t seem to work for me. It just returned posts from my blog category.

    Anyone have any ideas?

    Didn’t wo

    #71752
    Code:
    query_posts(array(
    ‘category_name’ => $post->post_title,
    ‘showposts’ => 10
    ));
    #71840
    dryan1144
    Member

    Dave, thanks very much for the code. It works great and is a huge help to me.

    Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Back End’ is closed to new topics and replies.