Wordpress doesn't display the permalinks of two of my post - php

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); ?>

Related

Restricting posts to a specifc category and subcategory

On this site: http://www.palmbeachwoman.com/stories/ I used a programmer to customize the template. His code for this page is:
<?php
$args = array( 'numberposts' => 18, 'post_status'=>"publish",'post_type'=>"post",'orderby'=>"post_date");
$postslist = get_posts( $args );
echo '<ul id="latest_stories">';
foreach ($postslist as $post) : setup_postdata($post); ?>
<li><a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
<span class="s_thumb"> <?php the_post_thumbnail( 'full' ); ?> </span>
<span class="s_title"> <?php the_title(); ?> </span></a>
<span class="s_cotegories">More Stories from <?php the_category( ', ' ); ?></span></li>
<?php endforeach; ?>
The posts were supposed to be restricted to a specific category (#82) and any subcategories within it. I know how to do this with the traditional post display: http://alijafarian.com/how-to-display-wordpress-posts-for-a-specific-category/ but since I didn't write this code, I'm not sure how to modify it.
You can set the category in the array past to get_posts
$args = array( 'numberposts' => 18, 'post_status'=>"publish",'post_type'=>"post",
'orderby'=>"post_date", category=>82);

Access the_post() contents in a custom sidebar

I have this code in single-legislacion.php page:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<h4><?php the_title(); ?></h4>
<?php endwhile; ?>
<?php endif; ?>
<?php
$args = array(
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $thePostID,
'post_status' => 'inherit',
'numberposts' => 1
);
$attachments = get_posts( $args );
if ( $attachments ) :
foreach ( $attachments as $attachment ) : ?>
<div class="BaseIco">
<a class="IcoDescargas" href="<?php echo wp_get_attachment_url( $attachment->ID, true ); ?>">
<img src="<?php echo get_template_directory_uri(); ?>/images/ico_descargas.png"><br>
Descargar PDF
</a>
</div>
<?php endforeach;
endif;
?>
Because I am using Table of Content Plus plugin and have not found a way to display the generated TOC outside of the_content() itself, the only solution I have is to display it through a widget on a sidebar. Now, my question is: can I access the_post() content, like attachments for example, in a custom sidebar? How?
Also if any knows any variant to show the TOC outside the content, I'll be graceful if can share it.
No, I don't think so. the_post() only works inside of the loop, sidebars are usually rendered outside of it.
However, you can use get_post with global $post, i.e.:
global $post;
$p = get_post($post->ID);

wordpress page with all the post links shown

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; ?>

Breadcrumb trail shows incorrect trail?

Why the following code would cause my breadcrumb trail to show the same post link in the breadcrumbs no matter what page you are on in the site?
I have been stuck on this issue for ages now and just cannot figure it out...
See what I mean here.
<!-- Loops through Stories and returns images -->
<ul style="width: 1520px">
<?php
global $post;
$category_id = get_cat_ID('stories');
$args = array( 'numberposts' => 9, 'offset'=> 0, 'category'=> $category_id );
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<!-- stories -->
<li>
<figure>
<?php if ( has_post_thumbnail()) : // Check if thumbnail exists ?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail(array(64,64)); // Declare pixel size you need inside the array ?></a>
<?php endif; ?>
</figure>
<!-- /post thumbnail -->
<h3><?php the_title(); ?></h3>
</li>
<?php endforeach; ?>
</ul>
<!-- /Loops through Stories and returns images -->
Try to reset the postdata, like in this example from the Codex:
<ul>
<?php
global $post;
$args = array( 'numberposts' => 5, 'offset'=> 1, 'category' => 1 );
$myposts = get_posts( $args );
foreach( $myposts as $post ) :
setup_postdata($post); ?>
<li><?php the_title(); ?></li>
<?php endforeach;
wp_reset_postdata(); ?>
</ul>

Wordpress Get Posts AJAX infinate scroll

I'm working on a website http://www.matchlessphotography.com which has got a great display of photos - it tiles for ages...
Essentially the client would like this to continue on infinately.
I have no idea how to do this and have had a look at some tutorials without any bearing...
This is how I am currently getting the posts:
<?php
global $post;
$args = array('numberposts' => 104, 'meta_key=visible&meta_value=yes');
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<a class="photohovera" href="<?php the_permalink(); ?>">
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
<img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<? echo $url ?>&h=138&w=197" width="197" height="138" title="<?php the_title(); ?>" />
<span class="spanno">
<strong class="title_blog_mini_post">
<?php the_title(); ?>
</strong>
</span>
</a>
<?php endforeach; ?>
I guess I just need to do this again but with an increased offset each time...?
Paul Irishs jQuery Plugin Infinite Scroll is the way to go here.
The plugin looks for a pagination container e.g. div.navigation and an item container for the items you are going to retrieve like .photohovera in your case.
WordPress provides a function for displaying pagination links. It's called paginate_links and its default output should match the requirements of the plugin.
However you will need to change they way you are getting your posts right now from get_posts() to a WP_Query Object:
<?php
$args = array('numberposts' => 104, 'meta_key=visible&meta_value=yes');
$myposts = new WP_Query( $args );
$results = $myposts->get_results();
foreach( $results as $post ) : setup_postdata($post); ?>

Categories