ThemeShaper Forums » Thematic

[closed]

Checking if you are on a category AND a specific page ID / page name

(4 posts)
  • Started 11 years ago by sixfootjames
  • Latest reply from helgatheviking
  • This topic is resolved
  1. Hi,

    I am trying to add a url link on certain pages with a certain category but exclude it from other pages who might have that category but is of a certain page name or even using a certain template page.

    I've tried many many different options and asked for help with this on the WP forums too but this leaves me to believe it's not working because I am using Thematic.

    Please see this snippet of code and what I am trying to sort out relating to the category "News".

    function add_below_the_post () {
    
    	$category = get_the_category();
    	$category = $category[0]->category_nicename;
    
    	if (!is_wp_error($category))
    	{
    		if ($category == 'student-stories')
    		{
    			echo('<a class="postFootLink" href="' .site_url() .'/people/student-stories/">Return to ' .$category .'</a>');
    		}
    		else if ($category == 'news')
    		{
    			if (is_page_template('template-page-news.php'))
    			{
    				echo('WORKING'); //here is where I want to exclude the link if it's using a certain template
    			} else
    			{
    				echo('<a class="postFootLink" href="' .site_url() .'/news/news-events/">Return to ' .$category .'</a>');
    			}
    		}
    		else if ($category == 'research')
    		{
    			echo('<a class="postFootLink" href="' .site_url() .'/research/research-snippet/">Return to ' .$category .' snippets</a>');
    		}
    
    	}
    }
    
    add_action('thematic_belowpost', 'add_below_the_post');

    There is a section in the code above where you will see I am trying to exclude the link but replaced it with a string called 'WORKING' just to test it.

    I have tried everything from is_page(16); is_page('news_events') to is_page_template('template-page-news.php'). I have also tried this...

    else if ($category == 'news' && !is_page('news-events'))
    {
    echo('<a class="postFootLink" href="' .site_url() .'/news/news-events/">Return to ' .$category .'</a>');
    }

    which doesn't work either. I'd really appreciate some insight into this please.

    Thanks ;)

    Posted 11 years ago #
  2. just b/c you can't get your conditionals right... that doesn't make it a thematic issue.

    looks like you're getting turned around b/c you are using a page template to display a particular category? the blog template is being deprecated, b/c you already have a template for displaying categories... it is called category.php. (which calls thematic_category_loop() )

    anyway, i suspect you are doing a new query on this page template. when that happens you obliterate the old query... and in your new loop (where you are accessing thematic_belowpost() ) all the $post data is now the $post data for the newly queried posts and it no longer knows that you are even ON a page template... so conditionally checking for a template will always be false.

    anyway that's the best i can do for now since i am confused by your implementation of page templates on what seems like single posts? or maybe category archives? and calling things pages when a page is something particular in WP and doesn't have categories. explain further and i might be able to help further.

    have you tried echoing out :

    $category = get_the_category();
    $category = $category[0]->category_nicename;
    
    echo "the category is = " . $category;

    to see what you are getting?

    Posted 11 years ago #
  3. Hi Helga,

    I thought it was something to do my misunderstanding of Thematic because I had tried a hundred different options before I posted and nothing was working.

    Anyway, this finally did the trick.

    function add_below_the_post () {
    
    	global $post;
    	$category = get_the_category();
    	$category = $category[0]->category_nicename;
    
    	global $pagename; //this is what I needed to check the page name I am on
    	$news_page_name = $pagename; 
    
    	if (!is_wp_error($category))
    	{
    		if ($category == 'student-stories')
    		{
    			echo('<a class="postFootLink" href="' .site_url() .'/people/student-stories/">Return to ' .$category .'</a>');
    		}
    		else if ($category == 'news' && $news_page_name != 'news-events')
    		{
    			echo('<a class="postFootLink" href="' .site_url() .'/news/news-events/">Return to ' .$category .'</a>');
    		}
    		else if ($category == 'research')
    		{
    			echo('<a class="postFootLink" href="' .site_url() .'/research/research-snippet/">Return to ' .$category .' snippets</a>');
    		}
    
    	}
    }
    
    add_action('thematic_belowpost', 'add_below_the_post');

    Thanks for the help!

    Posted 11 years ago #
  4. i still kind of think you should make the switch to using a category template, but that is good info to know. i've been stuck there before myself.

    Posted 11 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.