Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

celticpride678

Guest
Original poster
Feb 15, 2009
5,486
2
Boston, MA
I need some help coding a "BREAKING NEWS" image that when activated on a specific post, will show an image in the post. I have no idea where to start, but here is what I'm thinking:

When on the New Post page, the author can check a checkbox that will "activate" the Breaking News feature. I need help making the code for both the New Post page and actually placing the image into the code (I can position it later).

Does anyone have any ideas? Thanks.

I'm using the Mystique theme and WordPress 2.9.2

http://www.itsalltech.com
 
A piece of this may be done using WordPress's custom fields feature. This will likely need to be created as a plug-in, which can be a pain to develop if you're new to it. You can look through the plug-in directory to see if someone else has already created this type of feature.

Thanks! That worked perfectly. Now do you know of a code that when a checkbox is checked, it automatically fills in a form? Thanks.
 
Thanks! That worked perfectly. Now do you know of a code that when a checkbox is checked, it automatically fills in a form? Thanks.

Do you mean like with JavaScript? If so, you can attach a mouse click event on the checkbox, then you just grab the text field and set the text value. Below is some quick sample code. The JavaScript cannot run until after the page is loaded to will need to be added to the onload event.

HTML:
<input type="checkbox" name="breaking" id="breaking" />
<input type="text" name="field" id="field" />
PHP:
var chbox = document.getelementById('breaking');
chbox.onclick = function() {
	var textfield = document.getElementById('field');
	textfield.value = 'your value';
}
 
Do you mean like with JavaScript? If so, you can attach a mouse click event on the checkbox, then you just grab the text field and set the text value. Below is some quick sample code. The JavaScript cannot run until after the page is loaded to will need to be added to the onload event.

Well, that code wouldn't work for me. What I'm trying to do is setup a checkbox asking the author whether this is breaking news or not, and when the checkbox is checked, it fills in the information into the Custom Field Images widget (which is the plugin I downloaded). Thanks for the help so far.
 
Well, that code wouldn't work for me. What I'm trying to do is setup a checkbox asking the author whether this is breaking news or not, and when the checkbox is checked, it fills in the information into the Custom Field Images widget (which is the plugin I downloaded). Thanks for the help so far.

How doesn't it help? It's got a checkbox and fills a text field when clicked.
 
Show the HTML the plugin outputs that needs filling. Hopefully it has some id attribute to make it easy to grab.

Here is the code.
 

Attachments

  • dgh0ef.jpg
    dgh0ef.jpg
    61.8 KB · Views: 93
  • r201n6.jpg
    r201n6.jpg
    96.6 KB · Views: 87
I'm not sure which fields you wanted to use. I don't see any check boxes, just radio buttons. Below is code that attaches click events to those radio buttons and when clicked will fill out the image field url with a default value. I can't test this code, but should be pretty close.
PHP:
function addEvent(el, eType, fn, uC) {
	if (el.addEventListener) {
		el.addEventListener(eType, fn, uC);
		return true;
	}
	else if (el.attachEvent) {
		return el.attachEvent('on' + eType, fn);
	}
	else {
		el['on' + eType] = fn;
	}
} 

function InitRadioButtons() {
	var radios = document.getElementsByName('cfi-align');
	for (var a=0, b=radios.length; a<b; ++a) {
		addEvent(radios[a], 'click', function() {
			var textfield = document.getElementById('cfi-url');
			textfield.value = 'your value';
		}, false);
	}
}
addEvent(window, 'load', InitRadioButtons, false);
 
I'm not sure which fields you wanted to use. I don't see any check boxes, just radio buttons. Below is code that attaches click events to those radio buttons and when clicked will fill out the image field url with a default value. I can't test this code, but should be pretty close.
PHP:
function addEvent(el, eType, fn, uC) {
	if (el.addEventListener) {
		el.addEventListener(eType, fn, uC);
		return true;
	}
	else if (el.attachEvent) {
		return el.attachEvent('on' + eType, fn);
	}
	else {
		el['on' + eType] = fn;
	}
} 

function InitRadioButtons() {
	var radios = document.getElementsByName('cfi-align');
	for (var a=0, b=radios.length; a<b; ++a) {
		addEvent(radios[a], 'click', function() {
			var textfield = document.getElementById('cfi-url');
			textfield.value = 'your value';
		}, false);
	}
}
addEvent(window, 'load', InitRadioButtons, false);

Thanks, that was it. It needed a little modifying, but I got it. Thanks for all the help.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.