Hard link to the blog ?
-
I would like to have a personalized home page with only the last post appearing there and some other informations. But I would like a link below this post “See the full blog” for example that would send my readers to an address like https://www.site.com/blog with the actual blog.
-
You’re going to have to create a static front page and add a page template to your home page.
On that page template, you’ll need a custom loop to display just the latest post, maybe like this:
<?php query_posts('showposts=1'); ?> <?php while (have_posts()) : the_post(); ?> <!-- Do Stuff Here --> <?php endwhile;?>
You could add that above or below a standard Page loop if you want to display content for the homepage and the latest post.
You literally resolved 99% of my problem in just one post!!!
Thank you so much!!!!There is just one think that doesn’t work is the loop you gave me.
Should I put that bellow my content on the “HTML” tab of the Home page ?nop, I’ve tried again and again, ??
To explain again even if Im sur you understood.
I have the HOME and BLOG page.
And Im trying to pull the last post of the BLOG page to the bottom of th HOME page.Here is the code I have on my HOME page :
“
<img src=”https://www.creativewhoman.com/wp-content/jpg/title_welcome.jpg” alt=”creative whoman welcome title” />
A complete solution for the design of your business.
<span style=”font-weight: normal; font-size: 13px;”>We are a graphic, industrial and sound design firm specialized in branding and marketing. We will guide you to bring to your company significant design and technical elements that will help you create a unique and powerful tool of communication.
</span><?php query_posts(‘showposts=1’); ?>
<?php while (have_posts()) : the_post(); ?>
<!– Do Stuff Here –>
<?php endwhile;?>
“I’m not a dev, Im a designer. So my question might look stupid.
Go look at my website if you wanna have an idea.That’s OK, you don’t have to do anything very technical to get this setup how you want to, just a bit of copy pasting.
You can only use HTML in your post and page editor to add content to a page in WordPress. To add the PHP for this extra loop, you need to edit one of your theme’s files.
Actually, create a new one. Take a closer look at the documentation for creating page templates/ The first step is to create a page template for your home page and set that page to use the template: https://codex.www.ads-software.com/Pages#Page_Templates
Ok my friend I think Im almost there!!!
I created the page and upload on the server in the Theme folder.
Here is the code of my php page :
<?php
/*
Template Name: finallyhome
*/
get_header();?><img src=”https://www.creativewhoman.com/wp-content/jpg/title_welcome.jpg” alt=”creative whoman welcome title” />
<?php query_posts(‘showposts=1’); ?>
<?php while (have_posts()) : the_post(); ?>
<!– Do Stuff Here –>
<?php endwhile;?><?php get_footer(); ?>
Now im looking on how to make this page the home page!
Im still searching as I dont find the “Write > Page administration panel”
but im working on it. If you see this message before let me know my friend!!!
:))))YEAAAAAAA I found it!
I spent so much time for something so simple!
It was just on the right of the actual “HOME” page a created! ??Ok now, I think the only and last step is the piece of code you gave me.
Is it supposed to work just like that ?
I copy and past this in the php page ?(btw thank you a lot really…)
No, not exactly, that was just an example. You want to copy the
page.php
file from your theme and Rename that copy topage_home.php
.Open that new template file in a text editor and add this code to the very top of your the file:
<?php /* Template Name: Home Template */ ?>
Now, this home page template will function just like a regular WordPress page. It will load your theme’s header and footer, but also the content of the page.
You can edit the Home Page in WordPress in the page editor to change the headline or add regular static content to the page, such as images. So there is no need to code this image into your template file unless you want it to be above your headline or something:
<img src="https://www.creativewhoman.com/wp-content/jpg/title_welcome.jpg" alt="creative whoman welcome title" />
So you have one loop on the page to load that page’s content, and then your just need to add a second loop to load the latest post. Add this second loop right after the
<?php endif; ?>
statement.That code would look like this:
<?php query_posts('showposts=1'); ?> <?php while (have_posts()) : the_post(); ?> <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <div id="small"><smallbg><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></smallbg></div> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3> <div class="entry"> <?php the_content('Read the rest of this entry »'); ?> </div> <p class="postmetadata"><i><?php the_tags('Tags: ', ', ', '<br />'); ?></i> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p> </div> <?php endwhile;?>
So the code for your
page_home.php
file might look something like this:<?php /* Template Name: Home Template */ ?> <?php get_header(); ?> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="entry"> <?php the_content(__('(more...)')); ?> </div> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <?php query_posts('showposts=1'); ?> <?php while (have_posts()) : the_post(); ?> <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <div id="small"><smallbg><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></smallbg></div> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3> <div class="entry"> <?php the_content('Read the rest of this entry »'); ?> </div> <p class="postmetadata"><i><?php the_tags('Tags: ', ', ', '<br />'); ?></i> Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p> </div> <?php endwhile;?> <?php get_footer(); ?>
let me try this right now….
OMG!!!
THAT WORKS!!!!!
OKOK !!!!!! Last thing!!!!Can it be just the preview of the blog post and not the full post ?
ALSO
Are you interested in doing freelance ?
I still havnt find the way to stop the post to show everything…. ??
But I simplify the code :
<?php /* Template Name: finallyhome */ get_header();?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="more"> <?php the_content('more.'); ?> </div> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <div class="alignright"><strong><a href="https://www.creativewhoman.com/?page_id=1406">Access to the Blog »</a></strong></div> <?php query_posts('showposts=1'); ?> <?php while (have_posts()) : the_post(); ?> <div <?php post_class() ?> id="post-<?php the_ID(); ?>"> <h3><?php the_title(); ?></h3> <div class="more"> <?php the_content('more.'); ?> </div> </div> <?php endwhile;?> <div><img src="https://www.creativewhoman.com/wp-content/jpg/linethin.jpg" alt="creative whoman black line" /> <div class="alignright"><strong><a href="https://www.creativewhoman.com/?page_id=1406">Access to the Blog »</a></strong></div> </div><br /><br /> <?php get_footer(); ?>
I DID IT!!!!
AWESOMEEE!!!Thank you so much my friend!!
Cool, your site is looking sharp! No problem, glad that I could help.
And yes, I do some freelance work.
- The topic ‘Hard link to the blog ?’ is closed to new replies.