i have a website in joomla, and forum: MYBB,
i installed simplepie to show last posts on my home page,
It works,
But i have only 2 little problems
The update links are posting on a new line so it becmes double, i want it to be updated
The RE: before every reply, i want this to be deleted
example: http://i.imgur.com/MHDAl7A.png
code:
<?php require_once('php/autoloader.php');
$feed = new SimplePie();
$feed->set_feed_url('http://localhost//forum/syndication2.php');
$feed->enable_cache(false);
$feed->init();
$feed->handle_content_type();
?>
<?php foreach ($feed->get_items(0, 10) as $item): ?>
<li><?php echo $item->get_title(); ?></li>
<?php endforeach; ?>
Related
I want display 30 posts on category.php , but after 10 post loop is terminating where as i have more then 30 posts for particular category . I have tried on category.php with if(have_posts() )
Ohh i got answer .. It is simply SETTINGS -> READING -> Blog pages show at most
#Dibya
try this way to show the number of posts on category.php without affecting blog page
<?php
$query = new WP_Query('category_name=Category&posts_per_page=30');
if($query->have_posts()) : while($query->have_posts()) : $query->the_post();
if (has_post_thumbnail()) {
?>
<?php the_post_thumbnail(); ?>
<?php
}
?>
<h2><?php the_title(); ?></h2>
<?php
the_excerpt(); // or the_content(); for full post content
endwhile;endif;
?>
This can also be resolved using posts_per_page = -1 parameter in wp_query. By using this , you don't need to bother about the backend settings. This will always works.
I am unable to fetch post tags added from wordpress admin panel. I am using fishpig magento extension and everything is working perfectly.
I am fetching posts using the code
$posts = $this->getPosts();
and I need tags associated with each post.
Please help.
You can get the tags for an individual post by calling the getTags method on the post object. Here is a snippet pertaining to post tags from the post view template:
<?php $tags = $post->getTags() ?>
<?php if (count($tags) > 0): ?>
<span><?php echo (count($categories) == 0) ? $this->__('This post was tagged with') : $this->__('and was tagged with') ?> </span>
<?php $it = count($tags) ?>
<?php foreach($tags as $tag): ?>
<a href="<?php echo $tag->getUrl() ?>">
<?php echo $tag->getName() ?>
</a><?php if (--$it > 0): ?>, <?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
You have a collection of posts rather than a single post, you can call getTags on an individual post as you are iterating over your collection.
foreach($posts as $post) {
$tags = $post->getTags();
}
I am using Diamond MultiSite Widget in my site. Alongwith post title, url, description, I also want to display the post thumbnail. I have tried many times, contacted the plugin author for help but in vein. Does anyone know how to do it?
Ref: Please check 'Latest Questions' block in this quotation page.
Thanks.
First of all, you have to get the post id to belong that you get a post thumbnail image of that
Second, you have to display the post-featured Image.
Then this code is not working. please specify your actual requirement.
<?php $pages = get_pages(array('child_of' => 1)); ?>
<?php foreach ($pages as $page): ?>
<?php echo get_the_post_thumbnail($page->ID, 'thumbnail'); ?>
<h1><?php echo $page->post_title; ?></h1>
<?php echo $page->post_content; ?>
<?php endforeach; ?>
I'm trying to have a post from a certain category display on my static homepage.
I seem to everything working just how I'd like with one exception.
I'd like the post to included the standard Continue reading (<!--more-->) link, but I can't seem to get it to work on my homepage instead all the post's content is displayed.
Here's the code I'm using to display the one post from a catagory on my home page:
<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><?php the_title(); ?></h2>
<?php the_content( __( 'Continue reading →')); ?>
<?php endwhile; ?>
How do I get the <!--more--> tag to work correctly with the above code?
The <!--more--> quicktag generally doesn't work on anything other than the Home page. Try following the advice here under "How to Read More in Pages", i.e. like this:
<?php
global $more;
$more = 0;
?>
//The code must be inserted ahead of the call to the content
Then continue as you were:
<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><?php the_title(); ?></h2>
<?php the_content( __( 'Continue reading →')); ?>
<?php endwhile; ?>
You'll need to set $more to 0 before every the_content() call;
It resets every time it hits the loop.
The discussion topic referenced from that Codex entry talks about exactly the problem you're solving, I think.
I was able to find some information here: http://codex.wordpress.org/Function_Reference/the_content
Found these lines which seem to do the trick:
global $more; // Declare global $more (before the loop).
$more = 0; // Set (inside the loop) to display content above the more tag.
the_content("Read More");
Added the information to my code and everything work! Added in the Read More link when the more tag was added to the post.
Here's my final code:
<?php $recent = new WP_Query("cat=4&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>
<h2><?php the_title(); ?></h2>
<?php global $more;
$more = 0;
the_content("Read More");
?>
I am trying to set my WordPress homepage to a category but it only allows me to set it to either the latest posts or a static page.
Is it possible to set your homepage as a post category?
I am hoping that you know about how to set static page. So first create an empty .php file and name it whatever you like and put it along the other files (index.php, arhive.php etc).
and then enter following code
<?php
/*
* Template Name: Category based Homepage
*/
?>
<?php get_header(); ?>
<div class="main">
<?php
$cat_ID = '1'; //it should be your category ID, you can get the id of the category by going to categories and edit and then in url you can find the tag_ID.
$posts_to_show = '10'; // number of posts from the category you want to show on homepage
//query_posts("cat=$cat_ID&showposts=$posts_to_show");
$category_posts = new WP_Query("cat=$cat_ID&showposts=$posts_to_show");
//if (have_posts())
if ($category_posts->have_posts())
: $first = true;
?>
<ul class="post-list">
<?php
//while (have_posts()) : the_post();
while ($category_posts->have_posts()) : $category_posts->the_post();
if ($first)
$class = "first-in-row";
else
$class = "";
$first = !$first;
?>
<!-- Start: Post -->
<li <?php post_class($class); ?>>
<?php the_post_thumbnail(); ?>
<p class="categories"><?php the_category(", "); ?></p>
<h2><?php the_title(); ?> <?php edit_post_link(__('Edit', 'your_theme_text_domain'), '', ''); ?></h2>
<p class="post-meta"><span class="date"><?php the_time(get_option('date_format')) ?></span> <?php if (comments_open()) : ?>, <span class="comments"><?php comments_popup_link(_x('0', 'comments number', 'your_theme_text_domain'), _x('1', 'comments number', 'your_theme_text_domain'), _x('%', 'comments number', 'your_theme_text_domain')); ?></span> <?php endif; ?> <span class="author"><?php the_author() ?></span></p>
<?php the_excerpt(); ?>
<p class="more"><?php _e('Read More »» ', 'your_theme_text_domain'); ?></p>
<?php if (has_tag()): ?><p class="tags"><span><?php the_tags(""); ?></span></p><?php endif; ?>
</li>
<!-- End: Post -->
<?php endwhile; ?>
</ul>
<?php else : ?>
<h2 class="center"><?php _e('Not found', 'your_theme_text_domain'); ?></h2>
<p class="center"><?php _e('Sorry, but you are looking for something that isn\'t here.', 'your_theme_text_domain'); ?></p>
<?php
endif;
//wp_reset_query();
wp_reset_postdata();
?>
</div>
<?php get_sidebar(); //optional?>
<?php get_footer(); ?>
and replace $cat_ID and $posts_to_show to your liking. And I have used both query methods adjust it to your needs.
Hope it helps somebody who is looking for similar solution.
You can create a custom template that mimics a category page using get_posts and set a page using that template to home, but it won't be perfectly dynamic in the sense that you have to hard code the category slug or ID into that query. Assuming that you don't want to change that category often, that shouldn't be an issue. Alternatively, you could use wp_safe_redirect in a template to redirect to the category page - that would be if you want the user to be put directly on the real category page, URL and all.
I'm not sure what you mean by having your home page as a category, you mean that in your home page posts that will be displayed will be only from a certain category ?
You only need to perform a WP_Query before the loop;
$query = new WP_Query("cat=10, paged=".get_query_var('paged'));
Then use use the WP_Query object to perform the loop;
if($the_query->have_posts()):
while($the_query->have_posts()):
the_title();
the_content();
//Use all the loop function normally
endwhile;
endif;
The paged parameter is used to determine in which page you are, if you need paginantion.
Instead of using the category id, it is good to retrieve the id by the slug.
$home = get_category_by_slug('home-category-slug');
Then your query will be like this
$the_query = new WP_Query("cat=".$home->cat_ID.", paged=".get_query_var('paged'));
Yes this is possible Go to dashboard>>Setting>>Reading>>Static page Choose page from drop down and SAVE. On that page you can create your own stuff...