wordpress - Get current active category from multi category page -


i'm here little challenge.

the context:

i working company building new website them. being built in wordpress, btw everthing going ok.

the website has news , blog page posts on there. in special cases news post can part of blog page.

so when happens set 2 categories , put primary @ on of categories.

the challenge:

when visit post multiple categories can either go to:

http://example.com/blog/news_post 

or

http://example.com/news/news_post 

but there values on page depended on name of category. (i know not idea have no other choice in matter).

when visit page want category used field values need.

so, when going news page "news" category name when use function name.

i have tried multiple things internet said trick either don't work or (what happens most) aren't meant multi category posts getting cat of page.

if need more info please let me know.

ps. rather not url if best option take it. hope guys can help

edit

i managed it. although in end still used url beats other options lots of coding.

i came solution after post rené schubert

i out of options when saw there answer tried , worked after little tweak.

this code have now.

$url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) ); $category = substr($url, strpos($url, "category_name=") + 14); 

if have better way please let me know :) i'm better ways.

you wants display posts specific category , category name right?

i don't guess how getting, avoid confusion can create separate category template creating category-news.php file. refer this. display posts news category. here, category name display posts.

<?php             $cat_name=get_category($cat);             echo $cat_name;// diplay cat name             $cat_id=$cat_name->cat_id;             ?>             <div>                 <?php query_posts("cat=$cat_id&order=asc&orderby=date"); ?>                 <h4><?php single_cat_title(); ?></h4><hr>                 <ul>                     <?php while (have_posts()) : the_post();                        ?>                         <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>                         </li>                     <?php endwhile; ?>                 </ul>             </div> 

Comments

Post a Comment

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -