Note that there are some explanatory texts on larger screens.

plurals
  1. POList wordpress posts by category which match page title
    primarykey
    data
    text
    <p>I'm trying to list posts in the category which shares the name of the page. I.e. If you are on the "Services" page it should display posts in the category "Services". I realize it is easy to do with conditionals such as:</p> <pre><code>&lt;?php if ( (is_page('Groups')) ) { query_posts('category_name=groups'); while (have_posts()) { the_post();?&gt; &lt;h2 class="title" id="sub"&gt;Upcoming Group Programs&lt;/h2&gt; &lt;a href="&lt;?php the_permalink() ?&gt;"&gt; &lt;div class="post" id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;&lt;/a&gt; &lt;div class="entry"&gt;&lt;?php the_content(); ?&gt;&lt;/div&gt; &lt;/div&gt; &lt;?php } wp_reset_query(); //Restores Global Post Data }?&gt; </code></pre> <p>But I would like to do this without having to set multiple specific conditionals, something like:</p> <pre><code>&lt;?php //global $wp_query; // Uncomment if necessary, shouldn't be $test = the_title(); $args = array( 'cat_name' =&gt; $test // ARGS HERE ); $args = array_merge( $args , $wp_query-&gt;query ); query_posts( $args ); while (have_posts()) { the_post(); ?&gt; &lt;div class="post" id="post-&lt;?php the_ID(); ?&gt;"&gt; &lt;h2&gt;&lt;a href="&lt;?php the_permalink() ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;div class="entry"&gt;&lt;?php the_content(); ?&gt;&lt;/div&gt;&lt;/div&gt; &lt;?php } ?&gt; </code></pre> <p>Any thoughts! Obviously I could interchange the page &amp; category "name" with the "slug" or whatever works best. Thanks!</p> <p>Thanks! I changed a few things around and got it working with your suggestion.</p> <pre><code>&lt;?php $catmatch = get_the_title(); //The Query query_posts('category_name=' . $catmatch ); ?&gt; </code></pre> <p>Hopefully on the last line there I did the concatenation correctly, it seems to work but if that isn't how it is supposed to be done properly please let me know!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload