How to call single.php file using dynamically posts in wordpress? - wordpress

I have this href link which is dynamically posted, I want to get the single.php file and the dynamically posts to be redirected to my single.php file Here is my link below:
<a href="/single-<?php the_ID();?>-<?php the_slug(); ?>" class="wrapper" style="background-image:url('<?=$url?>')">
When I click on the link the URL is this way:
/single-137-2014-inaugural-diversity-abroad-conference-4
And I want that page to be redirected to my single.php file. How will I be able to do this?
Any help is muchl appreciated. TIA

I have solved your problem but please read about the get_permalink() function
<a href="<?php echo get_permalink(); ?>" class="wrapper" style="background-image:url('<?=$url?>')">
get_permalink() - Retrieves full permalink (link of a post) for the current post or post ID. This link will be opened post single page, which means if this is a custom post type and you create it as a separate single-post-type.php, then it will be as an open single-post-type.php page. Otherwise it appears as single.php.
For your information, posts have been opened in single.page while page opened with page.php. read about this link https://codex.wordpress.org/Post_Type_Templates

Related

how to show only relevant tag on post page

From the tag page I click a post.
When I get to the post page I want to show the relevant tag (the one I clicked).
Problem is that each of my posts has more then one tag. and using get_the_tags() get me the whole list of tags related to the post.
How can I identify and show only the relevant tag from the array?
Is there anyway to pass this information to the single.php page?
at the end I passed the tag name with the post URL and used $_GET to read it back on the post page.
on tag page:
<a href="<?php the_permalink()?>?tagName=<?php single_tag_title(); ?>">
on post page:
<?php echo $_GET["tagName"]; ?>

Get custom fields value on archive page

I want to display "Custom Field Value" in a archive page for wordpress. I tried
<?php echo get_post_meta($post->ID,'field_name',true); ?> but data can not display on archive page. what can i do?
Add this code your related page of archive.
<?php echo get_post_meta(get_the_ID(),'field_name',true); ?>
I have tested both code working fine. Please add code on archive.php just after while loop for test.

WordPress post details

I have WordPress page in which post titles of a single category are showed. When the user clicks any of the post a new tab should open and show the details of the post on which the user clicked how will I do this.
This is just simple the page where you found the list of post title is your "archive" or "category" page check where it's from coming. in that template give the link to your title like <a href="<?php echo get_permalink( $post->ID ) ?>"> which link you your single.php file in that change accordingly.

Link from single post page to index page

In Wordpress, is there an official way to link from a single post view to that post type's index view? I'm working with custom post types. I've googled around for a wordpress function but there doesn't seem to be one for this and I'd like to avoid hardcoding a URL.
Thanks!
<a href="<?php bloginfo('url'); ?>" > Home </a>

adding single.php page to wordpress or if condition for main page or post detail page

I use Barecity Theme for WordPress. i built everything, but now i need to add a single.php file to theme. now it displays all post content at homepage, I created a short_desc Custom Field. and I call it from code with;
<?php //get_post_meta($post->ID, 'short_desc', true); ?>
it is fine. but i need to display this short desc at home page listing, and the main content at details page. how can do that?
I appreciate helps!!
It sounds like what you are trying to do is show a custom field that you have set on a post on the index page (which lists all the posts).
To do that you'll need to modify index.php by adding your snippet where you would like to have the short description.
<?php echo get_post_meta($post->ID, 'short_desc', true); ?>
You need to use echo to display the results from the get_post_meta function.
Depending on how your posts are setup you can also use the More button when you write your posts. This will cut off your post at a certain point that you decide and only show that short part on the index and archive pages.
Another option would be to use
<?php the_excerpt(); ?>
Which shows the first 55 words (this can be adjusted though) of the post.
Hope that helps,
Paul

Resources