Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Plugins & Atahualpa (http://forum.bytesforall.com/forumdisplay.php?f=16)
-   -   Posts of Category "Bulletin" on home page? (http://forum.bytesforall.com/showthread.php?t=2822)

RAMilewski Aug 4, 2009 04:31 PM

Posts of Category "Bulletin" on home page?
 
I'm running Atahualpa 3.4.2 on Wordpress 2.8.3. ...and I'm a Wordpress NOOB.

Mostly, I'm using Wordpress as a CMS for a site with lots of static pages. But I would like to have the most recent post (preferably the most recent post in the "bulletin" category) appear above the content of the page "home".

Settings>Reading>Front Page Displays is set to "a static page".

Can I add something to Altahualpa Options in the "content ABOVE the LOOP" section to display the latest post in the "bulletin" category?

or....

Should I change Settings>Reading>Front Page Displays to "your latest posts" with a loop size of 1, and try to add something to Altahualpa Options in the "content BELOW the LOOP" section to display the page "home". ...if so what goes there?

Thanks!

Flynn Aug 8, 2009 06:00 AM

See http://codex.wordpress.org/Template_Tags/query_posts

and wrap your code into

<?php if ( is_front_page() ) {
...query_posts code here, without opening and closing php tags <?php ... ?>
} ?>

RAMilewski Aug 14, 2009 02:05 PM

Thanks, that gets me closer, but I'm unclear where to place that code.

The code snippet I'm using is:

<?php if ( is_front_page() ) { query_posts('showposts=1&cat=6'); } ?>

If I put that in the "Content ABOVE the LOOP" section, then the desired post displays correctly, but front page never displays.

What did I misunderstand?

Flynn Aug 16, 2009 04:10 AM

You're right, the query_posts stomps the page content. I suggest the plugin Page2Cat which can combine static page content and posts http://wordpress.org/extend/plugins/page2cat/

RAMilewski Aug 16, 2009 12:28 PM

Thanks Flynn!

I had looked at that briefly and gave it a pass because it was listed as being compatible only up to Wordpress 2.5. ...but I'll give it a try and report the results back here.

RAMilewski Aug 16, 2009 05:21 PM

Hmmm... OK so I think I can make this work, but there are some problems with page2cat (or Category Pages as it calls itself in the dashboard):

1 - It appears to be unsupported, so I doubt we ever see a real 2.8 version. Neither the support forum link nor the author link appear to work. That said, I haven't seen any bad behavior in WP 2.8.4 with Atahualpa 3.4.2.

2 - The short-tag functionality, which is the part I need, only puts up a link-list of the selected posts.

3 - It puts the posts after the page title and before the page content. I can finesse this problem by checking the "Do Not Dispaly" box in Atahualpa Page Options and putting my front page title in the body in a <h1 class="pseudo-headline"> tag, and then defining the style for that in the Add HTML/CSS Inserts section of Atahualpa theme options. I had thought I could just use a <h1 class="post-headline"> tag, but that doesn't work for reasons I don't understand.


Solving problem #2 was a bit more involved. Let me preface this by saying I'm not a php or Wordpress expert, and I've never written a plug-in for Wordpress. But... I cranked up my courage and added the following lines to page2cat.php starting about line #631:

PHP Code:

// Hack by RAMilewski to filter the content of a page, check for [bulletin=xx] tag and replace it with the posts in the requested category  

// NOTE: uses the same count and category settings as the [catlist=xx] tag. This is bad.
function page2cat_bulletin($content){
global 
$post;
    if ( 
stristr$content'[bulletin' )) {
        
$search "@(?:<p>)*\s*\[bulletin\s*=\s*(\w+|^\+)\]\s*(?:</p>)*@i";
        if    (
preg_match_all($search$content$matches)) {
            if (
is_array($matches)) {
                
$output "<div class='p2c_bulletin'>";
                
$limit get_option('p2c_catlist_limit');
                foreach (
$matches[1] as $key =>$v0) {
                    
$catposts get_posts('category='.$v0."&numberposts=".$limit);
                        foreach(
$catposts as $single):
                        
$output .="<h2>".$single->post_title."</h2>";
                        
$output .="<p>".$single->post_content."</p>";
                        endforeach;
                        
$output .= "</div>";
                    
$search $matches[0][$key];
                    
$replace$output;
                    
$contentstr_replace ($search$replacecontent);                
                }
            }
        }
    }
return 
$content;


I also added this line at the end of the file:


PHP Code:

add_filter('the_content','page2cat_bulletin'); 


These changes appear to add a new short tag of the form [bulletin=xxx] that works like the page2cat [catlist=xxx] tag except that it inserts both the title and content of the post into the page.

You can style the insert by adding styles for the class p2c_bulletin to the Add HTML/CSS Inserts section of Atahualpa theme options.

If anyone out there decides to duplicate this, please note that it was implemented by a bear of very little brain, and that it has been only summarily tested. I don't know the plug-in development process well enough to work through the issues of giving the [bulletin=xxx] short tag it's own category and limit controls in the Category Pages control panel, at least not within the time I have allotted for this project, so this whole thing should be considered just an unsupported hack.

The new function is a slight modification of the page2cat_content_catlist() function which comes just before it in the hacked file. Note that I believe there is an error in that function. The line:

$output .= "</ul>";

near the end of the function should, I believe, be moved to just after the endforeach; line so that the closing tag is included in $content by the str_replace() operation.


All times are GMT -6. The time now is 01:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.