I’d like to have a static announcement at the top of my blog page, before the start of the loop. I’d like this to be something can be editable and changed through the wp-admin, so I want it to be the content of a page or a post.
Also I’d like to be able to style this announcment via the stylesheet (so perhaps I’d put it in its own div).
I’m thinking along the lines of inserting the content of a page (as opposed to a post) because the function is more like a page — something that would be edited once in a while, but would mostly be static.
Is there a way to stick the content of a page in before the loop starts? I’ve been looking at the template tags but not sure how I’d call up a page.
]]>I’m trying to conditionally display a post using the Get A Post plugin. If the post doesn’t exist, I don’t want the DIV to display:
<?php $announcement = get_post(27);
if ($announcement) { ?>
<div id="announcements">
<?php get_a_post(27);
the_content(); ?>
</div>
<?php } ?>
This returns “Fatal error: Cannot pass parameter 1 by reference”
Searched everywhere in here but didn’t find a solution. Thanks in advance!
]]>My previous template code (with get-a-post) was :
get_a_post(145);
?>
<div class="post-intro" id="intro">
<h3><?php the_title();?></h3>
<?php the_content(); ?>
<p class="postmetadata"><?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>
</div>
How can I do the same without the get-a-post plugin ?
(this is outside the loop)
I also see there is a query_posts function. But I think if I use it, the other “default” posts will not be shown anymore, i’m I wrong ? I think this function restricts the query to one post, and what I want is one specific post on the top of the page, then the others…
Thanks !
Beno?t
]]>I’ve noticed that the WYSIWYG (rich text) editor is broken when GET-A-POST is enabled.
Firefox tells me
Erreur : realTinyMCE is not defined
Fichier source : https://***/wordpress/wp-includes/js/tinymce/tiny_mce_gzip.php?ver=20070326
Ligne : 43
It’s really strange becauses the plugins seems very simple; no javascript, one single file, etc.
Here’s the code. I can’t find what is the matter…
function get_a_post($id='GETPOST') {
global $post, $tableposts, $wp_version, $wpdb;
if($wp_version < 1.5)
$table = $tableposts;
else
$table = $wpdb->posts;
$now = current_time('mysql');
$name_or_id = '';
if(!$id || 'GETPOST' == $id) {
if($wp_version < 2.1)
$query_suffix = "post_status = 'publish'";
else
$query_suffix = "post_type = 'post' AND post_status = 'publish'";
} elseif ('GETPAGE' == $id) {
if($wp_version < 2.1)
$query_suffix = "post_status = 'static'";
else
$query_suffix = "post_type = 'page' AND post_status = 'publish'";
} elseif ('GETSTICKY' == $id) {
if($wp_version < 1.5)
$table .= ', ' . $tablepostmeta;
else
$table .= ', ' . $wpdb->postmeta;
$query_suffix = "ID = post_id AND meta_key = 'sticky' AND meta_value = 1";
} else {
$query_suffix = "(post_status = 'publish' OR post_status = 'static')";
if(is_numeric($id)) {
$name_or_id = "ID = '$id' AND";
} else {
$name_or_id = "post_name = '$id' AND";
}
}
$post = $wpdb->get_row("SELECT * FROM $table WHERE $name_or_id post_date <= '$now' AND $query_suffix ORDER BY post_date DESC LIMIT 1");
get_post_custom($post->ID);
if($wp_version < 1.5)
start_wp();
else
setup_postdata($post);
}
]]>// Sponsored by Gordie Lachance
// Outputs the translation of the post ID.
function gengoGetAPost($monpost) {
global $post, $gengo, $wpdb;
$now = current_time('mysql');
$where_posts = "WHERE p.post_date <= '$now' AND p.post_status = 'publish'";
$language_ids = implode(',', $gengo->language_preference_id);
$post = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p INNER JOIN $gengo->post2lang_table AS p2l ON p.ID = p2l.post_id INNER JOIN $gengo->post2lang_table AS p3l ON p3l.post_id='".$monpost."' ".$where_posts." AND p2l.translation_group=p3l.translation_group AND p2l.language_id IN ($language_ids) LIMIT 1");
if (!$post) { // if there is no translation, show the original post
$where_posts .= " AND p.id='".$monpost."'";
$post = $wpdb->get_row("SELECT p.* FROM $wpdb->posts AS p ".$where_posts." LIMIT 1");
}
get_post_custom($post->ID);
setup_postdata($post);
}
]]>I would like my function gengoGetAPost to find (if exists) the translated post of a given post_id.
Posts are in the “$wpdb->posts” table.
Posts with their post_id, language_id and translation_group are in “$gengo->post2lang_table”.
If I have 2 posts :
|POST_ID|LANGUAGE ID|TRANSLATION_GROUP|
17 1 5
23 2 5
I would like that gengoGetAPost(17,2) returns me the row of the post #23 in the $wpdb->posts table.
Could you help me ?
Here’s my first draft (not working), but I don’t know what to do now…
function gengoGetAPost($post,$lang) {
global $gengo, $wpdb;
$language_ids = 2;
$query = "SELECT p.* FROM $wpdb->posts AS p INNER JOIN $gengo->post2lang_table AS p2l ON p.ID = p2l.post_id WHERE p2l.translation_group=$lang AND p2l.post_id='".$post."' LIMIT 1";
echo $query;
return ($result = $wpdb->get_row($query)) ? $result : NULL;
}
]]>I searched around and found links to getting adsense in between posts, and the links I found for the get-a-post and cg-inbetween plug-ins didn’t seem to work any better (but that could also be my lacking of full blown PHP skills).
What I would like, is to be able to insert content (an excerpt and more link) from a Page I made in WordPress in between my first post and the rest of the posts.
I’m pretty sure that this is possible some how, but I can’t seem to break the loop, everything I’ve tried just causes the page excerpt to be repeated at the end of every post.
Thank you in advance for any help.
]]>