mac007 Posted October 5, 2008 Share Posted October 5, 2008 hello, all: I ham trying to make it so I can show a banner according to a blog articles's category(ries). per example if a posting (or postings) appears under category 101, then show banner1, if it appears on category 102, show banner2, if category 103 show banner3 and so forth. Problem is a post can belong to several categories, along 2 separate tables, in one-to-many relationship. I want the script to 'see" that a post appears in any of these specific categories and show its appropriate banner. This is a Wordpress blog setup. After I created a mysql script to bring all records into my webpage, I then created a another if-else statement to call up each banner accordingly, something like "if category xxx appears show banner1, else if category zzz appears then show banner2, else if category yyy appears then show banner3, else show ALL banners. So, right now, the problem is, if an article is tagged with ONLY that specific category, it works fine, it shows proper banner, BUT if an article is tagged across several categories, INCLUDING the one specific one (like belonging to categories 101, 12, 6, 200, etc), then it show's all banners, I figure cause it's obviously reading all other categories, and therefore shows all banners. But it should show ONLY the one banner associated with the specific category in question (in this case 101). Here are the 2 related tables which have the common post id field (see example entries, and there are many more fields, but I summarized to make easier) TABLE 1: wp_posts (posts table) ID post_title post_content post_date etc... 66 The Dog barks 67 The Cat Meows 68 The Duck Quacks 69 The Crocodile TABLE 2: wp_post2cat (Categories table) post_id category_id 66 101 66 565 66 756 67 101 68 130 SoI created a mysql-recordset to pull in articles based on a post's ID url value (articleBannersRS), and I added the code below where my banners are supposed to show up: <CODE> <? if ($row_articleBannersRS['category_id'] == '101') {include('inc_banner1.php'); } elseif ($row_articleBannersRS['category_id'] == '102') {include('inc_banner2.php'); } elseif ($row_articleBannersRS['category_id'] == '103') {include('inc_banner3.php'); } else { include('inc_banner1.php'); include('inc_banner2.php'); include('inc_banner3.php'); } ?> </CODE> As I said, posts with single categories (like posts 67 & 68) would show proper banner, but in the case of post # 66, that belongs to several categories, it would do the final "else" statement and show "ALL banners" when I want it to only show the banner that corresponds to category 101. Maybe I am not joining or doing my msql statement properly? this is my mysql statement: SELECT * FROM wp_posts, wp_post2cat WHERE wp_posts.ID = (here would be url post-id value) AND wp_posts.ID = wp_post2cat.post_id Well, this makes sense... Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/127076-help-with-showing-specific-banner-based-on-a-articles-category/ Share on other sites More sharing options...
Andy-H Posted October 5, 2008 Share Posted October 5, 2008 if ( in_array("101", $row_articleBannersRS) ){ include('inc_banner1.php'); } if ( in_array("102", $row_articleBannersRS) ){ include('inc_banner2.php'); } if ( in_array("103", $row_articleBannersRS) ){ include('inc_banner3.php'); } Would that work? Quote Link to comment https://forums.phpfreaks.com/topic/127076-help-with-showing-specific-banner-based-on-a-articles-category/#findComment-657327 Share on other sites More sharing options...
mac007 Posted October 5, 2008 Author Share Posted October 5, 2008 Thanks a lot Andy... Let me warn you I am a TRUE php beginner... let me try it; going to replace it with your include statements... Quote Link to comment https://forums.phpfreaks.com/topic/127076-help-with-showing-specific-banner-based-on-a-articles-category/#findComment-657328 Share on other sites More sharing options...
mac007 Posted October 5, 2008 Author Share Posted October 5, 2008 hmmm... no, not doing it right.. I did get an error that shows up if I dont actually give a url parameter to look for a post's ID: Warning: in_array() [function.in-array]: Wrong datatype for second argument in (url address) on line 42 It still kind of doing same thing as before, it properly shows correct banner if a post is tagged as having only THAT ONE specific category, but if it has other category tags ALONG with the one category then it shows all banners... It is also doing right thing by showing ALL banners if none of the specified categories are present... Seems like it's close, but cant figure it out... Quote Link to comment https://forums.phpfreaks.com/topic/127076-help-with-showing-specific-banner-based-on-a-articles-category/#findComment-657339 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.