• Resolved opus13i

    (@opus13i)


    One of the page templates is a ‘page-blog_template.php’ I see the call

    <?php
    		if(!empty($optimizer['blog_cat_id'])){
    			$blogcat = $optimizer['blog_cat_id'];
    			$blogcats =implode(',', $blogcat);
    			}else{$blogcats = '';}
    
          $args = array(
                         'post_type' => 'post',
                         'cat' => ''.$blogcats.'',
                         'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
                         'posts_per_page' => ''.absint($optimizer['blog_num_id']).'');
          $the_query = new WP_Query( $args );
       ?>

    How would i take the page title and use that title as the category to display posts from?

    For instance I have a page with the name ‘New Jack City’ and want to display all posts from new-jack-city on that page. I could do a


    $title = get_the_title();
    $catrep = str_replace(‘ ‘, ‘-‘, $title);
    $blogCat = strtolower($catrep);

    To give me the matching category slug… but then what? I don’t have the chops to see this through :/

Viewing 1 replies (of 1 total)
  • Thread Starter opus13i

    (@opus13i)

    Oh snap! I figured it out.

    $title = get_the_title();
        $catrep = str_replace(' ', '-', $title);
        $blogCat = strtolower($catrep);
        $idObj = get_category_by_slug($blogCat);
        $id = $idObj->term_id;
    
        $args = array(
          'post_type' => 'post',
          'cat' => $id,
          'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
          'posts_per_page' => '3');
        $the_query = new WP_Query( $args );
Viewing 1 replies (of 1 total)
  • The topic ‘Unusual Request: Use Page title as category definition.’ is closed to new replies.