Single Post
-
Does anybody know how to write simple php code in wordpress so that when I enter a particular function like <? single_entry(1) ?> for example, only the first entry from catagory 1 will show up? Thanks in advance!
-
My understanding of WordPress leads me to believe that this would be slightly difficult in the present form. An entry consists of a bunch of items which include the blog title, URL, comment trackback etc. In order to acheive what you want (if I understand you correctly, you want to simply print out the first entry of a category) you would have to modify the default b2_loop inside of WordPress to generate one entry. I patched together something for you.
Copy and paste the following code into a php file and call it single_entry.php
<?php
$blog = 1;
require_once(‘blog.header.php’);
require_once($abspath.’wp-links/links.php’);
require_once($abspath.’wp-links/links.weblogs.com.php’);
if ($posts) { $post = $posts[1]; start_b2();
the_date(”,'<h2>’,'</h2>’); ?>
<h3 class=”storytitle” id=”post-<?php the_ID(); ?>”>
” rel=”bookmark” title=”Permanent Link: <?php the_title(); ?>”><?php the_title(); ?>
<span class=”meta”>” title=”Category: <?php the_category() ?>”>[<?php the_category() ?>] — <?php the_author() ?> @ <?php the_time() ?></span>
</h3>
<div class=”storycontent”>
<?php the_content(); ?>
</div>
<div class=”feedback”>
<?php link_pages(‘
Pages: ‘, ‘
‘, ‘number’); ?>
<?php comments_popup_link(‘Comments (0)’, ‘Comments (1)’, ‘Comments (%)’); ?>
</div>
<?php include($abspath . ‘b2comments.php’); ?>
<?php } ?>
Now, put this file in your WordPress folder and simply point to it with the right category value. This should spit out the first entry for a single category, in a new webpage. Use the php include tags to put this inside your blog. Hope this helps,
PeaceJust put $posts_per_page = 1; under $blog = 1;
LaughingLizard: Wow, that code is whack! Thanks for the effort. At the moment I’m using quite an archaic way to spit out single-entries. What I do is create a “nude” page with nothing else but the WordPress header and the WP Loop. Then I do the
$posts_per_page = 1;
and$cat = 2;
under$blog = 1;
at the top which has worked for me since b2 days. This spits out the latest paged entry from catagory 2.
I primarily use this for my photoblog where I call the latest photo via iframe with the “nude” code above. So far so good, but like I said, it’s quite a rudimentary method. See it in action at https://www.truedeath.com
What I’d *like*, seeing that my knowledge of PHP is about zero, is a function<?php single_entry("456", "2"); ?>
that spits out _only_ the content of entry 456 or the latest entry from catagory 2. Perhaps this is pushing the envelope a bit far, but I hope readers see where this is going.
The problem I see is similar to what LaughingLizard pointed out. Since a blog entry is made out of several variables within a given single post, there’s nothing to stop others from requesting other modified pieces of code that spit out the author, authors email etc. Presumably, this will go ad nauseum and that’s not the way to go is it?
Perhaps someone can come up with a better solution? Right now I’m thinking a dedicated function included in the website that manually does mysql queries. Or even the ability to have 2 WP loops on one page, each having a seperate set of variables [can’t be done can it?] Help!Apologetically,I have to bow out of this topic for tonight, I have a test tomorrow … anyone else willing to help?
Maybe what we’re all looking for is a FILTER FUNCTION. Basically a function intergrated into WP that allows us to put filters on certain variables and thus the code or entry will be spat out.
I know for a fact that MT allows static includes so one can have a page with a main blog and mini sections around the page that recall specific data from single post (or X post) pages without having the code spew out the whole jinbang.
At the moment, I’m limited to having #of posts paged and catagory filters on any one page at a single time. Recalling data that is outside these filtered posts require use of an iframe.
Any circumvential methods?Anonymous>> Then I do the $posts_per_page = 1; and $cat = 2; under $blog = 1; at the top which has worked for me since b2 days. This spits out the latest paged entry from catagory 2. <<
I would love to see a solution for this problem, too.I just realized that there is a drawback to the simplicity of the single include() statement since all my links use whatever file they are on: the announcement shows up on every page on the site.
The fix is simple: test for $cat or $p to NOT be set to anything before you do the include:
<?php if( ” == $cat && ” == $p ){ include(‘https://www.huddledmasses.org/b2-include/announce.php’ ); } ?>Zaaba, you might want to look at the add_filter() function.
- The topic ‘Single Post’ is closed to new replies.