Support Forum

Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
coding-topic
Is simple press auto completing my tags?
Avatar
Scott leneau
Member
Free Members
sp_UserOfflineSmall Offline
Aug 17, 2013 - 9:24 am

I tried to add custom function to call the URL of the current topic. My goal was to wrap each of the forum and topic blocks in anchor tags, and turn them into a single button. So I wrapped them in a div, and wrote a really simple function that retrieved the URL of the corresponding topic/forum, and displayed it in an anchor tag that I coded to wrap around the div. The problem is that when the php file executes, a closing </P> tag is automatically added immediately after the opening anchor tag, resulting in a useless, empty link.

I will run through what is happening with specific filenames below, but I want to make my question clear at this point. I need to know two things: is there a function in simple:press that automatically tries to close anchor tags, something like Wordpress' autop and texturize functions? If so, in which file is it located, and is there a built-in method to deactivate it? The second thing I need to know is what purpose the function serves, if it exists? I don't want to deactivate something that might be helpful in another context.

Ok, so here's the specifics:
I am using a custom theme that consists of a slightly changed Default theme, with a custom overlay. I want the forum blocks from the "group" template file (spGroupView.php), and the topic blocks (from the "forum" template file(spForumView.php) in my custom theme to be turned into giant clickable buttons on the page. I wrote a function which I saved inside plugins > simple-press > Forum > spTopicViewFunctions.php.

The function is coded as follows, and works just fine in the topic loop:

function sp_MIBYG_topics() {
global $spThisTopic;
$topic_url = $spThisTopic->topic_permalink;
return $topic_url;
}

I can use $topic_url to echo out the URL of a specific topic in the loop, which I insert into an anchor tag at the beginning of the single topic block. I also have a closing anchor tag at the end of the topic block. This would work just fine, but when the php page is executed, a closing anchor tag ,</a>, is placed immediately after my opening tag, closing it immediately.

In case I haven't been clear enough, this function is being called inside the Topic Loop, which starts at line 147 in spForumView.php.

I checked, and I don't believe that this is Wordpress functionality. I am still testing, though, so any help you can offer to steer me in the right direction would be greatly apreciated.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Aug 17, 2013 - 12:56 pm

I do believe it is the wp functionality...  the entire forum page content is still run through wpautop filter of wp which loves to do that, though usually correctly...  we dont have a facility for balancing tags or correcting markup, but wp does...

was there a "blank line" after the opening tag?

could you show us the code segment in your topic view?

Avatar
Scott leneau
Member
Free Members
sp_UserOfflineSmall Offline
Aug 18, 2013 - 10:15 am

Hi, thanks so much for the prompt response! The code in question is in spForumView.php, immediately after the topic loop starts. I listed both the php, and the output html code from browser below.

I should mention that I have tried deactivating the autop and texturizing functions in the wordpress functions file with no change in the output. I do have page caching activated on my site, but I deleted the page cache when I test the page (I don't think that the Forum is getting cached anyway, but I'm trying to cover my bases). What I have here is an anomaly--when I view the code with my browser's element inspector (chrome), I see that the closing tag follows the anchor immediately. When I view the page source, everything seems in order. Even so, the code isn't working. I can't click anywhere on the anchor block and have it take me to the topic page. Something's screwy--check out the code below to see what I mean: 

(Sorry in advance about how much there is to read. I thought it would help to clarify things and give context)

It may also be helpful to take a look at the site I'm working on--I currently have set up a dummy installation to act as a sort of dry dock for the forum as I work on it. Here's the URL: http://www.wplab.scottleneau.c.....ic-1-forum

 

CODE: (source spForumView.php)

if (sp_has_topics()) : while (sp_loop_topics()) : sp_the_topic();

# Start the 'topic' section
# ----------------------------------------------------------------------
//This calls the URL and echos it:
$p = sp_MIBYG_topics();
echo "<a href=\"$p\">";

//THE DIV THAT ACTS AS CONTAINER FOR EACH TOPIC SECTION:

echo "<div id=\"topic_row_container\" class=\"clearfix\">";

sp_SectionStart('tagClass=spForumTopicSection', 'topic');

sp_TopicForumToolButton('', '', __sp('Open the forum toolset'));

# Column 1 of the topic row
# ----------------------------------------------------------------------
sp_ColumnStart('tagClass=spColumnSection spLeft&100px&height=50px', '','margin-left:10px;');
sp_TopicIndexIcon('tagClass=spRowIcon spLeft');
sp_ColumnEnd();

# Column 2 of the topic row
# ----------------------------------------------------------------------
sp_ColumnStart('tagClass=spColumnSection spLeft&width=300px&height=50px');
sp_TopicIndexName('tagClass=spRowName', __sp('Browse the thread %NAME%'));
if (function_exists('sp_TopicDescription')) sp_TopicDescription();
sp_TopicIndexPostPageLinks('tagClass=spInRowPageLinks spLeft', __sp('Jump to page %PAGE% of posts'));
if (function_exists('sp_TopicIndexTagsList')) sp_TopicIndexTagsList('tagClass=spTopicTagsList spButton spLeft', __sp('Tags'), __sp('Show the tags for this topic'));
if (function_exists('sp_TopicIndexTopicStatus')) sp_TopicIndexTopicStatus('tagClass=spTopicIndexStatus spButton spLeft', __sp('Search for other topics with this status'));
sp_ColumnEnd();

# Column 5 of the forum row
# ----------------------------------------------------------------------
sp_ColumnStart('tagClass=spColumnSection spRight&width=16%&height=50px', '', 'margin-top:10px; line-height:.8em;');
sp_TopicIndexLastPost('iconClass=spIcon spRight&nicedate=1&date=0&time=0&stackdate=0', __sp('Last Post'));
sp_ColumnEnd();

# Column 4 of the forum row
# ----------------------------------------------------------------------
sp_ColumnStart('tagClass=spColumnSection spRight&width=16%&height=50px', '', 'margin-top:10px; line-height:.8em;');
sp_TopicIndexFirstPost('iconClass=spIcon spRight&nicedate=1&date=0&time=0&stackdate=0', __sp('First Post'));
sp_ColumnEnd();

# Column 3 of the forum row
# ----------------------------------------------------------------------
sp_ColumnStart('tagClass=spColumnSection spRight&width=14%&height=50px', '', 'margin-top:15px; line-height:.8em;');
sp_TopicIndexPostCount('tagClass=spInRowCount', __sp('Posts'));
sp_TopicIndexViewCount('tagClass=spInRowCount', __sp('Views'));
sp_TopicIndexStatusIcons('tagClass=spStatusIcon spCenter', __sp('This topic is locked'), __sp('This topic is pinned'), __sp('This topic has unread posts'));
if (function_exists('sp_TopicIndexRating')) sp_TopicIndexRating('tagClass=spTopicRating spCenter');
sp_ColumnEnd();

sp_InsertBreak();

sp_SectionEnd('', 'topic');

//ENDS DIV THAT CONTAINS BUTTONS (notice the ending </div> and </a>)
echo "</div></a><!--End Forum_row_container-->";

endwhile; else:

sp_NoTopicsInForumMessage('tagClass=spMessage', __sp('There are no topics in this forum'));
endif;

sp_SectionEnd('', 'topiclist');

sp_SectionEnd('', 'forum');

OUTPUT:

I copied the whole topic block from my browser's source code to show you the output. What baffles me a little bit is that when I'm looking at the code in chrome's element inspector, the anchor tag has a closing tag immediately following it. But when I look at the page source code, this is what I see:

<div class='spForumTopicContainer' id='topiclist2'style="margin-top:10px;">

/*This is the problematic anchor tag. See that it is missing the closing tag now? Well, it still isn't working*/

<a href="http://www.wplab.scottleneau.com/?page_id=4/topic-1-forum/new-topic-for-the-heck-of-it">

/*This is the div that I added to surround the whole topic block. It is working just fine.*/

<div id="topic_row_container" class="clearfix">

 

<div class='spForumTopicSection spOdd' id='topic5'>

<div class='spColumnSection spLeft' style='width: auto; min-height: 50px; margin-left:10px;'>
<img id='spTopicIndexIcon5' class='spRowIcon spLeft' src='http://www.wplab.scottleneau.com/wp-content/sp-resources/forum-custom-icons/MIBYG_FORUM_ICON-copy.png' alt='' />
</div>
<div class='spColumnSection spLeft' style='width: 300px; min-height: 50px; '>
<a href='http://www.wplab.scottleneau.com/?page_id=4/topic-1-forum/new-topic-for-the-heck-of-it' id='spTopicIndexName5' class='spRowName vtip' title='Browse the thread New Topic for the heck of it'>New Topic for the heck of it</a>
</div>
<div class='spColumnSection spRight' style='width: 16%; min-height: 50px; margin-top:10px; line-height:.8em;'>
<div id='spTopicIndexLastPost5' class='spInRowPostLink'>
<span class='spInRowLabel'>Last Post
<a class='spInRowLastPostLink vtip' title='qegrtqeht' href='http://www.wplab.scottleneau.com/?page_id=4/topic-1-forum/new-topic-for-the-heck-of-it#p22'>
<img src='http://www.wplab.scottleneau.com/wp-content/sp-resources/forum-themes/MIBYG/images/sp_ArrowRight.png' class='spIcon spRight' alt=''/>
</a></span>
<span class='spInRowLabel'><br />sleneau</span><br /><span class='spInRowLabel'>2 days ago</span>
</div>
</div>
<div class='spColumnSection spRight' style='width: 16%; min-height: 50px; margin-top:10px; line-height:.8em;'>
<div id='spTopicIndexFirstPost5' class='spInRowPostLink'>
<span class='spInRowLabel'>First Post
<a class='spInRowLastPostLink vtip' title='qegrtqeht' href='http://www.wplab.scottleneau.com/?page_id=4/topic-1-forum/new-topic-for-the-heck-of-it#p22'>
<img src='http://www.wplab.scottleneau.com/wp-content/sp-resources/forum-themes/MIBYG/images/sp_ArrowRight.png' class='spIcon spRight' alt=''/>
</a></span>
<span class='spInRowLabel'><br />sleneau</span><br /><span class='spInRowLabel'>2 days ago</span>
</div>
</div>
<div class='spColumnSection spRight' style='width: 14%; min-height: 50px; margin-top:15px; line-height:.8em;'>
<div id='spTopicIndexPostCount5' class='spInRowCount'>
<span class='spInRowLabel'>Posts </span>
<span class='spInRowNumber'>1</span>
<span class='spInRowLabel'></span>
</div>
<div id='spTopicIndexViewCount5' class='spInRowCount'>
<span class='spInRowLabel'>Views </span>
<span class='spInRowNumber'>3</span>
<span class='spInRowLabel'></span>
</div>
<div id='spTopicIndexStatus5' class='spStatusIcon spCenter'>
</div>
</div>
<div style='clear: both; height:0px;'></div>
</div>

/*This is the closing tag for the div surrounding the whole topic block. As you can see, the closing anchor tag is here. Nevertheless, it still isn't working. I can't understand it.*/

</div></a>

Avatar
Yellow Swordfish
Glinton, England
SP Master
sp_UserOfflineSmall Offline
Aug 18, 2013 - 11:58 am

I need to go back and read though all of this as I just get the gist at the moment. Actually - i think I need a strong coffee and THEN go and read thought it all!

But... unless I am missing something - isn't this just because you are trying to contain a block level element (div) in an in-line element (a) which is actually not allowed and is invalid markup? I know I have had problems with Firefox mangling the output when I have tried things like that in the past...

andy-signature.png
YELLOW
SWORDFISH
Avatar
Scott leneau
Member
Free Members
sp_UserOfflineSmall Offline
Aug 18, 2013 - 6:56 pm

You're right about the block-level element inside an anchor tag being invalid markup. Weird thing is, I could have sworn that that is now allowable in HTML 5. That might be the problem, but I honestly don't know how widespread implementation is. Either way, I'd prefer that it work in earlier versions of browsers, so I will certainly try changing the div to something else.

I'll post the result here.

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Aug 18, 2013 - 7:56 pm

yes, it is allowable under html5, but doubt your site is serving html5... the forum is not...

I have actually seen it work in most browsers... but worth trying a quick change...

If still there, I can walk you through a series of our filters and we can look at the markup in intermediate stages and see when it might be going south...

Avatar
Mr Papa
Simi Valley, CA
SP Master
Free Members
sp_UserOfflineSmall Offline
Aug 18, 2013 - 9:17 pm

then again, maybe not...  looking at it again, its not run through our filters...

but we can verify what it looks like when we send it back to wp...

for grins, maybe try going to forum - integration - page and permalink and turn on the strict wp api option...

Avatar
Scott leneau
Member
Free Members
sp_UserOfflineSmall Offline
Aug 19, 2013 - 3:35 am

Ok, I tried what you suggested, and the forum disappeared. It displayed this message across the integration page at the top, and would NOT display:

The page slug is either missing or incorrect. The forum will not display until this is corrected

I fixed this by changing my permalink structure from "default" to "post name". Either way, when the forum was back up, no permutation of those three options fixed my issue.

As for changing the <div> element into an inline element to see if the issue was that you can't wrap a block-level element inside an inline element, here are my results:

I changed the code in spForumView to the following:

if (sp_has_topics()) : while (sp_loop_topics()) : sp_the_topic();

# Start the 'topic' section
# ----------------------------------------------------------------------
//BEGINS DIV THAT CONTAIND BUTTONS
$p = sp_MIBYG_topics();
echo "<a href=\"$p\">";

echo "<span id=\"topic_row_container\" class=\"clearfix\">";

sp_SectionStart('tagClass=spForumTopicSection', 'topic');

...further down the page:

sp_SectionEnd('', 'topic');

/*ENDS DIV THAT CONTAINS BUTTONS*/

 echo "</span></a><!--End Forum_row_container-->"; endwhile; else: sp_NoTopicsInForumMessage('tagClass=spMessage', __sp('There are no topics in this forum')); endif;

You can see that I have changed the <div id=\"topic_row_container\" class=\"clearfix\"> to the inline element <span id=\"topic_row_container\" class=\"clearfix\">.

The output was very revealing:

<div class='spForumTopicContainer' id='topiclist2'style="margin-top:10px;">

<a href="http://www.wplab.scottleneau.com/forum/topic-1-forum/new-topic-for-the-heck-of-it/">

<span id="topic_row_container" class="clearfix">

<div class='spForumTopicSection spOdd' id='topic5'>

Again, it shows something different in the code inspector than it does in the source code, but it seems like it would work just fine here. But it doesn't. The code inspector shows the <a> tag wrapping the <span> element, but closing immediately before the <div> tag. This seems to suggest that the filters and the autop aren't to blame. This seems a lot more like a browser-imposed issue. The reason I think that is because the source code is logically immaculate, and should work while the code inspector reflects what is actually going on on the page.

So it looks like the browser is enforcing the prohibition against wrapping div tags with anchor tags. Oh well, I suppose it's onClick to the rescue :(

Avatar
Scott leneau
Member
Free Members
sp_UserOfflineSmall Offline
Aug 19, 2013 - 3:47 am

Success!

So long as these people have javascript enabled, my code won't be broken.

I changed the code to this:

$p = sp_MIBYG_topics();
 echo "<a href=\"$p\">";
echo "<div id=\"topic_row_container\" onClick=\"window.open('$p','_blank');\" class=\"clearfix\" style=\"cursor:hand;\">";

Thanks so much for your super-prompt and helpful advice. I really do appreciate you taking the time to help me troubleshoot. Hope you have a great day!
Avatar
Scott leneau
Member
Free Members
sp_UserOfflineSmall Offline
Aug 19, 2013 - 3:59 am

Of course, I had to change that style to be cursor:pointer; before it actually worked...

Forum Timezone: Europe/Stockholm
Most Users Ever Online: 1170
Currently Online:
Guest(s) 1
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Mr Papa: 19448
Ike: 2086
Brandon: 864
kvr28: 804
jim: 650
FidoSysop: 577
Conrad_Farlow: 531
fiddlerman: 358
Stefano Prete: 325
Member Stats:
Guest Posters: 620
Members: 17365
Moderators: 0
Admins: 4
Forum Stats:
Groups: 7
Forums: 17
Topics: 10128
Posts: 79626