Hey, I have a Wordpress template that I've been working on. I've been getting frustrated because I've been getting errors everytime I try using the query function in Wordpress. Like I've been trying to show post from a certain category in one section and show a certain post in one section. Let me know if you will be able to do this. Please PM me your quotes. Thanks.
I'm getting various syntax errors. When I go to the line it tells me the last line in the document which sometimes has nothing on it. Also, the lines I enter to get specific posts or categories give errors in my template but not in others. I believe it may be a deeper problem since I don't have a function.php file. However, I need this problem solved soon.
It is a custom theme. Here is the index.php code. <?php get_header(); ?> <div id="content"> <div id="homepage"> <div id="homepagetop"> <div class="featuredtop"> <?php include (ABSPATH . '/wp-content/plugins/plugin-name/plugin.php'); ?> </div> </div> <div id="homepagebottom"> <div class="featuredbottom"> <h2>Header2</h2> **THE SINGLE POST IS TO BE HERE** </div> </div> </div> <?php include(TEMPLATEPATH."/sidebar.php");?> </div> <!-- The main column ends --> <?php get_footer(); ?> Code (markup): I tried using <?php while (have_posts()) : the_post(); ?> <?php query_posts('cat=3&showposts=2'); ?> Code (markup): and <?php while (have_posts()) : the_post(); ?> <?php query_posts('p=1'); ?> Code (markup): And I get errors like the following everytime. However, those lines work in other templates just not mine. Also, I've remove widgets. Parse error: syntax error, unexpected $end in /home/username/public_html/wp-content/themes/theme_name/index.php on line 64 Code (markup):
look like you need to read up on the loop, no need to hire anyone, keep your money in your pocket for your next project. Here is a simple wordpress loop taken from the standard theme apply your css and div's where needed to separate the info, you can add in various tags like author, time etc, read the link below you need to read up on the loop how it opens and closes, it really is simple. have a look here hxxp://codex.wordpress.org/The_Loop hope that helps, if you need any more help drop me a pm or lets discuss it here Regards Roy Bunq
You guys are the hero for the day. I forgot about adding that line <?php endwhile; ?> Now, the only issue I have is with the following code. <?php query_posts('cat=1&showposts=2'); ?> <?php while (have_posts()) : the_post(); ?> <h2><?php the_title(); ?></h2> <?php endwhile; ?> Code (markup): How can I add and limit the amount of words shown and have an option to "Continue Reading?" Help is greatly appreciated.
for that, you just need the Custom Excerpts plugin: http://wordpress.org/extend/plugins/custom-excerpts/ or just use the instructions below: 1. In your functions.php , add the following function: function custom_excerpt($text, $chars) { $text = strip_shortcodes($text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $pattern = "/\[(.*?)\b[^>]*\]/ims"; $text = preg_replace($pattern, "", $text); $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text . "..."; echo $text; } PHP: 2. To display the text (with character amount limiting), put this in the loop: <?php custom_excerpt($post->post_content, 300); ?> PHP: that will limit the text to 300 character 3. to display the read more link (continue reading), put this (also in the loop): <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Read More...</a></div> PHP:
When I use the following I get the error below. <?php query_posts('cat=1&showposts=2'); ?> <?php while (have_posts()) : the_post(); ?> <h2><?php the_title(); ?></h2> <?php custom_excerpt($post->post_content, 300); ?> <?php endwhile; ?> Code (markup): This is the sidebar.php code. <div> <div class="news_updates"> <h2>News Updates</h2> <?php query_posts('cat=1&showposts=2'); ?> <?php while (have_posts()) : the_post(); ?> <h2><?php the_title(); ?></h2> <?php custom_excerpt($post->post_content, 300); ?> <?php endwhile; ?> </div> </div> Code (markup):
Now, the following shows at the top of the page. function custom_excerpt($text, $chars) { $text = strip_shortcodes($text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $pattern = "/\[(.*?)\b[^>]*\]/ims"; $text = preg_replace($pattern, "", $text); $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text . "..."; echo $text; } / Code (markup): And this appears at the /wp-admin/ login page. function custom_excerpt($text, $chars) { $text = strip_shortcodes($text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $pattern = "/\[(.*?)\b[^>]*\]/ims"; $text = preg_replace($pattern, "", $text); $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text . "..."; echo $text; } Warning: Cannot modify header information - headers already sent by (output started at /home/username/public_html/wp-content/themes/themename/functions.php:15) in /home/thecubeh/public_html/pmb/wp-includes/pluggable.php on line 865 Code (markup): I never had a functions.php file before. I just added it and copied your code straight to create it.
Now, just put this code in that functions.php <?php function custom_excerpt($text, $chars) { $text = strip_shortcodes($text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $pattern = "/\[(.*?)\b[^>]*\]/ims"; $text = preg_replace($pattern, "", $text); $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text . "..."; echo $text; } ?> PHP: That will work. I've used this code for a number of my theme... for example: http://forums.digitalpoint.com/showthread.php?t=1398365
i still can't figure out the solution and cauz i have come acoss the same problem but different errors
friends here is my msn: , add me, at the moment i am so tired and sleepy, i worked whole night and its 8:21AM here, so i will come online in the evening, will try my best to help each one thanks
Now I changed the functions.php to <?php function custom_excerpt($text, $chars) { $text = strip_shortcodes($text); $text = str_replace(']]>', ']]>', $text); $text = strip_tags($text); $pattern = "/\[(.*?)\b[^>]*\]/ims"; $text = preg_replace($pattern, "", $text); $text = substr($text,0,$chars); $text = substr($text,0,strrpos($text,' ')); $text = $text . "[B]Continue Reading...[/B]"; echo $text; } ?> Code (markup): How can I turn that into a link to view the rest of the post?
3. to display the read more link (continue reading), put this (also in the loop): <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Read More...</a> PHP: Please read the post above carefully before asking. If you still have problem with that one, you clearly need someone to look at your code.
or alternatively just write the exact number of words you want to display in the excerpt and add the read more link below that izwanmad has added, then you write the full post in the normal WYSIWYG panel, that will display on the page when a user clicks through. a simple solution if your not up on code, but probably not the best way to do it ! All the best Roy
If you still need someone to do it, please pm me with your budget and your MSN or YM. I'm more than willing to help you.