I want a page in my wordpress with all the links of all the posts. Same question as http://stackoverflow.com/questions/8953585/wordpress-get-links-to-all-posts-on-one-page
So in that post answer the following code is shown. I am using wordpress and testing it on my local server. So how to run this code and add a page in my site will all posts links.
I am not getting where to put this code.
<?php
$args = array( 'numberposts' => -1, 'orderby' => 'post_date' );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<div>
<?php the_title(); ?>
<br />
<?php the_date(); ?>
<br />
<?php the_excerpt(); ?>
</div>
<?php endforeach; ?>
Related
I have a function to get Custom posts title and picture. When I place it in header.php it works as it should be. For some reason when I put the shortcode into the Wordpress home page, it shows "HomePage" without a picture.
How can I display custom post title and image in home page?
function show_credit_cards_posts() {
$custom_query = get_posts( array(
'post_type' => 'credit-cards',
'post_status' => 'publish',
'posts_per_page' => -1,
'caller_get_posts'=> 1
)
);
foreach ($custom_query as $post) :
setup_postdata($post); ?>
<div class="top-button">
<div class="img-holder"><?php echo get_the_post_thumbnail(); ?></div>
<?php the_title(); ?>
</div>
<!-- <p><a class="more" href="<?php // echo get_post_permalink();?>">Find out more »</a></p></dd> -->
<?php endforeach;
wp_reset_postdata();
}
add_shortcode( 'show-credit-cards-blocks', 'show_credit_cards_posts' );
Use wp_query
<?php
$query = new WP_Query(array(
'post_type' => 'credit-cards',
'post_status' => 'publish',
'posts_per_page' => -1
));
while ($query->have_posts()) {
$query->the_post();
?>
<div class="top-button">
<div class="img-holder"><?php echo get_the_post_thumbnail(); ?></div>
<?php get_the_title(); ?>
</div>
<!-- <p><a class="more" href="<?php // echo get_post_permalink();?>">Find out more »</a></p></dd> -->
<?php
}
wp_reset_query();
?>
My main portfolio page is setup correctly which is displaying ALL the work, the next step I'm having trouble with is displaying work ONLY from a specific category.
Under the custom content types manager I checked "Enable Categories" under Taxonomies which gave me control to add categories to the content type like the URL below.
For example: http://localhost/category/narrative would display all work with the category "Narrative" attached, right now it's displaying all the work since I copy & pasted the code from the work page.
How can I get this category.php template to detect and display the work associated with the category it's loading?
<?php
/**
* The template for displaying Category Archive pages
*
* #package WordPress
*/
$res = get_posts(array('post_type' => 'work', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => -1));
get_header(); ?>
<section role="main" class="container">
<div id="da-thumbs" class="row work-list da-thumbs">
<? foreach($res as $post) : setup_postdata($post) ?>
<?
$thumbnail = get_custom_field('thumbnail');
?>
<div class="col four">
<a href="<?php echo get_permalink(); ?>">
<img src="<?=$thumbnail?>" />
<div><span><?php the_title( '<h3>', '</h3>' ); ?></span></div>
</a>
</div>
<? endforeach; ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php the_content(__('(more...)')); ?>
<?php endwhile; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>
</section>
<?php get_footer(); ?>
Your get_posts is not filtering by category.
Do something like:
$the_category = get_queried_object();
$cat_id = $the_category->term_id;
$res = get_posts(array('category' => $cat_id, 'post_type' => 'work', 'orderby' => 'menu_order', 'order' => 'ASC', 'numberposts' => -1));
Please provide the code for how to integrate. I kept blog inside at public_html folder and blog has one database and site has other database I have created.
I have tried these code at my site index.php
<?php require('blog/wp-blog-header.php');?>
<?php
$args = array( 'numberposts' => 2, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<div class="events">
<p><strong><?php the_date(); ?></strong></p>
<p><?php the_title(); ?></p>
</div>
<?php endforeach; ?>
but shows an error like
Fatal error: Call to undefined function wp_get_recent_posts() in
/home/sharelok/public_html/application/views/index.php on line 124
You may try this
define('WP_USE_THEMES', false);
require('blog/wp-load.php');
$postslist = get_posts( array( 'posts_per_page' => 2, 'orderby'=> 'post_date' ) );
foreach( $postslist as $post ) : setup_postdata($post); ?>
<div class="events">
<p><strong><?php the_date(); ?></strong></p>
<p><?php the_title(); ?></p>
</div>
<?php endforeach; ?>
My question is How can I create two rows with 2 columns <td> in a Dynamic way, receiving posts from the query_post()!
I spent sometime using the query_post() in WordPress to create this :
I made a drastic mistake and this is the snippet:
http://pastebin.com/cp6RSTQQ
this gives me the recent posts of a category called watch using the offset in the query_post()
in this way:
<?php
$args = array( 'posts_per_page' => 1, 'order'=> 'DESC','category' => 'watch', 'orderby' => 'post_date','offset' => 0 );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<td class="leftBoxes">
<div class="imgMargin"> <?php the_post_thumbnail(); ?> </div>
<br>
<div class="boxScrollsBlogsView">
<h2><?php the_title(); ?> </h2>
<P>
<?php the_excerpt(); ?>
</P>
<h3> ReadMore</h3>
</div>
</td>
<?php endforeach; ?>
After I wanted to go forward, I realized that I can't do pagination in the way I wrote th code!
I have looked at this QUESTION on wordpress website, but I can't understand how he is doing it honestly!
Just deleted the the right box and I changed the code to look like this
<?php
$args = array( 'posts_per_page' => 4, 'order'=> 'DESC','category' => 'watch', 'orderby' => 'post_date','offset' => 0 );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<td class="leftBoxes">
<div class="imgMargin"> <?php the_post_thumbnail(); ?> </div>
<br>
<div class="boxScrollsBlogsView">
<h2><?php the_title(); ?> </h2>
<P>
<?php the_excerpt(); ?>
</P>
<h3> ReadMore</h3>
</div>
</td>
<?php endforeach; ?>
and it creates one TD after another eventually it goes to the new line for making rows
Here is my webpage: http://dastousgroupeconseil.com/faq-2/
Here is the complete code of my page: http://pastebin.com/PQUsYdha
I used this php code to display the excerpt and the hyperlink of my posts, but some of them don't want to display. Is it because I reset the $post variable after each endforeach?
<?php global $post;
$args = array( 'numberposts' => 4, 'offset'=> 0, 'category' => 140 );
$myposts = get_posts( $args );
foreach( $myposts as $post) : setup_postdata($post); ?>
<a href="<?php the_permalink(); ?>" target='_blank' ><?php the_excerpt(); ?></a>
<?php endforeach; wp_reset_postdata(); ?>
I've had issues using setup_postdata a few times myself, I tend to skip it altogether and just use the retrieved $post objects.
So for the permalink:
<?php echo get_permalink($post->ID); ?>