Solved

News articles functionality

Posted on 2014-10-01
38
58 Views
Last Modified: 2015-01-21
Hello, I'm having an issue with some custom programming that is built into the site but for some reason works on some pages but not on others. Here is the situation.

My site has the ability to associated post with each other. My site has a variety of different type of post such as:

Events Post
News Post

Typically I linked news post that are related to event post so when you go to the event post you will see the news announcements associated with event.

With all that being said I currently have one event that allows me to associate news post with it while I have another event that does not show the related event news. Here is the page that shows the events news:

http://supercon2k.com/supercon-2k-series-at-denver-comic-con/

As you can see the related news post show up in two areas of the event page:
-Header
-Within the contents of the event

Both use the following code in both the header.php and the the-event.php file:

Header File:
<?php 
if(in_category('4') && is_front_page()==false):


$post_slug = basename(get_permalink($post->ID));


$catKids = get_categories('child_of=4');
foreach($catKids as $kiddo): if($kiddo->slug==$post_slug):
$catKid =  $kiddo->cat_ID;
endif; endforeach;
if(!empty($catKid)):
query_posts( 
array(
      	'post_type' => array(
      	'post','video'),
      	'posts_per_page' => '-1',
      	'order' => 'DESC',
      	'cat' => $catKid,
      	'category__not_in' => 4)
); ?>

<?php if ( have_posts() ) :  ?>
<script type="text/javascript">
jQuery().ready(function(){

$('#block-news').bxSlider({
		displaySlideQty: 1,
		moveSlideQty: 1,
		infiniteLoop: false,
		hideControlOnEnd: false
		});
});
</script>

<h2 style="color: #FFF; font-size: 3.2em; margin: 60px 0 8px 6px;">Event Related News:</h2>

<div class="content" id="head-news">
<ul id="block-news">
<?php while ( have_posts() ) : the_post();
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id(get_the_ID()) , 'thumbnail' ); 

$vidID = get_post_meta($post->ID, 'video_id', true); 
$vidSRC = get_post_meta($post->ID, 'video_source', true); 


if(!in_category('80')): $post_link1 = '<a href="'.get_permalink().'" class="txt">'; 
else: $post_link1 = '<a href="http://www.youtube.com/watch?v='.$vidID.'" class="txt" rel="prettyPhoto">'; endif;

if(!in_category('80')): $post_link2 = '<a href="'.get_permalink().'" title="" style="display: block; height: 60px;">'; 
else: $post_link2 = '<a href="http://www.youtube.com/watch?v='.$vidID.'" rel="prettyPhoto" style="display: block; height: 60px;">'; endif;

?>

Open in new window


the-event.php
<?php 
/////	Event Links:
///////
$post_slug = $post->post_name;

//echo $post_slug;

//debug($post);

$catKids = get_categories('cat=4');

//debug($catKids);

foreach($catKids as $kiddo): if($kiddo->slug==$post_slug):
$catKid =  $kiddo->cat_ID;
endif; endforeach;

if(!empty($catKid)):

query_posts( 
array(
      	'post_type' => array(
      	'post','video'),
      	'posts_per_page' => '-1',
      	'order' => 'DESC',
      	'cat' => $catKid,
      	'category__not_in' => 4)
); ?>

<?php if ( have_posts() ) :  ?>

<script type="text/javascript">
jQuery().ready(function(){

$('#related-news').bxSlider({
		displaySlideQty: 1,
		moveSlideQty: 1,
		infiniteLoop: false,
		hideControlOnEnd: false
		});
});
</script>

<h2 style="color: #FFF; font-size: 3.2em; margin: 0 0 15px 0;">Event Related News:</h2>
<div class="related-news">
<ul id="related-news">
<?php while ( have_posts() ) : the_post();
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id(get_the_ID()) , 'medium' );

$vidID = get_post_meta($post->ID, 'video_id', true); 
$vidSRC = get_post_meta($post->ID, 'video_source', true); 


if(get_post_type(get_the_ID())=='post'): $post_link1 = '<a href="#news'.get_the_ID().'" rel="prettyPhoto" class="txt">'; 
else: $post_link1 = '<a href="http://www.youtube.com/watch?v='.$vidID.'" class="txt" rel="prettyPhoto">'; endif;

if(get_post_type(get_the_ID())=='post'): $post_link2 = '<a href="#news'.get_the_ID().'" rel="prettyPhoto" title="" style="display: block; height: 120px;">'; 
else: $post_link2 = '<a href="http://www.youtube.com/watch?v='.$vidID.'" rel="prettyPhoto" style="display: block; height: 120px;">'; endif;
?>

Open in new window


So right now I'm really confused by why its showing up for one event but does not show up for another event. For testing I'm trying to link the following news post:

http://supercon2k.com/come-get-man-card-broshow/

to the following event post

http://supercon2k.com/supercon-2k-series-broshow/

Currently the news post shows up on the Denver Comic Con event post without any issues.
0
Comment
Question by:DancingFighterG
  • 21
  • 17
38 Comments
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
These <ul> tags do not appear in the markup for the test page but they do for the working page.

<ul id="related-news">
<ul id="block-news">

Perhaps the test page is not being generated from the same header.php and event.php templates.
0
 

Author Comment

by:DancingFighterG
Comment Utility
Hello Tom,

The header.php that is being used is both the parent and child header.php. This issue started before we implemented the child theme. The the-event.php is being used on the parent theme. I believe there is a slug issue.
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
Based solely on what you have posted...

This <ul> is hard coded in the markup on the header.php file..

<ul id="block-news">

...so it will automatically appear on any page that uses that header.php file.

This is hard coded in the markup on the the-event.php so, same deal: <ul id="related-news">

<ul id="block-news"> and <ul id="related-news"> both appear in the markup at the link that works.

http://supercon2k.com/supercon-2k-series-at-denver-comic-con/

Neither <ul id="block-news"> nor <ul id="related-news"> appear in the markup at the other two pages..

http://supercon2k.com/come-get-man-card-broshow/
http://supercon2k.com/supercon-2k-series-broshow/

..although all three pages come from the same wordpress site.

This tells me that the two pages above are not being generated using the same header.php and the-event.php files as the working page. If they were, the <ul> blocks would be present. Maybe you are already aware of this and have concluded that this is not the issue.
0
 

Author Comment

by:DancingFighterG
Comment Utility
This is what I see in the header.php file for the child theme:

<div class="content" id="head-news">
<ul id="block-news">
<?php while ( have_posts() ) : the_post();
$imgLg = wp_get_attachment_image_src ( get_post_thumbnail_id(get_the_ID()) , 'thumbnail' );

Here is the if statement using the post functions:

if ( have_posts() ) : while ( have_posts() ) : the_post();

if($post->ec3_schedule[0]->active==1):
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
That header.php file is NOT being used to generate this page.

http://supercon2k.com/come-get-man-card-broshow/

That header.php file is NOT being used to generate this page either.

http://supercon2k.com/supercon-2k-series-broshow/

Try this. Go into that header.php and add something dramatic to the markup like this:

<div class="content" id="head-news">
<h1><span style="font-size:3em;color:red">THIS IS THE HEADER.PHP FILE TALKING!!!!!</span></h1>
<ul id="block-news">

Save everything and go to the two links above. Do you see the large red text?

Now go to this link:

http://supercon2k.com/supercon-2k-series-at-denver-comic-con/

Do you see it on that page?
0
 

Author Comment

by:DancingFighterG
Comment Utility
Ok, I added the code but I added near my social buttons. It does not show up under the tags you specified. Take a look at dev.supercon2k.com
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
Added code does not show up under the tags I specified because the tags themselves do not appear in the markup of the generated page. This is because a different header.php file is being used to generate that part of the page. Probably the header.php from the parent theme is being used instead.
0
 

Author Comment

by:DancingFighterG
Comment Utility
Tom, when I put the following code:

<h1><span style="font-size:3em;color:red">THIS IS THE HEADER.PHP FILE TALKING!!!!!</span></h1>

between those tags nothing shows up regardless if its in the header.php for the parent or the child. When I put this code  between the code that shows the buttons for our social network items the code shows up when I place it in the child theme header.php file. You can see it now in dev.supercon2k.com
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
Is the header.php file in the parent theme identical to the header.php file in the child theme?

Can you post the entire header.php file here? The snippet of the header.php file that you posted with your question has a syntax problem somewhere.
0
 

Author Comment

by:DancingFighterG
Comment Utility
Hey Tom,

Here is the two files - one being the child header file and the other being the parent header file
headerchild.php
header.php
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
My best guess:

This conditional statement is true, if(in_category('4') && is_front_page()==false):
..the code advances, but this statement, nested inside resolves to false, if(!empty($catKid)):
..code execution stops.

$catKid is empty on the two pages that do not work.

Since $catKid is indirectly populated by the result of this statement, $catKids = get_categories('child_of=4');, my best guess is that category 4 has no descendants when the two pages that do not work are built by Wordpress. Why? I have know way of knowing from what you posted.
0
 

Author Comment

by:DancingFighterG
Comment Utility
So how does that explain why this event:

http://supercon2k.com/supercon-2k-series-at-denver-comic-con/

shows news articles associated with it?
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
I don't know. You have control of how categories and sub-categories are organized. I can only respond to what I see.

You have a complex structure of nested conditionals in the header.php file. Each conditional prints something to the page when the condition is true. Based on the differences between what is being printed out in the working page vs. the two that are not working, I can determine which conditionals are executing.

On all three pages, if(in_category('4') && is_front_page()==false) is true so the code advances and certain markup is appearing on all three pages. But inside that conditional you have another conditional, if(!empty($catKid)): that is true for the page that works and false for the two pages that do not. You've shown me the code and there's nothing wrong with it. If the conditions are met it will print the markup needed. But the conditions are not being met on the two pages that do not work. This suggests that $catKid is empty for the pages that do not work. Working back in the code, the most likely reason is that category 4 has no descendants.

Try echoing something to the page just before that inner conditional, if(!empty($catKid)):. Like this:

echo (empty($catKid)) ? "<h3>catKid is empty</h3>" : "<h3>catKid is NOT empty</h3>";

It should print one or the other of those strings to the header on every page. My guess is it will print "empty" on the pages that are not working and "NOT empty" on the one that works.
0
 

Author Comment

by:DancingFighterG
Comment Utility
ok, let me do some work on this
0
 

Author Comment

by:DancingFighterG
Comment Utility
Ok, I added the code and it is verifying which items are empty and which ones are not

Two that are empty (Have no post associated with it):

http://supercon2k.com/movie-night-go-sleep/
http://supercon2k.com/movie-night-interstellar/

Two that are not empty but they say its empty and are not showing up on the site:

http://supercon2k.com/supercon-2k-series-skillcon/
http://supercon2k.com/supercon-2k-series-broshow/

One that is not empty and showing up on the site:

http://supercon2k.com/supercon-2k-series-at-denver-comic-con/
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
Can you tell me where exactly in the header.php file you put the code I suggested?

Four the four links you provided is it like this, just before the if(!empty($catKid))/:

echo (empty($catKid)) ? "<h3>catKid is empty</h3>" : "<h3>catKid is NOT empty</h3>";
if(!empty($catKid)):
0
 

Author Comment

by:DancingFighterG
Comment Utility
Here is where the code you gave me lives in the child theme header file:

<?php 
if(in_category('4') && is_front_page()==false):


$post_slug = basename(get_permalink($post->ID));


$catKids = get_categories('child_of=4');
foreach($catKids as $kiddo): if($kiddo->slug==$post_slug):
$catKid =  $kiddo->cat_ID;
endif; endforeach;
echo (empty($catKid)) ? "<h3>catKid is empty</h3>" : "<h3>catKid is NOT empty</h3>";
if(!empty($catKid)):
query_posts( 
array(
      	'post_type' => array(
      	'post','video'),
      	'posts_per_page' => '-1',
      	'order' => 'DESC',
      	'cat' => $catKid,
      	'category__not_in' => 4)
); ?>

Open in new window

0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
That's perfect, just where it should be.

I studied the header.php file carefully to try to understand the complex nesting of the various conditionals. From that study, I came up with this diagram.
Conditionals from header.php
On the four links that do not work, in the view source, I see this output:
<h3>catKid is empty</h3>

            </div><div class="clear"></div><!--|      END .grid_13      |-->

Same result for all four of those links.

That tells me that the if condition on LEVEL 1 A of my diagram is running and printing out "catKid is empty". The else condition is of course not running. Nothing in there is being printed out. However, $catKid is not being populated so no additional markup is being printed out.

On the one link that does work, again the if condition on LEVEL 1 A of my diagram is running. Only this time, $catKid is populated so the remaining code in the if condition prints out markup to the page, namely the <ul> block.

I fell like I'm repeating myself. I keep coming to the same conclusions. The problem you are having is not due to any syntax error in the code. The problem has to be either with the logic of your arrangement of the conditionals OR in the way you have organized the categories in your Wordpress site. Example: There may be some reason that category 4 has no descendants when tested for the four pages that do not work.

Perhaps you can use my diagram to better understand what is going on with the code in the header.php file. From that you could perhaps see the reason your logic is not producing the results you expect.
0
 

Author Comment

by:DancingFighterG
Comment Utility
Is there a way in WP to see what id 4 is as a category or should I just go into the DB?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
You could go into the database or you could temporarily put something in your functions.php file to print the category hierarchy and number of posts per to the head of the page. Like this:
add_action( 'wp_head', 'list_categories_all' );
function list_categories_all() {
	wp_list_categories('show_count=1');
}

Open in new window

If you want to limit it to category 4 you could:
add_action( 'wp_head', 'list_categories_all' );
function list_categories_all() {
	wp_list_categories('include=4&show_count=1');
}

Open in new window

0
 

Author Comment

by:DancingFighterG
Comment Utility
Ok so category 4 is called Schedule Events. Schedule Events is the category that I place all the post that are events for the website. I'm using my post SkillCon as a test and I have associated specific post with the post SkillCon but it still says its empty.

WP tells me that there are 5 post associated with the Skillcon event.
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
You have this line in your code:
$catKids = get_categories('child_of=4');

You are asking for children of category 4. If SkillCon is a post in a category that is not a child of the Schedule Events category (category 4) then nothing will be added to the page because $catKid will be empty.

Is SkillCon in a category that is a child of category 4?
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
Just re-reading your last post. Is SkillCon a category or a post? You call it a post more than once in your first statement but then on the final line you say 5 posts are associated with the SkillCon event. Posts cannot be associated with posts, hence my confusion.
0
 

Author Comment

by:DancingFighterG
Comment Utility
Sorry, SuperCon 2K Series at Skillcon is a category but its also the name of a post

Yes, SuperCon 2K Series at Skillcon in a category that is a child of category 4
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
How about this conditional.

if($kiddo->slug==$post_slug)

On the pages that do not work, perhaps the slugs and permalinks do not match so $catKid never gets filled.
0
 

Author Comment

by:DancingFighterG
Comment Utility
Hey Tom,

I will do an echo of $post_slug and see what it returns. You might be right about the permlinks and slugs
0
 

Author Comment

by:DancingFighterG
Comment Utility
Question, a little rusty on PHP the line:

if($kiddo->slug==$post_slug)

What does the -> mean?
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
Object -> Property

$kiddo represents a Wordpress category in this case. WP Categories have properties like slug, name, taxonomy, count, etc. Each property has a value so  object->property gives you the property's value. To assign a value to a property use =>
0
 

Author Comment

by:DancingFighterG
Comment Utility
oK thanks. I will echo the variable and see what it comes up with today
0
 

Author Comment

by:DancingFighterG
Comment Utility
Can you provide me an echo statement for the of following variables:

if($kiddo->slug==$post_slug)

So i can see what it's not getting
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
foreach($catKids as $kiddo):

echo "kiddo: " . $kiddo . ", post_slug: " . $post_slug . "<br />";

if($kiddo->slug==$post_slug):

$catKid =  $kiddo->cat_ID;

endif;  endforeach;
0
 

Author Comment

by:DancingFighterG
Comment Utility
Tried to put in this code but it caused an error
0
 
LVL 38

Expert Comment

by:Tom Beck
Comment Utility
My Bad.

foreach($catKids as $kiddo):

echo "kiddo slug: " . $kiddo->slug . ", post_slug: " . $post_slug . "<br />";

if($kiddo->slug==$post_slug):

$catKid =  $kiddo->cat_ID;

endif;  endforeach;
0
 

Author Comment

by:DancingFighterG
Comment Utility
Ok, did a test on the post that I want to link to events:

http://supercon2k.com/justin-wong-will-making-mark-supercon-2k-series/

 and I can link a new post that I have made to the following post:

http://supercon2k.com/supercon-2k-series-at-megacon/
http://supercon2k.com/supercon-2k-series-pensacon/

but it does not show on the following:

http://supercon2k.com/supercon-2k-series-skillcon/

So I'm now convinced there is something wrong with the slug or permlink of the skillcon post
0
 

Author Comment

by:DancingFighterG
Comment Utility
ok added the code and this is what I see:

http://supercon2k.com/supercon-2k-series-will-skillcon/
0
 
LVL 38

Accepted Solution

by:
Tom Beck earned 500 total points
Comment Utility
You included 5 links in your last two posts. None of them are producing markup from the if statement at level 1 A (refer to my diagram). The "else" section is producing content in 4 of the 5. On http://supercon2k.com/supercon-2k-series-pensacon/ there is no content from either the else or the if section. Bottom line, the test code is not even being reached.
0
 

Author Comment

by:DancingFighterG
Comment Utility
Ok, I was able to get news to show up in the skillcon event within the contexts of the post but it still is not showing up in the open area at the stop. I recreated the entire skillcon page. I need to see why since the news articles are  associated with the post and showing up but not in all areas that it needs to show up
0
 

Author Closing Comment

by:DancingFighterG
Comment Utility
Thanks!!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Do you think that WordPress is just for blogs?  Think again!  WordPress is really a fantastic all around platform that you can use to develop websites on.  Integrated into its basic functionality is the ability to create pages using your choice of a…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now